### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.compiler.apt Index: src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java,v retrieving revision 1.11 diff -u -r1.11 RoundEnvImpl.java --- src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java 19 Jul 2007 23:32:43 -0000 1.11 +++ src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java 9 May 2011 14:48:12 -0000 @@ -29,6 +29,7 @@ import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; +import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.TagBits; @@ -64,6 +65,9 @@ private void collectAnnotations(ReferenceBinding[] referenceBindings) { for (ReferenceBinding referenceBinding : referenceBindings) { // collect all annotations from the binary types + if (referenceBinding instanceof ParameterizedTypeBinding) { + referenceBinding = ((ParameterizedTypeBinding) referenceBinding).genericType(); + } AnnotationBinding[] annotationBindings = referenceBinding.getAnnotations(); for (AnnotationBinding annotationBinding : annotationBindings) { TypeElement anno = (TypeElement)_factory.newElement(annotationBinding.getAnnotationType()); @@ -127,7 +131,7 @@ Set annotatedElements = new HashSet(_annoToUnit.getValues(a)); // For all other root elements that are TypeElements, and for their recursively enclosed // types, add each element if it has a superclass are annotated with 'a' - ReferenceBinding annoTypeBinding = (ReferenceBinding)((TypeElementImpl)a)._binding; + ReferenceBinding annoTypeBinding = (ReferenceBinding) annoBinding; for (TypeElement element : ElementFilter.typesIn(getRootElements())) { ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding; addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements); @@ -162,15 +166,19 @@ * @return true if element has a superclass that is annotated with anno */ private boolean inheritsAnno(ReferenceBinding element, ReferenceBinding anno) { + ReferenceBinding searchedElement = element; do { - AnnotationBinding[] annos = element.getAnnotations(); + if (searchedElement instanceof ParameterizedTypeBinding) { + searchedElement = ((ParameterizedTypeBinding) searchedElement).genericType(); + } + AnnotationBinding[] annos = searchedElement.getAnnotations(); for (AnnotationBinding annoBinding : annos) { if (annoBinding.getAnnotationType() == anno) { // element is annotated with anno return true; } } - } while (null != (element = element.superclass())); + } while (null != (searchedElement = searchedElement.superclass())); return false; } Index: src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java,v retrieving revision 1.25.10.2 diff -u -r1.25.10.2 ElementsImpl.java --- src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java 21 Apr 2011 14:48:28 -0000 1.25.10.2 +++ src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java 9 May 2011 14:48:12 -0000 @@ -49,6 +49,7 @@ import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier; import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.TagBits; @@ -88,6 +89,9 @@ Set annotationTypes = new HashSet(); ReferenceBinding binding = (ReferenceBinding)((TypeElementImpl)e)._binding; while (null != binding) { + if (binding instanceof ParameterizedTypeBinding) { + binding = ((ParameterizedTypeBinding) binding).genericType(); + } for (AnnotationBinding annotation : binding.getAnnotations()) { if (annotation == null) continue; ReferenceBinding annotationType = annotation.getAnnotationType(); #P org.eclipse.jdt.compiler.apt.tests Index: processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/Attic/ArgsConstructorProcessor.java,v retrieving revision 1.1.2.1 diff -u -r1.1.2.1 ArgsConstructorProcessor.java --- processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java 6 May 2011 19:01:49 -0000 1.1.2.1 +++ processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java 9 May 2011 14:48:12 -0000 @@ -15,9 +15,10 @@ import java.util.Map.Entry; import java.util.Set; -import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.annotation.processing.*; import javax.lang.model.SourceVersion; @@ -28,10 +29,12 @@ import javax.tools.Diagnostic.Kind; import org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor; +import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor; @SupportedAnnotationTypes("org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor") @SupportedSourceVersion(SourceVersion.RELEASE_6) -public class ArgsConstructorProcessor extends AbstractProcessor { +public class ArgsConstructorProcessor extends BaseProcessor { + private TypeElement _elementAC; @Override public boolean process(Set annotations, @@ -40,8 +43,36 @@ for (TypeElement type : annotations) { processArgsConstructorClasses(env, type); } + + if (!collectElements()) { + reportError("Failed"); + return false; + } + TypeMirror superclass = _elementAC.getSuperclass(); + if (TypeKind.DECLARED != superclass.getKind()) { + reportError("Wrong type: should be a declared type"); + return false; + } + Element typeElement = _typeUtils.asElement(superclass); + if (typeElement.getAnnotationMirrors().size() != 1) { + reportError("Should contain an annotation"); + return false; + } + reportSuccess(); return true; + } + /** + * Collect some elements that will be reused in various tests + * @return true if all tests passed + */ + private boolean collectElements() { + _elementAC = _elementUtils.getTypeElement("targets.inherited.TestGenericChild"); + if (_elementAC == null) { + reportError("TestGenericChild was not found"); + return false; + } + return true; } private void processArgsConstructorClasses(RoundEnvironment env, Index: src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java,v retrieving revision 1.10.6.2 diff -u -r1.10.6.2 NegativeTests.java --- src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java 6 May 2011 19:01:49 -0000 1.10.6.2 +++ src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java 9 May 2011 14:48:12 -0000 @@ -61,6 +61,7 @@ // See corresponding usages in the NegativeModelProc class private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc"; + private static final String INHERITED_PROCNAME ="org.eclipse.jdt.compiler.apt.tests.processors.inherited.ArgsConstructorProcessor"; private static final String IGNOREJAVACBUGS = "ignoreJavacBugs"; @Override @@ -184,6 +185,7 @@ public void testNegativeModel10WithEclipseCompiler() throws IOException { JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); System.clearProperty(NEGATIVEMODELPROCNAME); + System.clearProperty(INHERITED_PROCNAME); File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited"); BatchTestUtils.copyResources("targets/inherited", targetFolder); @@ -202,6 +204,39 @@ "Class targets.inherited.TestNormalChild lacks a public constructor with args: java.awt.Point"; assertEquals("Wrong output", expectedErrors, String.valueOf(errBuffer)); + String property = System.getProperty(INHERITED_PROCNAME); + assertNotNull("No property - probably processing did not take place", property); + assertEquals("succeeded", property); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=328575 + */ + public void testNegativeModel10WithSystemCompiler() throws IOException { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + if (compiler == null) { + System.out.println("No system java compiler available"); + return; + } + System.clearProperty(NEGATIVEMODELPROCNAME); + System.clearProperty(INHERITED_PROCNAME); + File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited"); + BatchTestUtils.copyResources("targets/inherited", targetFolder); + + // Invoke processing by compiling the targets.model resources + ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); + PrintWriter printWriter = new PrintWriter(errBuffer); + TestDiagnosticListener diagnosticListener = new TestDiagnosticListener(printWriter); + boolean success = BatchTestUtils.compileTreeWithErrors(compiler, new ArrayList(), targetFolder, diagnosticListener); + + assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); + assertEquals("Two errors should be reported", 2, diagnosticListener.errorCounter); + printWriter.flush(); + printWriter.close(); + + String property = System.getProperty(INHERITED_PROCNAME); + assertNotNull("No property - probably processing did not take place", property); + assertEquals("succeeded", property); } /**