Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 195076 Details for
Bug 328575
Inheritance of annotation fails with generic classes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression test
patch_328575.txt (text/plain), 10.65 KB, created by
Olivier Thomann
on 2011-05-09 10:50:17 EDT
(
hide
)
Description:
Proposed fix + regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2011-05-09 10:50:17 EDT
Size:
10.65 KB
patch
obsolete
>### 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<Element> annotatedElements = new HashSet<Element>(_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<ReferenceBinding> annotationTypes = new HashSet<ReferenceBinding>(); > 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<? extends TypeElement> 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<String>(), 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); > } > > /**
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 328575
:
183392
|
184094
|
194881
|
194885
| 195076