diff options
author | Jayaprakash Arthanareeswaran | 2014-05-08 05:59:51 +0000 |
---|---|---|
committer | Jayaprakash Arthanareeswaran | 2014-05-09 12:35:11 +0000 |
commit | 27c1920f64a582c8b3fb2e33913ab524b814896a (patch) | |
tree | 0dd01b8e50ac7081857c9182baa604b99ccb8849 | |
parent | 202289a0f3ae102df5a7d1850f83bca79293b678 (diff) | |
download | eclipse.jdt.core-27c1920f64a582c8b3fb2e33913ab524b814896a.tar.gz eclipse.jdt.core-27c1920f64a582c8b3fb2e33913ab524b814896a.tar.xz eclipse.jdt.core-27c1920f64a582c8b3fb2e33913ab524b814896a.zip |
Fix for bug Bug 387956 - Adding testsI20140511-2000I20140510-1500I20140509-2000
9 files changed, 156 insertions, 1 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 28a23cf7d5..feeeb8c42d 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 @@ -5,3 +5,4 @@ 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 +org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.Bug387956Processor 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 d53dcb7e9e..624fbc4ebf 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 cc988bdfab..5393caeffb 100644 --- a/org.eclipse.jdt.apt.pluggable.tests/plugin.xml +++ b/org.eclipse.jdt.apt.pluggable.tests/plugin.xml @@ -40,6 +40,9 @@ <java6processor class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTester8Proc"> </java6processor> + <java6processor + class="org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.Bug387956Processor"> + </java6processor> </java6processors> </extension> </plugin> diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/Entity.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/Entity.java new file mode 100644 index 0000000000..b9ee2a7669 --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/Entity.java @@ -0,0 +1,12 @@ +package targets.bug387956; + +import targets.bug387956.Generate; + +/** + * Using {@link Generate} on {@link Entity} will generate the empty + * {@link generated.GeneratedEntity} class. + */ +@Generate +public class Entity { + +}
\ No newline at end of file diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/Generate.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/Generate.java new file mode 100644 index 0000000000..1fae923cbb --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/Generate.java @@ -0,0 +1,15 @@ +package targets.bug387956; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Used on a type "SomeType", generates a new empty class named + * "generated.GeneratedSomeType" + */ +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.TYPE) +public @interface Generate { +} diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/SomeAnnotation.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/SomeAnnotation.java new file mode 100644 index 0000000000..95389607e0 --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/SomeAnnotation.java @@ -0,0 +1,18 @@ +package targets.bug387956; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A useless annotation that is not processed by the annotation processor. Any + * annotation can be used instead of this one to reproduce the bug. + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.FIELD) +public @interface SomeAnnotation { + + int value(); + +} diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/SomeClass.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/SomeClass.java new file mode 100644 index 0000000000..ad4f78917e --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/bug387956/SomeClass.java @@ -0,0 +1,35 @@ +package targets.bug387956; + +/* + * The import triggers a compilation error, if SomeAnnotation has a reference to + * Integer.MAX_VALUE: "The import generated.GeneratedEntity cannot be resolved" + */ +import generated.GeneratedEntity; + + +@SuppressWarnings("unused") +public class SomeClass { + + /** + * The problem only occurs when you do a Project > Clean. It doesn't occur + * when saving the file without cleaning (incremental compilation), because + * cleaning removes generated.GeneratedEntity, which is then generated + * again. + * + * If you comment "@SomeAnnotation(Integer.MAX_VALUE)", the error + * disappears. + * + * If you replace Integer.MAX_VALUE with its value, the error disappears. + * + * This seems to be because {@link SomeAnnotation} fires the Eclipse + * annotation processing, which sees a reference that needs to be resolved + * (Integer.MAX_VALUE), and therefore tries to resolve imports, where it + * finds import {@link generated.GeneratedEntity} and cannot resolve it. + * + * This can happen with any annotation java 6 processor that generates code. + * Also note that I couldn't reproduce this on the simple java 5 processor + * given here: http://www.eclipse.org/jdt/apt/introToAPT.html + */ + @SomeAnnotation(Integer.MAX_VALUE) + Object none; +}
\ No newline at end of file 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 f4d308d476..96bc1be710 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 @@ -191,7 +191,7 @@ public class BuilderTests extends TestBase "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 - public void testBbug407841() throws Throwable { + public void testBug407841() 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; @@ -211,4 +211,16 @@ public class BuilderTests extends TestBase } } + public void testBug387956() throws Exception { + ProcessorTestStatus.reset(); + IJavaProject jproj = createJavaProject(_projectName); + disableJava5Factories(jproj); + IProject proj = jproj.getProject(); + IdeTestUtils.copyResources(proj, "targets/bug387956", "src/targets/bug387956"); + + AptConfig.setEnabled(jproj, true); + fullBuild(); + expectingNoProblems(); + } + } diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/Bug387956Processor.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/Bug387956Processor.java new file mode 100644 index 0000000000..62d79fa51d --- /dev/null +++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/Bug387956Processor.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.io.IOException; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +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; +import javax.tools.Diagnostic; +import javax.tools.JavaFileObject; + +@SupportedAnnotationTypes("targets.bug387956.Generate") +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class Bug387956Processor extends AbstractProcessor { + + RoundEnvironment roundEnv = null; + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + + for (TypeElement annotation : annotations) { + Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(annotation); + for (Element annotatedElement : annotatedElements) { + Filer filer = processingEnv.getFiler(); + String generatedClassSimpleName = "Generated" + annotatedElement.getSimpleName().toString(); + try { + JavaFileObject file = filer.createSourceFile("generated/" + generatedClassSimpleName, annotatedElement); + file.openWriter() // + .append("package generated;\n" // + + "\n" // + + "public class " + generatedClassSimpleName + " {\n" // + + "\n" // + + "}\n") // + .close(); + } catch (IOException e) { + Messager messager = processingEnv.getMessager(); + messager.printMessage(Diagnostic.Kind.ERROR, "IOException: " + e); + } + } + } + return true; + } +} |