Skip to content

Commit 50f6eb9

Browse files
committed
GROOVY-10544
1 parent 7aa55b0 commit 50f6eb9

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2020 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1307,15 +1307,6 @@ public void testJavaInterfaceWithDefaultMethod2() {
13071307

13081308
@Test // https://github.com/groovy/groovy-eclipse/issues/1047
13091309
public void testJavaInterfaceWithDefaultMethod3() {
1310-
// Java 11 adds default method toArray(IntFunction) to the Collection interface
1311-
boolean jdkCollectToArray3;
1312-
try {
1313-
java.util.Collection.class.getDeclaredMethod("toArray", java.util.function.IntFunction.class);
1314-
jdkCollectToArray3 = true;
1315-
} catch (Exception e) {
1316-
jdkCollectToArray3 = false;
1317-
}
1318-
13191310
//@formatter:off
13201311
String contents =
13211312
"List<String> list = []\n" +
@@ -1325,8 +1316,15 @@ public void testJavaInterfaceWithDefaultMethod3() {
13251316
//@formatter:on
13261317

13271318
int offset = contents.indexOf("toArray");
1328-
MethodNode method = assertDeclaration(contents, offset, offset + 7, "java.util.Collection<java.lang.String>", "toArray", DeclarationKind.METHOD);
1329-
assertEquals(jdkCollectToArray3 ? "java.util.function.IntFunction<T[]>" : "T[]", printTypeName(method.getParameters()[0].getType()));
1319+
try { // Java 11 adds default method toArray(IntFunction) to the Collection interface
1320+
java.util.Collection.class.getDeclaredMethod("toArray", java.util.function.IntFunction.class);
1321+
MethodNode method = assertDeclaration(contents, offset, offset + 7, "java.util.Collection<java.lang.String>", "toArray", DeclarationKind.METHOD);
1322+
assertEquals("java.util.function.IntFunction<T[]>", printTypeName(method.getParameters()[0].getType()));
1323+
assertType(contents, "n", "java.lang.Integer");
1324+
} catch (Exception e) {
1325+
MethodNode method = assertDeclaration(contents, offset, offset + 7, "java.util.List<java.lang.String>", "toArray", DeclarationKind.METHOD);
1326+
assertEquals("T[]", printTypeName(method.getParameters()[0].getType()));
1327+
}
13301328
}
13311329

13321330
@Test // GRECLIPSE-1105

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

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2021 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1283,6 +1283,22 @@ public void testMethod6() {
12831283
assertType(contents, "n", "java.lang.Byte");
12841284
}
12851285

1286+
@Test // GROOVY-10544
1287+
public void testMethod7() {
1288+
String contents =
1289+
"import java.util.function.Function\n" +
1290+
"interface I<T> {\n" +
1291+
" def <U> Iterable<U> m(Function<? super T, ? extends U> f)\n" +
1292+
"}\n" +
1293+
"interface J<T> extends I<T> {\n" +
1294+
" def <U> List<U> m(Function<? super T, ? extends U> f)\n" +
1295+
"}\n" +
1296+
"void test(J<String> j) {\n" +
1297+
" def list = j.m{s -> java.util.regex.Pattern.compile(s)}\n" +
1298+
"}\n";
1299+
assertType(contents, "list", "java.util.List<java.util.regex.Pattern>");
1300+
}
1301+
12861302
@Test // GRECLIPSE-1129: Static generic method type inference with @CompileStatic
12871303
public void testStaticMethod1() {
12881304
String contents =
@@ -1431,8 +1447,7 @@ public void testStaticMethod11() {
14311447
String toFind = "removeAll";
14321448
int start = contents.indexOf(toFind), end = start + toFind.length();
14331449
assertType(contents, start, end, "java.lang.Boolean");
1434-
// Is there any reason to fully resolve the declaring type in this case?
1435-
MethodNode m = assertDeclaration(contents, start, end, "java.util.Collection<E extends java.lang.Object>", toFind, DeclarationKind.METHOD);
1450+
MethodNode m = assertDeclaration(contents, start, end, "java.util.List<java.lang.String>", toFind, DeclarationKind.METHOD);
14361451
assertEquals("java.util.Collection<?>", printTypeName(m.getParameters()[0].getType()));
14371452
}
14381453

@@ -1443,7 +1458,7 @@ public void testStaticMethod12() {
14431458
String toFind = "addAll";
14441459
int start = contents.indexOf(toFind), end = start + toFind.length();
14451460
assertType(contents, start, end, "java.lang.Boolean");
1446-
MethodNode m = assertDeclaration(contents, start, end, "java.util.Collection<java.lang.String>", toFind, DeclarationKind.METHOD);
1461+
MethodNode m = assertDeclaration(contents, start, end, "java.util.List<java.lang.String>", toFind, DeclarationKind.METHOD);
14471462
assertEquals("Parameter type should be resolved", "java.util.Collection<? extends java.lang.String>", printTypeName(m.getParameters()[0].getType()));
14481463
}
14491464

base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ protected MethodNode findMethodDeclaration(final String name, final ClassNode de
793793
return innerCandidate;
794794
}
795795
if (argumentTypes.size() == methodParameters.length) {
796-
outerCandidate = innerCandidate;
796+
outerCandidate = closer(innerCandidate, outerCandidate, argumentTypes);
797797

798798
Boolean suitable = isTypeCompatible(argumentTypes, methodParameters);
799799
if (Boolean.FALSE.equals(suitable)) {

0 commit comments

Comments
 (0)