Skip to content

Commit

Permalink
minor fix-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 5, 2019
1 parent 7660da0 commit 2c2ed17
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -48,22 +48,23 @@ 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 : </Project/src/Foo.groovy> range : <%d,%d> category : <150> severity : <2>]";
}

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);
Expand All @@ -83,71 +84,83 @@ 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");
}

@Test
public void testAccessForExtends() {
String source = "import java.beans.*\n" +
"class Foo extends BeanDescriptor {}";
"class Foo extends BeanDescriptor {\n" +
"}";

assertAccessRestriction(source, "BeanDescriptor");
}

@Test
public void testAccessForImplements() {
String source = "import java.beans.*\n" +
"abstract class Foo implements BeanInfo {}";
"abstract class Foo implements BeanInfo {\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
}

@Test
public void testAccessForExtendsGenerics() {
String source = "import java.beans.*\n" +
"abstract class Foo extends ArrayList<BeanDescriptor> {}";
"abstract class Foo extends ArrayList<BeanDescriptor> {\n" +
"}";

assertAccessRestriction(source, "BeanDescriptor");
}

@Test
public void testAccessForImplementsGenerics() {
String source = "import java.beans.*\n" +
"abstract class Foo implements List<BeanInfo> {}";
"abstract class Foo implements List<BeanInfo> {\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
}

@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");
}

@Test
public void testAccessForProperty() {
String source = "import java.beans.*\n" +
"class Foo { BeanInfo info }";
"class Foo {\n" +
" BeanInfo info\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
}

@Test
public void testAccessForFieldGenerics() {
String source = "import java.beans.*\n" +
"class Foo { private List<BeanInfo> info }";
"class Foo {\n" +
" private List<BeanInfo> info\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
}

@Test
public void testAccessForPropertyGenerics() {
String source = "import java.beans.*\n" +
"class Foo { List<BeanInfo> info }";
"class Foo {\n" +
" List<BeanInfo> info\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
}
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -187,8 +200,8 @@ public void testAccessForMethodReturnType() {
public void testAccessForMethodParameterGenerics() {
String source = "import java.beans.*\n" +
"class Foo {\n" +
" def meth(List<BeanInfo> info) { }\n" +
" }";
" def meth(List<BeanInfo> info) {}\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
}
Expand All @@ -197,7 +210,7 @@ public void testAccessForMethodParameterGenerics() {
public void testAccessForMethodReturnTypeGenerics() {
String source = "import java.beans.*\n" +
"class Foo {\n" +
" List<BeanInfo> meth() { }\n" +
" List<BeanInfo> meth() {}\n" +
"}";

assertAccessRestriction(source, "BeanInfo");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -273,23 +274,24 @@ public ClassNode resolve(String name) {
}
}

ClassNode firstClass = compilationUnit.getFirstClassNode();
String mainClassName = firstClass.getModule().getMainClassName();
Set<String> 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<ModuleNode> modules = compilationUnit.getAST().getModules();
if (!modules.isEmpty() && !modules.get(0).getClasses().isEmpty()) {
Set<String> 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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion extras/groovy-eclipse-compiler-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>run</goal>
</goals>
</execution>
Expand Down

0 comments on commit 2c2ed17

Please sign in to comment.