diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuildAccessRulesTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuildAccessRulesTests.java index e0c7a2b804..88781ab977 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuildAccessRulesTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuildAccessRulesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2019 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. @@ -48,14 +48,15 @@ public final class BuildAccessRulesTests extends BuilderTestSuite { @Before public void setUp() throws Exception { - IPath projectPath = env.addProject("Project"); + IPath projectPath = env.addProject("Project", "1.7"); env.setClasspath(projectPath, new IClasspathEntry[] { JavaCore.newSourceEntry(src = projectPath.append("src")), JavaCore.newContainerEntry(GroovyClasspathContainer.CONTAINER_ID), JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"), - new IAccessRule[] {new ClasspathAccessRule(new Path("java/beans/**"), IAccessRule.K_NON_ACCESSIBLE)}, null, false) // create access restriction + new IAccessRule[] {new ClasspathAccessRule(new Path("java/beans/**"), IAccessRule.K_NON_ACCESSIBLE)}, null, false), // create access restriction }); env.createFolder(src); + fullBuild(projectPath); problemFormat = "Problem : Access restriction: The type '%s' is not API (restriction on required library '##')" + " [ resource : range : <%d,%d> category : <150> severity : <2>]"; @@ -63,7 +64,7 @@ public void setUp() throws Exception { private void assertAccessRestriction(String source, String... types) { IPath foo = env.addGroovyClass(src, "Foo", source); - fullBuild(); + incrementalBuild(); // read back contents in case of line delimeters change or package statement addition or ... source = env.readTextFile(foo); @@ -83,7 +84,7 @@ private void assertAccessRestriction(String source, String... types) { @Test public void testAccessForImport() { - String source = "import java.beans.BeanDescriptor"; + String source = "import java.beans.BeanDescriptor\n"; assertAccessRestriction(source, "java.beans.BeanDescriptor"); } @@ -91,7 +92,8 @@ public void testAccessForImport() { @Test public void testAccessForExtends() { String source = "import java.beans.*\n" + - "class Foo extends BeanDescriptor {}"; + "class Foo extends BeanDescriptor {\n" + + "}"; assertAccessRestriction(source, "BeanDescriptor"); } @@ -99,7 +101,8 @@ public void testAccessForExtends() { @Test public void testAccessForImplements() { String source = "import java.beans.*\n" + - "abstract class Foo implements BeanInfo {}"; + "abstract class Foo implements BeanInfo {\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -107,7 +110,8 @@ public void testAccessForImplements() { @Test public void testAccessForExtendsGenerics() { String source = "import java.beans.*\n" + - "abstract class Foo extends ArrayList {}"; + "abstract class Foo extends ArrayList {\n" + + "}"; assertAccessRestriction(source, "BeanDescriptor"); } @@ -115,7 +119,8 @@ public void testAccessForExtendsGenerics() { @Test public void testAccessForImplementsGenerics() { String source = "import java.beans.*\n" + - "abstract class Foo implements List {}"; + "abstract class Foo implements List {\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -123,7 +128,9 @@ public void testAccessForImplementsGenerics() { @Test public void testAccessForField() { String source = "import java.beans.*\n" + - "class Foo { private BeanInfo info }"; + "class Foo {\n" + + " private BeanInfo info\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -131,7 +138,9 @@ public void testAccessForField() { @Test public void testAccessForProperty() { String source = "import java.beans.*\n" + - "class Foo { BeanInfo info }"; + "class Foo {\n" + + " BeanInfo info\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -139,7 +148,9 @@ public void testAccessForProperty() { @Test public void testAccessForFieldGenerics() { String source = "import java.beans.*\n" + - "class Foo { private List info }"; + "class Foo {\n" + + " private List info\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -147,7 +158,9 @@ public void testAccessForFieldGenerics() { @Test public void testAccessForPropertyGenerics() { String source = "import java.beans.*\n" + - "class Foo { List info }"; + "class Foo {\n" + + " List info\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -167,7 +180,7 @@ public void testAccessForLazyProperty() { public void testAccessForMethodParameter() { String source = "import java.beans.*\n" + "class Foo {\n" + - " def meth(BeanInfo info) { }\n" + + " def meth(BeanInfo info) {}\n" + "}"; assertAccessRestriction(source, "BeanInfo"); @@ -177,7 +190,7 @@ public void testAccessForMethodParameter() { public void testAccessForMethodReturnType() { String source = "import java.beans.*\n" + "class Foo {\n" + - " BeanInfo meth() { }\n" + + " BeanInfo meth() {}\n" + "}"; assertAccessRestriction(source, "BeanInfo"); @@ -187,8 +200,8 @@ public void testAccessForMethodReturnType() { public void testAccessForMethodParameterGenerics() { String source = "import java.beans.*\n" + "class Foo {\n" + - " def meth(List info) { }\n" + - " }"; + " def meth(List info) {}\n" + + "}"; assertAccessRestriction(source, "BeanInfo"); } @@ -197,7 +210,7 @@ public void testAccessForMethodParameterGenerics() { public void testAccessForMethodReturnTypeGenerics() { String source = "import java.beans.*\n" + "class Foo {\n" + - " List meth() { }\n" + + " List meth() {}\n" + "}"; assertAccessRestriction(source, "BeanInfo"); diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java index 90a7f770ec..33c225639b 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/JDTResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2019 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. @@ -27,6 +27,7 @@ import org.codehaus.groovy.ast.ClassHelper; import org.codehaus.groovy.ast.ClassNode; +import org.codehaus.groovy.ast.ModuleNode; import org.codehaus.groovy.control.CompilationFailedException; import org.codehaus.groovy.control.CompilationUnit; import org.codehaus.groovy.control.ResolveVisitor; @@ -273,23 +274,24 @@ public ClassNode resolve(String name) { } } - ClassNode firstClass = compilationUnit.getFirstClassNode(); - String mainClassName = firstClass.getModule().getMainClassName(); - Set unresolvable = unresolvables.computeIfAbsent(mainClassName, x -> new HashSet<>()); - if (!unresolvable.contains(name)) { - synchronized (this) { - ClassNode previousClass = currentClass; - try { - currentClass = firstClass.getPlainNodeReference(); - - ClassNode type = ClassHelper.makeWithoutCaching(name); - if (super.resolve(type, true, true, true)) { - return type.redirect(); - } else { - unresolvable.add(name); + List modules = compilationUnit.getAST().getModules(); + if (!modules.isEmpty() && !modules.get(0).getClasses().isEmpty()) { + Set unresolvable = unresolvables.computeIfAbsent(modules.get(0).getMainClassName(), x -> new HashSet<>()); + if (!unresolvable.contains(name)) { + synchronized (this) { + ClassNode previousClass = currentClass; + try { + currentClass = compilationUnit.getFirstClassNode().getPlainNodeReference(); + + ClassNode type = ClassHelper.makeWithoutCaching(name); + if (super.resolve(type, true, true, true)) { + return type.redirect(); + } else { + unresolvable.add(name); + } + } finally { + currentClass = previousClass; } - } finally { - currentClass = previousClass; } } } 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 97ce8a11aa..1ce28900e8 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 @@ -531,8 +531,7 @@ protected ASTNode findDeclarationForDynamicVariable(VariableExpression var, Clas VariableScope outer = owner.getNodeMetaData("outer.scope"); if (outer != null) { // owner is an enclosing closure if (isLhsExpr) scope.getWormhole().put("lhs", var); - VariableScope.CallAndType cat = outer.getEnclosingMethodCallExpression(); - int enclosingResolveStrategy = (cat == null ? 0 : cat.getResolveStrategy(outer.getEnclosingClosure())); + int enclosingResolveStrategy = outer.getEnclosingClosureResolveStrategy(); candidate = findDeclarationForDynamicVariable(var, getBaseDeclaringType(outer.getOwner()), outer, enclosingResolveStrategy); } else { candidate = findDeclaration(var.getName(), owner, isLhsExpr, scope.isOwnerStatic(), scope.isFieldAccessDirect(), callArgs); diff --git a/extras/groovy-eclipse-compiler-tests/pom.xml b/extras/groovy-eclipse-compiler-tests/pom.xml index 4ce010866d..741a58df9a 100644 --- a/extras/groovy-eclipse-compiler-tests/pom.xml +++ b/extras/groovy-eclipse-compiler-tests/pom.xml @@ -55,7 +55,6 @@ integration-test - integration-test run