public abstract class AbstractTypeProcessor extends AbstractProcessor
Type processing occurs in one round after the tool (e.g. Java compiler) analyzes the source (all sources taken as input to the tool and sources generated by other annotation processors).
The tool infrastructure will interact with classes extending this abstract class as follows.
1-3 are identical to the Processor
life cycle. 4-5 are unique to AbstractTypeProcessor
subclasses.
Processor
object is not being used, to create an instance of a
processor the tool calls the no-arg constructor of the processor class.
init
method with an appropriate ProcessingEnvironment
.
getSupportedAnnotationTypes
, getSupportedOptions
, and getSupportedSourceVersion
. These methods are only called once
per run, not on each round.
typeProcess
method on the Processor
. The class
is guaranteed to be type-checked Java code and all the tree type and symbol information is
resolved.
typeProcessingOver
method on the
Processor
.
The tool is permitted to ask type processors to process a class once it is analyzed before the
rest of classes are analyzed. The tool is also permitted to stop type processing immediately if
any errors are raised, without invoking typeProcessingOver
A subclass may override any of the methods in this class, as long as the general Processor
contract is obeyed, with one notable exception.
process(Set, RoundEnvironment)
may not be overridden, as it is called during the
declaration annotation phase before classes are analyzed.
processingEnv
Modifier | Constructor and Description |
---|---|
protected |
AbstractTypeProcessor()
Constructor for subclasses to call.
|
Modifier and Type | Method and Description |
---|---|
void |
init(ProcessingEnvironment env) |
boolean |
process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv)
The use of this method is obsolete in type processors.
|
abstract void |
typeProcess(TypeElement element,
TreePath tree)
Processes a fully-analyzed class that contains a supported annotation (see
AbstractProcessor.getSupportedAnnotationTypes() ). |
void |
typeProcessingOver()
A method to be called once all the classes are processed and no error is reported.
|
void |
typeProcessingStart()
A method to be called once before the first call to typeProcess.
|
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, isInitialized
protected AbstractTypeProcessor()
public void init(ProcessingEnvironment env)
Register a TaskListener that will get called after FLOW.
init
in interface Processor
init
in class AbstractProcessor
public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
process
in interface Processor
process
in class AbstractProcessor
public void typeProcessingStart()
Subclasses may override this method to do any initialization work.
public abstract void typeProcess(TypeElement element, TreePath tree)
AbstractProcessor.getSupportedAnnotationTypes()
).
The passed class is always valid type-checked Java code.
element
- element of the analyzed classtree
- the tree path to the element, with the leaf being a ClassTree
public void typeProcessingOver()
Subclasses may override this method to do any aggregate analysis (e.g. generate report, persistence) or resource deallocation.
If an error (a Java error or a processor error) is reported, this method is not guaranteed to be invoked.