Bug 336566 - Inherited annotations from a super class aren't returned by getAnnotation
Summary: Inherited annotations from a super class aren't returned by getAnnotation
Status: RESOLVED DUPLICATE of bug 270754
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 3.7   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Generic inbox for the JDT-APT component CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-07 16:48 EST by Eric Bartley CLA
Modified: 2011-02-23 02:40 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Bartley CLA 2011-02-07 16:48:47 EST
Build Identifier: 20100917-0705

Java doc for javax.lang.model.element.Element.getAnnotation(Class<A> annotationType) says "The annotation may be either inherited or directly present on this element."

I'm not seeing the behavior when my annotation processing is running in Eclipse.


Reproducible: Always

Steps to Reproduce:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface A {
}
----------
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface B {
}
----------
@A
public class ClassA {
}
----------
@B
public class ClassB extends ClassA {
}
----------
	@Override
	public boolean process(Set<? extends TypeElement> arg0,
			RoundEnvironment arg1) {
		Set<? extends Element> elements = arg1.getElementsAnnotatedWith(B.class);
		
		for (Element e : elements) {
			A a = e.getAnnotation(A.class);
			if (a == null) {
				processingEnv.getMessager().printMessage(Kind.ERROR, "No inherited annotation.");
			}
		}
		return false;
	}


I would expect the call to return the super classes annotation not null.
Comment 1 Stephan Herrmann CLA 2011-02-22 14:20:03 EST
Is this the same as bug 270754?
Comment 2 Eric Bartley CLA 2011-02-22 14:25:04 EST
(In reply to comment #1)

No, that bug is about when the processor gets invoked. This bug is about the type mirror model eclipse is exposing via java.lang.model
Comment 3 Stephan Herrmann CLA 2011-02-22 14:55:51 EST
(In reply to comment #2)
> (In reply to comment #1)
> 
> No, that bug is about when the processor gets invoked. This bug is about the
> type mirror model eclipse is exposing via java.lang.model

For the initial issue of that bug you're right, but looking at 
bug 270754 comment 6 I seem to see a connection between both issues, no?
Comment 4 Eric Bartley CLA 2011-02-22 15:16:24 EST
(In reply to comment #3)

Ya looks like, you can close this as a dup
Comment 5 Stephan Herrmann CLA 2011-02-22 15:41:39 EST
(In reply to comment #4)
> (In reply to comment #3)
> 
> Ya looks like, you can close this as a dup

Thanks for confirming.
Yet, for closing we need a JDT-APT committer :)
Comment 6 Walter Harley CLA 2011-02-23 02:40:30 EST
Yes, I agree this is a duplicate.

*** This bug has been marked as a duplicate of bug 270754 ***