|
|
|
|
|
|
Re: Identifying Annotated POJOs inside a Jar File [message #636986 is a reply to message #636032] |
Wed, 03 November 2010 16:30 |
Walter Harley Messages: 847 Registered: July 2009 |
Senior Member |
|
|
On 10/28/10 11:13 PM, Tilak wrote:
> I use JDT API org.eclipse.jdt.internal.core.util.ClassFileReader to
> identify annotated POJOs, which doesn't provide functionality to
> identify a POJO as annotated if it's parent (interface) is already
> annotated.
If you're directly reading class files, you may have to navigate the
class hierarchy yourself, e.g., recursively find and open the parent
types to search for annotations.
If the annotation type you're looking for has
@Retention(RetentionType.RUNTIME) or @Retention(RetentionType.CLASS),
and if it has @Inherited, then the APT annotation processing API will
report a class as showing the annotation, if one of its superclasses is
annotated. Roughly the same is true of reading the class reflectively.
However, that does not apply to interfaces, only to superclasses. You
can read about that in the JDK docs [1].
I guess what I'm saying is that by the terms of Java, a POJO _is not_
annotated just because it implements an interface that happens to be
annotated. Therefore there is no direct way to ask a representation of
a class whether it is annotated in this way - rather, you have to walk
the supertype hierarchy and ask the individual interfaces whether they
have the annotation.
[1]
http://download.oracle.com/javase/1.5.0/docs/api/index.html? java/lang/annotation/Retention.html
|
|
|
Powered by
FUDForum. Page generated in 0.05984 seconds