diff options
author | Jayaprakash Arthanareeswaran | 2014-03-19 13:56:40 +0000 |
---|---|---|
committer | Jayaprakash Arthanareeswaran | 2014-04-14 07:22:21 +0000 |
commit | c8da4a40a8568b9c631912d3263d6c1940c37ca8 (patch) | |
tree | 5f67dbe4c871e351c0baab3ae802bbd8f8601fe8 | |
parent | 35868a2bd44946bcaa16cc791e1a3f869f5cd6bb (diff) | |
download | eclipse.jdt.core-c8da4a40a8568b9c631912d3263d6c1940c37ca8.tar.gz eclipse.jdt.core-c8da4a40a8568b9c631912d3263d6c1940c37ca8.tar.xz eclipse.jdt.core-c8da4a40a8568b9c631912d3263d6c1940c37ca8.zip |
Bug 407841 - Compiler ignores the compilation units marked as
isImplicitUnit when compiled in multiple batches
9 files changed, 134 insertions, 7 deletions
diff --git a/org.eclipse.jdt.apt.pluggable.tests/META-INF/services/javax.annotation.processing.Processor b/org.eclipse.jdt.apt.pluggable.tests/META-INF/services/javax.annotation.processing.Processor index 1b45c046e0..28a23cf7d5 100644 --- a/org.eclipse.jdt.apt.pluggable.tests/META-INF/services/javax.annotation.processing.Processor +++ b/org.eclipse.jdt.apt.pluggable.tests/META-INF/services/javax.annotation.processing.Processor @@ -3,4 +3,5 @@ org.eclipse.jdt.apt.pluggable.tests.processors.message6.Message6Proc org.eclipse.jdt.apt.pluggable.tests.processors.filertester.FilerTesterProc org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.TestFinalRoundProc +org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.BugsProc org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc diff --git a/org.eclipse.jdt.apt.pluggable.tests/lib/annotations.jar b/org.eclipse.jdt.apt.pluggable.tests/lib/annotations.jar Binary files differindex 693ee8154d..f9febfbdd9 100644 --- a/org.eclipse.jdt.apt.pluggable.tests/lib/annotations.jar +++ b/org.eclipse.jdt.apt.pluggable.tests/lib/annotations.jar diff --git a/org.eclipse.jdt.apt.pluggable.tests/plugin.xml b/org.eclipse.jdt.apt.pluggable.tests/plugin.xml index cd521def4b..806cb32707 100644 --- a/org.eclipse.jdt.apt.pluggable.tests/plugin.xml +++ b/org.eclipse.jdt.apt.pluggable.tests/plugin.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <!-- - Copyright (c) 2005, 2010 IBM Corporation and others. + Copyright (c) 2005, 2014 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at @@ -32,6 +32,9 @@ class="org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.TestFinalRoundProc"> </java6processor> <java6processor + class="org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.BugsProc"> + </java6processor> + <java6processor class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc"> </java6processor> </java6processors> diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug407841/ModuleCore.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug407841/ModuleCore.java new file mode 100644 index 0000000000..c8a6cec53a --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug407841/ModuleCore.java @@ -0,0 +1,11 @@ +package targets.bug407841; + +import targets.bug407841.ModuleLegacy; +import org.eclipse.jdt.apt.pluggable.tests.annotations.Module; + +@Module(key=ModuleCore.KEY) +public class ModuleCore +{ + public static final String LEGACY_KEY = ModuleLegacy.KEY; + public static final String KEY = "CORE"; +}
\ No newline at end of file diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug407841/ModuleLegacy.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug407841/ModuleLegacy.java new file mode 100644 index 0000000000..59fe6258ca --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug407841/ModuleLegacy.java @@ -0,0 +1,9 @@ +package targets.bug407841; + +import targets.bug407841.ModuleCore; +import org.eclipse.jdt.apt.pluggable.tests.annotations.Module; + +@Module(key=ModuleCore.KEY) +public class ModuleLegacy { + public static final String KEY = "LEGACY"; +} 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 928667a889..9c3294d5a6 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 - 2010 Walter Harley and others + * Copyright (c) 2008 - 2014 Walter Harley and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,6 +19,7 @@ import junit.framework.TestSuite; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.apt.core.util.AptConfig; +import org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.BugsProc; import org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc; import org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.TestFinalRoundProc; import org.eclipse.jdt.core.IJavaProject; @@ -189,4 +190,26 @@ public class BuilderTests extends TestBase "Problem : FooEvent cannot be resolved to a type [ resource : </" + _projectName + "/src/test295948/FooImpl.java> range : <108,116> category : <40> severity : <2>]\n" + "Problem : FooEvent cannot be resolved to a type [ resource : </" + _projectName + "/src/test295948/FooImpl.java> range : <52,60> category : <40> severity : <2>]"); } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=407841 + @SuppressWarnings("restriction") + public void testBbug407841() throws Throwable { + int old = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE =1; + ProcessorTestStatus.reset(); + IJavaProject jproj = createJavaProject(_projectName); + disableJava5Factories(jproj); + IProject proj = jproj.getProject(); + IdeTestUtils.copyResources(proj, "targets/bug407841", "src/targets/bug407841"); + + AptConfig.setEnabled(jproj, true); + fullBuild(); + expectingNoProblems(); + assertEquals("Elements should have been processed", 0, BugsProc.getUnprocessedElements()); + assertEquals("Elements should have been processed", 3, BugsProc.getNumRounds()); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = old; + } + } + } diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/Module.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/Module.java new file mode 100644 index 0000000000..f96044ac91 --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/Module.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.apt.pluggable.tests.annotations; + +public @interface Module { + String key(); +}
\ No newline at end of file diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/BugsProc.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/BugsProc.java new file mode 100644 index 0000000000..3dcf5def26 --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/BugsProc.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.apt.pluggable.tests.processors.buildertester; + +import java.util.HashSet; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; + +@SupportedAnnotationTypes({"org.eclipse.jdt.apt.pluggable.tests.annotations.Module"}) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class BugsProc extends AbstractProcessor { + + private static final String[] ELEMENT_NAMES = new String[] {"targets.bug407841.ModuleCore", "targets.bug407841.ModuleLegacy"}; + private static HashSet<String> expectedElements = new HashSet<String>(2); + private static int _numRounds = 0; + { + for (String name : ELEMENT_NAMES) { + expectedElements.add(name); + } + } + RoundEnvironment roundEnv = null; + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + _numRounds++; + this.roundEnv = roundEnv; + for (TypeElement element : annotations) { + Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(element); + for (Element e : elements) { + expectedElements.remove(e.asType().toString()); + } + } + return true; + } + + public static int getNumRounds() { + return _numRounds; + } + + public static int getUnprocessedElements() { + return expectedElements.size(); + } +} diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java index 780aa65aba..2651c8377b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -326,7 +326,6 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { } else { parsedUnit = this.parser.dietParse(sourceUnit, unitResult); } - parsedUnit.bits |= ASTNode.IsImplicitUnit; // initial type binding creation this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); addCompilationUnit(sourceUnit, parsedUnit); @@ -811,14 +810,23 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { int index = 0; for (int i = bottom; i < top; i++) { CompilationUnitDeclaration currentUnit = this.unitsToProcess[i]; - if ((currentUnit.bits & ASTNode.IsImplicitUnit) == 0) { - currentUnits[index++] = currentUnit; - } + currentUnits[index++] = currentUnit; } if (index != length) { System.arraycopy(currentUnits, 0, (currentUnits = new CompilationUnitDeclaration[index]), 0, index); } this.annotationProcessorManager.processAnnotations(currentUnits, binaryTypeBindingsTemp, false); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=407841 + // It is possible that during the #processAnnotations() call, some units in the next batch would have been + // brought forward and compiled already. If there are any such, process them for annotations then and there. + // This would avoid the complications of marking some units as compiled but not-annotation-processed-yet. + if (top < this.totalUnits) { + length = this.totalUnits - top; // NOTE: Reuse the same variable, but make sure it's not used after this point + CompilationUnitDeclaration[] addedUnits = new CompilationUnitDeclaration[length]; + System.arraycopy(this.unitsToProcess, top, addedUnits, 0, length); + this.annotationProcessorManager.processAnnotations(addedUnits, binaryTypeBindingsTemp, false); + this.annotationProcessorStartIndex = top; + } ICompilationUnit[] newUnits = this.annotationProcessorManager.getNewUnits(); newUnitSize = newUnits.length; ReferenceBinding[] newClassFiles = this.annotationProcessorManager.getNewClassFiles(); |