diff options
author | Till Brychcy | 2018-09-30 18:20:28 +0000 |
---|---|---|
committer | Till Brychcy | 2018-09-30 19:04:37 +0000 |
commit | 6373b82afa49b788930f634c152d22a5233860ad (patch) | |
tree | b9c224509e58ca822d7732a4f6b2327775002609 | |
parent | 3b66d562ce258059a9d1e585dd4f34250880f833 (diff) | |
download | eclipse.jdt.core-6373b82afa49b788930f634c152d22a5233860ad.tar.gz eclipse.jdt.core-6373b82afa49b788930f634c152d22a5233860ad.tar.xz eclipse.jdt.core-6373b82afa49b788930f634c152d22a5233860ad.zip |
Bug 539663 - [9] in named module, class created by annotation processorI20181002-0205I20181001-1800I20181001-0920
cannot be referenced in class that causes its creation
Change-Id: Ic5c984feeacc6820a2db70fb277a075244ae566d
5 files changed, 70 insertions, 6 deletions
diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/BuilderTests.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/BuilderTests.java index 8691015998..703df680d9 100644 --- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/BuilderTests.java +++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/BuilderTests.java @@ -388,4 +388,36 @@ public class BuilderTests extends TestBase fullBuild(); assertTrue("Processor should be able to compile with passed options", Bug341298Processor.success()); } + + public void testBug539663() throws Throwable { + if (!canRunJava9()) { + return; + } + ProcessorTestStatus.reset(); + IJavaProject jproj = createJava9Project(_projectName); + disableJava5Factories(jproj); + IProject proj = jproj.getProject(); + IPath projPath = proj.getFullPath(); + IPath root = projPath.append("src"); + IPath packagePath = root.append("test"); + try { + env.addClass(root, null, "module-info", "module example {}"); + + env.addClass(root, "test", "Foo", + "package test;\n" + + "import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6;\n" + + "@GenClass6(name = \"ImmutableFoo\", pkg = \"test\")\n" + + "public class Foo {\n" + + " public void f(ImmutableFoo o) { }\n" + + "}"); + AptConfig.setEnabled(jproj, true); + + fullBuild(); + expectingNoProblems(); + } finally { + env.removeClass(packagePath, "module-info"); + env.removeClass(packagePath, "Foo"); + env.removeClass(packagePath, "ImmutableFoo"); + } + } } diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java index d87bfff38d..480926c0eb 100644 --- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java +++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java @@ -19,6 +19,8 @@ import java.io.InputStream; import java.net.URL; import java.util.Map; +import javax.lang.model.SourceVersion; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -38,6 +40,7 @@ public class TestBase extends BuilderTests protected static final String JAVA_16_COMPLIANCE = "1.6"; protected static final String JAVA_18_COMPLIANCE = "1.8"; + protected static final String JAVA_9_COMPLIANCE = "9"; protected String _projectName; protected static int _projectSerial = 0; // used to create unique project names, to avoid resource deletion problems @@ -119,7 +122,29 @@ public class TestBase extends BuilderTests addAnnotationJar(javaProj); return javaProj; } - + + /** + * Create a java project with java libraries and test annotations on classpath + * (compiler level is 1.9). Use "src" as source folder and "bin" as output folder. APT + * is not enabled. + * + * @param projectName + * @return a java project that has been added to the current workspace. + * @throws Exception + */ + protected static IJavaProject createJava9Project(final String projectName) throws Exception { + // Note, make sure this is run only with a JRE 9 and above. + IPath projectPath = env.addProject(projectName, JAVA_9_COMPLIANCE); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + final IJavaProject javaProj = env.getJavaProject(projectPath); + addAnnotationJar(javaProj); + return javaProj; + } + /** * Ensure that there are no Java 5 processors on the factory path, as they can cause * units to be multiply compiled, which can mess up tests that expect a certain number @@ -177,5 +202,12 @@ public class TestBase extends BuilderTests env.setAutoBuilding(false); _projectName = String.format("testproj%04d", ++_projectSerial); } - + public boolean canRunJava9() { + try { + SourceVersion.valueOf("RELEASE_9"); + } catch(IllegalArgumentException iae) { + return false; + } + return true; + } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java index 78142a01f6..cdd7675932 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java @@ -276,7 +276,7 @@ public class ClassScope extends Scope { int count = 0; nextMember : for (int i = 0; i < length; i++) { TypeDeclaration memberContext = this.referenceContext.memberTypes[i]; - if (this.environment().isProcessingAnnotations && this.environment().isMissingType(memberContext.name)) { + if (this.environment().root.isProcessingAnnotations && this.environment().isMissingType(memberContext.name)) { throw new SourceTypeCollisionException(); // resolved a type ref before APT generated the type } switch(TypeDeclaration.kind(memberContext.modifiers)) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java index a4394594eb..81179a7fe1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java @@ -158,7 +158,7 @@ void buildTypeBindings(AccessRestriction accessRestriction) { int count = 0; nextType: for (int i = 0; i < typeLength; i++) { TypeDeclaration typeDecl = types[i]; - if (this.environment.isProcessingAnnotations && this.environment.isMissingType(typeDecl.name)) + if (this.environment.root.isProcessingAnnotations && this.environment.isMissingType(typeDecl.name)) throw new SourceTypeCollisionException(); // resolved a type ref before APT generated the type ReferenceBinding typeBinding = this.fPackage.getType0(typeDecl.name); if (Binding.isValid(typeBinding) && this.fPackage instanceof SplitPackageBinding && !this.environment.module.canAccess(typeBinding.fPackage)) @@ -166,7 +166,7 @@ void buildTypeBindings(AccessRestriction accessRestriction) { recordSimpleReference(typeDecl.name); // needed to detect collision cases if (Binding.isValid(typeBinding) && !(typeBinding instanceof UnresolvedReferenceBinding)) { // if its an unresolved binding - its fixed up whenever its needed, see UnresolvedReferenceBinding.resolve() - if (this.environment.isProcessingAnnotations) + if (this.environment.root.isProcessingAnnotations) throw new SourceTypeCollisionException(); // resolved a type ref before APT generated the type // if a type exists, check that its a valid type // it can be a NotFound problem type if its a secondary type referenced before its primary type found in additional units diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java index 142fbe26dc..31672e0519 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java @@ -120,7 +120,7 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants { private ArrayList missingTypes; Set<SourceTypeBinding> typesBeingConnected; // SHARED - public boolean isProcessingAnnotations = false; + public boolean isProcessingAnnotations = false; // ROOT_ONLY public boolean mayTolerateMissingType = false; PackageBinding nullableAnnotationPackage; // the package supposed to contain the Nullable annotation type |