org.apache.beehive.wsm.jsr181.processor.apt
Class TwoPhaseAnnotationProcessor
Object
TwoPhaseAnnotationProcessor
- All Implemented Interfaces:
- AnnotationProcessor
- Direct Known Subclasses:
- WsmAnnotationProcessor
public abstract class TwoPhaseAnnotationProcessor
- extends Object
- implements AnnotationProcessor
The TwoPhaseAnnotationProcessor class is an abstract class that implements the APT
AnnotationProcessor interface. It breaks the work of the process() method of the
AnnotationProcessor down into two distinct phases, represented as abstract method
of TwoPhaseAnnotationProcessor 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 AnnotationProcessorEnvironment'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.
TwoPhaseAnnotationProcessor is intended provide a uniform mechanism for writing
AnnotationProcessor 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 AnnotationProcessorEnvironment and associated interfaces (Messager,
Filer etc).
Method Summary |
void |
check()
Performs semantic validation of input Declarations that are annotated with
annotations claimed by this AnnotationProcessor. |
abstract void |
check(Declaration decl)
The check method is responsible for all semantic validation of the input Declaration. |
void |
generate()
Emits additional artifacts for input Declarations that are annotated with
annotations claimed by this AnnotationProcessor. |
abstract void |
generate(Declaration decl)
The generate method is responsible for the generation of any additional artifacts
(source, class, or binary) that are derived from the input Declaration. |
protected AnnotationProcessorEnvironment |
getAnnotationProcessorEnvironment()
|
void |
process()
Implements AnnotationProcessor.process() as two phases, "check" and "generate". |
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TwoPhaseAnnotationProcessor
public TwoPhaseAnnotationProcessor(Set<AnnotationTypeDeclaration> atds,
AnnotationProcessorEnvironment env)
process
public void process()
- Implements AnnotationProcessor.process() as two phases, "check" and "generate".
- Specified by:
process
in interface AnnotationProcessor
check
public void check()
- Performs semantic validation of input Declarations that are annotated with
annotations claimed by this AnnotationProcessor.
generate
public void generate()
throws ProcessorException
- Emits additional artifacts for input Declarations that are annotated with
annotations claimed by this AnnotationProcessor.
- Throws:
ProcessorException
check
public abstract void check(Declaration decl)
- The check method is responsible for all semantic validation of the input Declaration.
All semantic warnings/errors associated with the input Declaration should
be output during check via a Messager obtained from the
AnnotationProcessorEnvironment.
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 AnnotationProcessorEnvironment'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.
generate
public abstract void generate(Declaration decl)
- The generate method is responsible for the generation of any additional artifacts
(source, class, or binary) that are derived from the input Declaration.
getAnnotationProcessorEnvironment
protected AnnotationProcessorEnvironment getAnnotationProcessorEnvironment()