public abstract class BasicAnnotationProcessor extends AbstractProcessor
Processor
implementation that ensures that top-level Element
instances are well-formed before attempting to perform processing on any of their children. In
the event that they are not, the element will be enqueued for processing in a subsequent round.
This ensures that processors will avoid many common pitfalls like ErrorType
instances,
ClassCastException
s and badly coerced types.
The primary disadvantage to this processor is that any Element
that forms a circular
dependency with a type generated by a subclass of this processor will never compile because the
given Element
will never be fully complete. All such compilations will fail with an error
message on the offending type that describes the issue.
Subclasses should put their processing logic in BasicAnnotationProcessor.ProcessingStep
implementations. The
steps are passed to the processor by returning them in the initSteps()
method - access
the ProcessingEnvironment
using AbstractProcessor.processingEnv
. Finally, any logic that needs to
happen once per round can be specified by overriding postProcess()
.
Modifier and Type | Class and Description |
---|---|
static interface |
BasicAnnotationProcessor.ProcessingStep
The unit of processing logic that runs under the guarantee that all elements are complete and
well-formed.
|
processingEnv
Constructor and Description |
---|
BasicAnnotationProcessor() |
Modifier and Type | Method and Description |
---|---|
com.google.common.collect.ImmutableSet<String> |
getSupportedAnnotationTypes()
Returns the set of supported annotation types as a collected from registered
processing steps.
|
void |
init(ProcessingEnvironment processingEnv) |
protected abstract Iterable<? extends BasicAnnotationProcessor.ProcessingStep> |
initSteps()
The mechanism by which processing steps are associated with the
processor.
|
protected void |
postProcess()
An optional hook for logic to be executed at the end of each round.
|
boolean |
process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) |
getCompletions, getSupportedOptions, getSupportedSourceVersion, isInitialized
public final void init(ProcessingEnvironment processingEnv)
init
in interface Processor
init
in class AbstractProcessor
protected abstract Iterable<? extends BasicAnnotationProcessor.ProcessingStep> initSteps()
protected void postProcess()
public final com.google.common.collect.ImmutableSet<String> getSupportedAnnotationTypes()
getSupportedAnnotationTypes
in interface Processor
getSupportedAnnotationTypes
in class AbstractProcessor
public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
process
in interface Processor
process
in class AbstractProcessor
Copyright © 2015 Google, Inc.. All rights reserved.