Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [jdt-apt-dev] Question about JSR Annotations.

> In order for me to introspect a Class for annotations (say within a

> JDT listener code) how do I get hold of java.lang.Class in order to

> call the new jsr 175 APIs. Presently at runtime within eclipse there

> is no way of me getting a java.lang.Class from jdt IType. I want to

> react to annotation changes (additions/removal etc) that user enters

> while using the jdt editor. Should I be using AnnotationProcessor for

> this? Does the process API on the AnnotationProcessor get called only

> during a build?

 

Yes, you want to use an AnnotationProcessor. This will allow you to use the Mirror APIs to introspect java source code, rather than JSR-175, which was designed for run-time introspection of classes.

 

Mirror APIs can be found here: http://java.sun.com/j2se/1.5.0/docs/guide/apt/mirror/overview-summary.html

 

The process() API gets called during JDT’s reconcile and build pass. It is only possible to generate types during a build with the current implementation though.

 

>

> Thanks in advance -Manish

>

> PS. I am having some what hard time in getting the APTDemo to run as

> a plugin project. My runtime environment does not recongnize the 2

> annotations (DemoAnnotation and TypeGeneratingAnnotation) defined at

> all. I do see demo plugin in the Preferences setting though. Any

> ideas as to what am I missing? I have eclipse 3.1.1 and jre 5.0

 

You need to add your annotation classes to the classpath of the project you’re using.

 

Cheers,

Jess

 


Back to the top