types - Java 6 annotation processing -- getting a class from an annotation -


i have custom annotation called @pojo use automatic wiki documentation generation:

package com.example.annotations;  import java.lang.annotation.elementtype; import java.lang.annotation.retention; import java.lang.annotation.retentionpolicy; import java.lang.annotation.target;  @retention(retentionpolicy.source) @target(elementtype.method) public @interface pojo {     class<?> value(); } 

i use this:

@pojo(com.example.restserver.model.appointment.appointment.class) 

to annotation resource method annotation processor can automatically generate wiki page describing resource , type expects.

i need read value of value field in annotation processor, getting runtime error.

in source code processor have following lines:

final pojo pojo = element.getannotation(pojo.class); // ... final class<?> pojojavaclass = pojo.value(); 

but actual class in not available processor. think need javax.lang.model.type.typemirror instead surrogate real class. i'm not sure how one.

the error getting is:

javax.lang.model.type.mirroredtypeexception: attempt access class object typemirror com.example.restserver.model.appointment.appointment 

the appointment class mentioned in 1 of @pojo annotation.

unfortunately, document and/or tutorials on java annotation processing seems scarce. tried googling.

have read article: http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/ ?

there trick use getannotation() , catch mirroredtypeexception. surprisingly exception provides typemirror of required class.

i don't know if solution, one. in personal opinion try type behind mirroredtype, don't know if possible.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -