diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java index accd795ab5..191fe1e896 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/InferencingTests.java @@ -1063,6 +1063,57 @@ public void testStaticMethod9() throws Exception { assertType(contents, "meth(compile('abc'))", "java.util.regex.Pattern"); } + @Test + public void testStaticMethod10() throws Exception { + createUnit("foo", "Bar", "package foo\n" + + "import java.util.regex.*\n" + + "abstract class Bar {\n" + + " static Object meth(Object o) { return o;}\n" + + " static Pattern meth(Pattern p) { return p;}\n" + + " static Collection meth(Collection c) { return c;}\n" + + "}"); + + String contents = + "import static foo.Bar.*\n" + + "import static java.util.regex.Pattern.*\n" + + "meth(compile('abc'))"; + assertType(contents, "meth", "java.util.regex.Pattern"); + } + + @Test + public void testStaticMethod11() throws Exception { + String contents = + "import static java.util.regex.Pattern.*\n" + + "import java.util.regex.*\n" + + "abstract class Bar {\n" + + " static Object meth(Object o) { return o;}\n" + + " static Pattern meth(Pattern p) { return p;}\n" + + " static Collection meth(Collection c) { return c;}\n" + + " static main(args) {\n" + + " meth(compile('abc'))\n" + + " }\n" + + "}"; + assertType(contents, "meth", "java.util.regex.Pattern"); + } + + @Test + public void testStaticMethod12() throws Exception { + String contents = + "import static java.util.regex.Pattern.*\n" + + "import java.util.regex.*\n" + + "class Foo {\n" + + " static Object meth(Object o) { return o;}\n" + + " static Pattern meth(Pattern p) { return p;}\n" + + " static Collection meth(Collection c) { return c;}\n" + + "}\n" + + "abstract class Bar extends Foo {\n" + + " static main(args) {\n" + + " meth(compile('abc'))\n" + + " }\n" + + "}"; + assertType(contents, "meth", "java.util.regex.Pattern"); + } + @Test public void testStaticThisAndSuper1() { String contents = diff --git a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java index a1e3d77cff..fc75d6228a 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/SimpleTypeLookup.java @@ -302,12 +302,11 @@ protected TypeLookupResult findType(final Expression node, final ClassNode decla } else if (node instanceof StaticMethodCallExpression) { List candidates = new LinkedList<>(); java.util.function.BiConsumer collector = (classNode, methodName) -> { + // concrete types (without mixins/traits) return all methods from getMethods(String) if (classNode.isAbstract() || classNode.isInterface() || implementsTrait(classNode)) { - LinkedHashSet abstractTypes = new LinkedHashSet<>(); - VariableScope.findAllInterfaces(classNode, abstractTypes, false); - for (ClassNode abstractType : abstractTypes) { - candidates.addAll(abstractType.getMethods(methodName)); - } + LinkedHashSet hierarchy = new LinkedHashSet<>(); + VariableScope.createTypeHierarchy(classNode, hierarchy, false); + hierarchy.forEach(type -> candidates.addAll(type.getMethods(methodName))); } else { candidates.addAll(classNode.getMethods(methodName)); }