diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/ClosureInferencingTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/ClosureInferencingTests.java index e45ad616ab..32549dfca7 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/ClosureInferencingTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/ClosureInferencingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 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. @@ -110,10 +110,10 @@ public void testClosure7() { " }\n" + " }\n" + "}"; - assertExprType(contents, "this", "Bar"); - assertExprType(contents, "super", "Foo"); - assertExprType(contents, "owner", "Bar"); - assertExprType(contents, "delegate", "Bar"); + assertExprType(contents, "this", "Bar"); + assertExprType(contents, "super", "Foo"); + assertExprType(contents, "owner", "Bar"); + assertExprType(contents, "delegate", "Bar"); } @Test // closure with non-default resolve strategy @@ -130,10 +130,10 @@ public void testClosure8() { " }\n" + " }\n" + "}"; - assertExprType(contents, "this", "Bar"); - assertExprType(contents, "super", "java.lang.Object"); - assertExprType(contents, "owner", "Bar"); - assertExprType(contents, "delegate", "Foo"); + assertExprType(contents, "this", "Bar"); + assertExprType(contents, "super", "java.lang.Object"); + assertExprType(contents, "owner", "Bar"); + assertExprType(contents, "delegate", "Foo"); } @Test // closure within static scope wrt owner @@ -148,8 +148,24 @@ public void testClosure9() { " }\n" + " }\n" + "}"; - assertExprType(contents, "owner", "java.lang.Class"); - assertExprType(contents, "delegate", "java.lang.Class"); + assertExprType(contents, "owner", "java.lang.Class"); + assertExprType(contents, "delegate", "java.lang.Class"); + } + + @Test // https://github.com/groovy/groovy-eclipse/issues/502 + public void testClosure9a() { + String contents = + "class Foo {\n" + + " static long bar(String arg) {\n" + + " }\n" + + " static void baz() {\n" + + " String a = 'bc'\n" + + " def closure = {\n" + + " bar(a)\n" + // call static method from closure within static scope + " }\n" + + " }\n" + + "}"; + assertExprType(contents, "bar", "java.lang.Long"); } @Test @@ -340,9 +356,9 @@ public void testClosure17() { " }\n" + " }\n" + "}"; - assertExprType(contents, "this", "B"); - assertExprType(contents, "super", "A"); - assertExprType(contents, "owner", "B"); + assertExprType(contents, "this", "B"); + assertExprType(contents, "super", "A"); + assertExprType(contents, "owner", "B"); assertExprType(contents, "delegate", "B"); } 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 084989b87d..d2d3efe653 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 @@ -172,7 +172,7 @@ protected ClassNode findDeclaringType(Expression node, VariableScope scope, Type // method call without an object expression; requires same handling as a free variable ClassNode ownerType; if (scope.getEnclosingClosure() != null) { - ownerType = scope.getOwner(); + ownerType = getBaseDeclaringType(scope.getOwner()); } else { ownerType = scope.getEnclosingTypeDeclaration(); } @@ -183,7 +183,7 @@ protected ClassNode findDeclaringType(Expression node, VariableScope scope, Type if (var != null && !(var instanceof Parameter || var instanceof VariableExpression)) { ClassNode ownerType; if (scope.getEnclosingClosure() != null) { - ownerType = scope.getOwner(); + ownerType = getBaseDeclaringType(scope.getOwner()); } else { ownerType = scope.getEnclosingTypeDeclaration(); }