In javax.annotation.processing
package there is a interface Processor
in which there is a function:
/**
* Processes a set of annotation types on type elements
* originating from the prior round and returns whether or not
* these annotation types are claimed by this processor. If {@code
* true} is returned, the annotation types are claimed and subsequent
* processors will not be asked to process them; if {@code false}
* is returned, the annotation types are unclaimed and subsequent
* processors may be asked to process them. A processor may
* always return the same boolean value or may vary the result
* based on chosen criteria.
*
* <p>The input set will be empty if the processor supports {@code
* "*"} and the root elements have no annotations. A {@code
* Processor} must gracefully handle an empty set of annotations.
*
* @param annotations the annotation types requested to be processed
* @param roundEnv environment for information about the current and prior round
* @return whether or not the set of annotation types are claimed by this processor
*/
boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv);
The Java API AbstractProcessor
implements above interface. Now I created my own processor class:
public class MyProcessor extends AbstractProcessor {
...
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation: annotations) {
// How can I get the class of the annotation ?
}
}
}
My questions:
- The API doc tells me the
annotations
in the process function are
the the annotation types requested to be processed
Then, why is it with type TypeElement
not java.lang.annotation.Annotation
? I get confused by this because I am not sure whether the annotations
actually mean the elements that being annotated or the real annotations annotating elements.
- Because of my 1st question above, how can I get each annotation's class from the
TypeElement
?