Skip to content

Commit 54e560a

Browse files
committed
GROOVY-10351
1 parent e1e9ab5 commit 54e560a

File tree

6 files changed

+81
-41
lines changed

6 files changed

+81
-41
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/ClosureInferencingTests.java

-20
Original file line numberDiff line numberDiff line change
@@ -934,26 +934,6 @@ public void testCoercedClosure2() {
934934
assertType(contents, "z", "java.util.regex.Pattern");
935935
}
936936

937-
@Test // https://github.com/groovy/groovy-eclipse/issues/1000
938-
public void testCoercedClosure3() {
939-
//@formatter:off
940-
createUnit("Face",
941-
"interface Face<T> {\n" +
942-
" boolean test(T t)\n" +
943-
"}");
944-
945-
String contents =
946-
"class C<E> {\n" + // like Collection
947-
" boolean meth(Face<? super E> f) {\n" + // like removeIf
948-
" f.test(null)\n" +
949-
" }\n" +
950-
"}\n" +
951-
"def c = new C<Integer>()\n" +
952-
"def result = c.meth { e -> e }\n";
953-
//@formatter:on
954-
assertType(contents, "e", "java.lang.Integer");
955-
}
956-
957937
@Test // Closure type inference without @CompileStatic
958938
public void testCompileStaticClosure0() {
959939
//@formatter:off

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/GenericInferencingTests.java

+49-18
Original file line numberDiff line numberDiff line change
@@ -887,14 +887,14 @@ public void testClosure5() {
887887
}
888888

889889
@Test
890-
public void testClosure5a() {
890+
public void testClosure6() {
891891
assumeTrue(isParrotParser());
892892
String contents = "def fn = String[]::new";
893893
assertType(contents, "fn", "groovy.lang.Closure<java.lang.String[]>");
894894
}
895895

896896
@Test
897-
public void testClosure6() {
897+
public void testClosure7() {
898898
String contents =
899899
"void test(List<String> list) {\n" +
900900
" def array = list.stream().toArray {\n" +
@@ -905,7 +905,7 @@ public void testClosure6() {
905905
}
906906

907907
@Test
908-
public void testClosure6a() {
908+
public void testClosure8() {
909909
assumeTrue(isParrotParser());
910910
String contents =
911911
"void test(List<String> list) {\n" +
@@ -916,7 +916,7 @@ public void testClosure6a() {
916916
}
917917

918918
@Test
919-
public void testClosure6b() {
919+
public void testClosure9() {
920920
assumeTrue(isAtLeastGroovy(30));
921921
String contents =
922922
"void test(List<String> list) {\n" +
@@ -927,7 +927,7 @@ public void testClosure6b() {
927927
}
928928

929929
@Test // incorrect LHS type should not alter RHS type
930-
public void testClosure6c() {
930+
public void testClosure10() {
931931
String contents =
932932
"void test(List<String> list) {\n" +
933933
" Number[] array = list.stream().toArray(String[].&new)\n" +
@@ -937,7 +937,7 @@ public void testClosure6c() {
937937
}
938938

939939
@Test // GROOVY-9803
940-
public void testClosure7() {
940+
public void testClosure11() {
941941
for (String toSet : new String[] {"D.&wrap", "Collections.&singleton", "{x -> [x].toSet()}", "{Collections.singleton(it)}"}) {
942942
String contents =
943943
"class C<T> {\n" +
@@ -963,27 +963,27 @@ public void testClosure7() {
963963
}
964964

965965
@Test // https://github.com/groovy/groovy-eclipse/issues/1194
966-
public void testClosure8() {
966+
public void testClosure12() {
967967
String contents = "Optional.of(1).map(Arrays.&asList).map{x -> x.first()}\n";
968968
assertType(contents, "asList", "java.util.List<java.lang.Integer>");
969969
assertType(contents, "x", "java.util.List<java.lang.Integer>");
970970
}
971971

972972
@Test // https://github.com/groovy/groovy-eclipse/issues/1194
973-
public void testClosure9() {
973+
public void testClosure13() {
974974
String contents = "Optional.of(1).map(Collections.&singletonList).map{x -> x.first()}\n";
975975
assertType(contents, "singletonList", "java.util.List<java.lang.Integer>");
976976
assertType(contents, "x", "java.util.List<java.lang.Integer>");
977977
}
978978

979979
@Test // https://github.com/groovy/groovy-eclipse/issues/1194
980-
public void testClosure10() {
980+
public void testClosure14() {
981981
String contents = "void test(Closure<List<Integer>> cl) {}\n" + "test(Arrays.&asList)\n";
982982
assertType(contents, "asList", "java.util.List<java.lang.Integer>");
983983
}
984984

985985
@Test // https://github.com/groovy/groovy-eclipse/issues/1194
986-
public void testClosure11() {
986+
public void testClosure15() {
987987
String contents = "import groovy.transform.stc.*\n" +
988988
"def m(@ClosureParams(value=SimpleType,options='java.lang.Integer') Closure c) {}\n" +
989989
"def <T> String test(T t) {}\n" +
@@ -996,22 +996,25 @@ public void testClosure11() {
996996
}
997997

998998
@Test // https://github.com/groovy/groovy-eclipse/issues/1198
999-
public void testClosure12() {
999+
public void testClosure16() {
10001000
assumeTrue(isParrotParser());
10011001
String contents = "Optional.of(21).map(num -> num * 2).get()\n";
10021002
assertType(contents, "get", "java.lang.Integer");
10031003
assertDeclaringType(contents, "get", "java.util.Optional<java.lang.Integer>");
10041004
}
10051005

10061006
@Test // https://github.com/groovy/groovy-eclipse/issues/1199
1007-
public void testClosure13() {
1007+
public void testClosure17() {
10081008
String contents = "java.util.function.Function<Integer, List<Integer>> f = Arrays.&asList\n";
10091009
assertType(contents, "asList", "java.util.List<java.lang.Integer>");
10101010
}
10111011

10121012
@Test // https://github.com/groovy/groovy-eclipse/issues/1199
1013-
public void testClosure14() {
1014-
String contents = "def <T> String test(T t) {}\n" + "java.util.function.Function<Integer, String> f = this.&test\n";
1013+
public void testClosure18() {
1014+
String contents =
1015+
"def <T> String test(T t) {}\n" +
1016+
"java.util.function.Function<Integer, String> f = this.&test\n";
1017+
10151018
int offset = contents.lastIndexOf("test");
10161019

10171020
MethodNode m = assertDeclaration(contents, offset, offset + 4, "Search", "test", DeclarationKind.METHOD);
@@ -1020,16 +1023,44 @@ public void testClosure14() {
10201023
}
10211024

10221025
@Test // https://github.com/groovy/groovy-eclipse/issues/1282
1023-
public void testClosure15() {
1026+
public void testClosure19() {
10241027
String contents =
10251028
"def <T> void test(Iterator<T> it) {\n" +
1026-
" it.forEachRemaining{e->}\n" +
1029+
" it.forEachRemaining{t->}\n" +
1030+
"}\n";
1031+
assertType(contents, "t", "T");
1032+
}
1033+
1034+
@Test // https://github.com/groovy/groovy-eclipse/issues/1000
1035+
public void testClosure20() {
1036+
String contents =
1037+
"void test(Collection<Integer> c) {\n" +
1038+
" boolean b = c.removeIf{i->false}\n" +
1039+
"}\n";
1040+
assertType(contents, "i", "java.lang.Integer");
1041+
}
1042+
1043+
@Test // https://github.com/groovy/groovy-eclipse/issues/1000
1044+
public void testClosure21() {
1045+
assumeTrue(isParrotParser());
1046+
String contents =
1047+
"void test(Collection<Integer> c) {\n" +
1048+
" boolean b = c.removeIf(i->false)\n" +
10271049
"}\n";
1028-
assertType(contents, "e", "T");
1050+
assertType(contents, "i", "java.lang.Integer");
10291051
}
10301052

10311053
@Test
1032-
public void testClosure16() {
1054+
public void testClosure22() {
1055+
String contents =
1056+
"void test(Collection<Integer> c) {\n" +
1057+
" boolean b = c.removeIf{Number n->}\n" +
1058+
"}\n";
1059+
assertType(contents, "n", "java.lang.Number");
1060+
}
1061+
1062+
@Test
1063+
public void testClosure23() {
10331064
String contents =
10341065
"void test(List list) {\n" +
10351066
" list.stream().map{e->}\n" +

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+23
Original file line numberDiff line numberDiff line change
@@ -4735,4 +4735,27 @@ public void testTypeChecked10347a() {
47354735

47364736
runConformTest(sources, "[bar, foo]");
47374737
}
4738+
4739+
@Test
4740+
public void testTypeChecked10351() {
4741+
//@formatter:off
4742+
String[] sources = {
4743+
"Main.groovy",
4744+
"class C<T> {\n" +
4745+
" C(T one, D<T,? extends T> two) {\n" +
4746+
" }\n" +
4747+
"}\n" +
4748+
"class D<U,V> {\n" +
4749+
"}\n" +
4750+
"@groovy.transform.TypeChecked\n" +
4751+
"void test() {\n" +
4752+
" D<Integer,? extends Integer> x = null\n" +
4753+
" C<Integer> y = new C<>(1,x)\n" +
4754+
"}\n" +
4755+
"test()\n",
4756+
};
4757+
//@formatter:on
4758+
4759+
runConformTest(sources);
4760+
}
47384761
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+4
Original file line numberDiff line numberDiff line change
@@ -2073,9 +2073,13 @@ private static void extractGenericsConnections(Map<GenericsTypeName, GenericsTyp
20732073
ClassNode ui = usage[i];
20742074
ClassNode di = declaration[i];
20752075
if (di.isGenericsPlaceHolder()) {
2076+
/* GRECLIPSE edit -- GROOVY-10351
20762077
GenericsType gt = new GenericsType(di);
20772078
gt.setPlaceholder(di.isGenericsPlaceHolder());
20782079
connections.put(new GenericsTypeName(di.getGenericsTypes()[0].getName()), gt);
2080+
*/
2081+
connections.put(new GenericsTypeName(di.getUnresolvedName()), new GenericsType(ui));
2082+
// GRECLIPSE end
20792083
} else if (di.isUsingGenerics()) {
20802084
extractGenericsConnections(connections, ui.getGenericsTypes(), di.getGenericsTypes());
20812085
}

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+4
Original file line numberDiff line numberDiff line change
@@ -1946,9 +1946,13 @@ private static void extractGenericsConnections(final Map<GenericsTypeName, Gener
19461946
ClassNode ui = usage[i];
19471947
ClassNode di = declaration[i];
19481948
if (di.isGenericsPlaceHolder()) {
1949+
/* GRECLIPSE edit -- GROOVY-10351
19491950
GenericsType gt = new GenericsType(di);
19501951
gt.setPlaceholder(di.isGenericsPlaceHolder());
19511952
connections.put(new GenericsTypeName(di.getGenericsTypes()[0].getName()), gt);
1953+
*/
1954+
connections.put(new GenericsTypeName(di.getUnresolvedName()), new GenericsType(ui));
1955+
// GRECLIPSE end
19521956
} else if (di.isUsingGenerics()) {
19531957
extractGenericsConnections(connections, ui.getGenericsTypes(), di.getGenericsTypes());
19541958
}

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1807,9 +1807,7 @@ private static void extractGenericsConnections(final Map<GenericsTypeName, Gener
18071807
ClassNode ui = usage[i];
18081808
ClassNode di = declaration[i];
18091809
if (di.isGenericsPlaceHolder()) {
1810-
GenericsType gt = new GenericsType(di);
1811-
gt.setPlaceholder(di.isGenericsPlaceHolder());
1812-
connections.put(new GenericsTypeName(di.getGenericsTypes()[0].getName()), gt);
1810+
connections.put(new GenericsTypeName(di.getUnresolvedName()), new GenericsType(ui));
18131811
} else if (di.isUsingGenerics()) {
18141812
extractGenericsConnections(connections, ui.getGenericsTypes(), di.getGenericsTypes());
18151813
}

0 commit comments

Comments
 (0)