The TwoPhaseCoreAnnotationProcessor class is an abstract class that implements the APT
CoreAnnotationProcessor interface. It breaks the work of the process() method of the
CoreAnnotationProcessor down into two distinct phases, represented as abstract method
of TwoPhaseCoreAnnotationProcessor that are to be implemented by concrete subclasses.
The two phases of processing are:
The check phase is used to validate input Declarations that have been
annotated with annotations claimed by the processor to ensure that it
is semantically valid. If the presence of the input Declaration implies the need
to add new files, and those files need to be visible during the check phase for
other Declarations, then the CoreAnnotationProcessorEnv's Filer API should be
used to add those files in this phase. The adding of such files at this point
should typically not result in their emission to persistent storage (i.e. disk),
but rather be kept in memory to be referenced by the check phase of other
Declarations.
The generate phase will actually emit any source, binary, or class files
that are derived from the input Declaration, including files added via the Filer
API during the check phase. The Filer API may also be used in this phase to add
new files, however, such additions will not be visible during the check phase of
any Declarations.
The benefits of breaking process() down into check() and generate() phases are:
Makes it possible to perform the semantic validation of Declarations without
necessarily resulting in code generation.
Provides a clearer association between input Declarations and generator output.
TwoPhaseCoreAnnotationProcessor is intended provide a uniform mechanism for writing
CoreAnnotationProcessor implementations that can be used in tooling environments more
sophisticated than command-line tools (that may not do all their work on source
in a single pass). Such environments will typically also provide implementations
of the CoreAnnotationProcessorEnv and associated interfaces (Messager,
Filer etc).