You are unable to access the Class the Annotation Processor is processing because the Class has not been compiled yet. Instead Java offers the analogous Elements api for reflection-style inspection of the input source.
The Element (which you found by using roundEnv.getRootElements()
) has much more information about the class being compiled than just its name. A ton of useful information can be found by using the ElementVisitors:
http://docs.oracle.com/javase/6/docs/api/javax/lang/model/element/ElementVisitor.html http://docs.oracle.com/javase/6/docs/api/javax/lang/model/util/ElementKindVisitor6.html
Including the classes constructor, methods, fields, etc.
Here's how to use it:
public class AnnotationProcessor extends AbstractProcessor {
......
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> rootE=roundEnv.getRootElements();
for(Element e: rootE) {
for(Element subElement : e.getEnclosedElements()){
subElement.accept(new ExampleVisitor(), null); // implement ExampleVisitor
}
}
}
}