Skip to content

Commit

Permalink
GROOVY-10651, GROOVY-10671
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 27, 2023
1 parent e1a97f7 commit 6e1a638
Show file tree
Hide file tree
Showing 8 changed files with 806 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,43 @@ public void testCircularReference2() {
assertType(contents, offset, offset + 8, "Scorable<? super T,FeatureName>");
}

@Test // GROOVY-10671
public void testCircularReference3() {
createJavaUnit("p", "ObjectAssert",
"package p;\n" +
"abstract class ObjectAssert<SELF extends ObjectAssert<SELF>> {\n" +
" SELF as(String description) {\n" +
" return (SELF) this;\n" +
" }\n" +
"}\n");

createJavaUnit("p", "IterableAssert",
"package p;\n" +
"abstract class IterableAssert<SELF extends IterableAssert<SELF>> extends ObjectAssert<SELF> {\n" +
"}\n");

createJavaUnit("p", "CollectionAssert",
"package p;\n" +
"abstract class CollectionAssert<SELF extends CollectionAssert<SELF>> extends IterableAssert<SELF> {\n" +
" void containsExactlyInAnyOrderElementsOf(java.util.Collection<?> expect) {\n" +
" }\n" +
"}\n");

createJavaUnit("p", "Assert",
"package p;\n" +
"class Assert {\n" +
" public static <E> CollectionAssert<?> assertThat(java.util.Collection<? extends E> c) {return null;}\n" +
"}\n");

String contents =
"import static p.Assert.assertThat\n" +
"def strings = (Collection<String>) ['a','b']\n" +
"assertThat(strings).as('assertion description')\n" +
" .containsExactlyInAnyOrderElementsOf(['a','b'])\n";

assertDeclaringType(contents, "containsExactlyInAnyOrderElementsOf", "p.CollectionAssert");
}

@Test
public void testJira1718() throws Exception {
createUnit("p2", "Renderer",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2647,6 +2647,50 @@ public void testWildcards7() {
"----------\n");
}

@Test // GROOVY-10671
public void testWildcards8() {
//@formatter:off
String[] sources = {
"Main.groovy",
"import static p.Assert.assertThat\n" +
"def strings = (Collection<String>) ['a','b']\n" +
"assertThat(strings).as('assertion description')\n" +
" .containsExactlyInAnyOrderElementsOf(['a','b'])\n",

"p/Assert.java",
"package p;\n" +
"class Assert {\n" +
" public static <E> CollectionAssert<?> assertThat(java.util.Collection<? extends E> c) {\n" +
" return new CollectionAssert() {};\n" +
" }\n" +
"}\n",

"p/ObjectAssert.java",
"package p;\n" +
"abstract class ObjectAssert<SELF extends ObjectAssert<SELF>> {\n" +
" SELF as(String description) {\n" +
" return (SELF) this;\n" +
" }\n" +
"}\n",

"p/IterableAssert.java",
"package p;\n" +
"abstract class IterableAssert<SELF extends IterableAssert<SELF>> extends ObjectAssert<SELF> {\n" +
"}\n",

"p/CollectionAssert.java",
"package p;\n" +
"abstract class CollectionAssert<SELF extends CollectionAssert<SELF>> extends IterableAssert<SELF> {\n" +
" void containsExactlyInAnyOrderElementsOf(java.util.Collection<?> expect) {\n" +
" System.out.print(expect);\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "[a, b]");
}

@Test
public void testUpperBounds1() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ private ClassNode configureWildcardType(final WildcardType wildcardType) {
private ClassNode configureParameterizedType(final ParameterizedType parameterizedType) {
ClassNode base = configureType(parameterizedType.getRawType());
GenericsType[] gts = configureTypeArguments(parameterizedType.getActualTypeArguments());
// GRECLIPSE add -- GROOVY-10153, GROOVY-10651, GROOVY-10671, GROOVY-10756, GROOVY-11258
// fix erasure : ResolveVisitor#resolveWildcardBounding
final int n; if (gts != null && (n = gts.length) > 0) {
for (int i = 0; i < n; i += 1) { GenericsType gt = gts[i];
if (!gt.isWildcard() || gt.getUpperBounds() != null) continue;
ClassNode[] ubs = base.redirect().getGenericsTypes()[i].getUpperBounds();
if (ubs != null && !ClassHelper.OBJECT_TYPE.equals(ubs[0])) gt.getType().setRedirect(ubs[0]);
}
}
// GRECLIPSE end
base.setGenericsTypes(gts);
return base;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ private ClassNode configureWildcardType(final WildcardType wildcardType) {
private ClassNode configureParameterizedType(final ParameterizedType parameterizedType) {
ClassNode base = configureType(parameterizedType.getRawType());
GenericsType[] gts = configureTypeArguments(parameterizedType.getActualTypeArguments());
// GRECLIPSE add -- GROOVY-10153, GROOVY-10651, GROOVY-10671, GROOVY-10756, GROOVY-11258
// fix erasure : ResolveVisitor#resolveWildcardBounding
final int n; if (gts != null && (n = gts.length) > 0) {
for (int i = 0; i < n; i += 1) { GenericsType gt = gts[i];
if (!gt.isWildcard() || gt.getUpperBounds() != null) continue;
ClassNode[] ubs = base.redirect().getGenericsTypes()[i].getUpperBounds();
if (ubs != null && !ClassHelper.OBJECT_TYPE.equals(ubs[0])) gt.getType().setRedirect(ubs[0]);
}
}
// GRECLIPSE end
base.setGenericsTypes(gts);
return base;
}
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy50/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<file-match-pattern match-pattern="groovy/transform/trait/TraitComposer.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/trait/TraitReceiverTransformer.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/trait/Traits.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/vmplugin/v8/Java8.java" include-pattern="false" />
</fileset>
<filter name="DerivedFiles" enabled="true" />
</fileset-config>
Loading

0 comments on commit 6e1a638

Please sign in to comment.