Processor implementation that defers processing of Elements to later
rounds if they cannot be processed.
Subclasses put their processing logic in Step implementations. The steps are passed to
the processor by returning them in the steps() method, and can access the ProcessingEnvironment using processingEnv.
Any logic that needs to happen once per round can be specified by overriding postRound(RoundEnvironment).
Step. This helps processors to avoid many common pitfalls, such as ErrorType instances, ClassCastExceptions and badly coerced types.
A non-package element is considered well-formed if its type, type parameters, parameters,
default values, supertypes, annotations, and enclosed elements are. Package elements are treated
similarly, except that their enclosed elements are not validated. See SuperficialValidation#validateElement(Element) for details.
The primary disadvantage to this validation is that any element that forms a circular
dependency with a type generated by another BasicAnnotationProcessor will never compile
because the element will never be fully complete. All such compilations will fail with an error
message on the offending type that describes the issue.
Step can defer elementsEach Step can defer elements by including them in the set returned by Step#process(ImmutableSetMultimap); elements deferred by a step will be passed back to that step
in a later round of processing.
This feature is useful when one processor may depend on code generated by another, independent
processor, in a way that isn't caught by the well-formedness check described above. For example,
if an element A cannot be processed because processing it depends on the existence of
some class B, then A should be deferred until a later round of processing, when
B will have been generated by another processor.
If A directly references B, then the well-formedness check will correctly
defer processing of A until B has been generated.
However, if A references B only indirectly (for example, from within a method
body), then the well-formedness check will not defer processing A, but a processing step
can reject A.
| Modifier and Type | Class and Description |
|---|---|
| private static class | BasicAnnotationProcessor.ElementName
A package or type name. |
| public static interface | BasicAnnotationProcessor.ProcessingStep
Deprecated
Implement The unit of processing logic that runs under the guarantee that all elements are complete and
well-formed.
Step instead.
|
| private static class | |
| public static interface | BasicAnnotationProcessor.Step
The unit of processing logic that runs under the guarantee that all elements are complete and well-formed. |
| Modifier and Type | Field and Description |
|---|---|
| private final Set | |
| private Elements | |
| private final SetMultimap | |
| private Messager | |
| private ImmutableList |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected static BasicAnnotationProcessor. | asStep(BasicAnnotationProcessor.
Deprecated
as a consequence of
Wraps the passed BasicAnnotationProcessor.ProcessingStep being deprecated.
ProcessingStep in a Step.
|
| private static void | findAnnotatedElements(Element element, ImmutableSet<TypeElement> annotationTypes, ImmutableSetMultimap.
Adds |
| private static TypeElement | getEnclosingType(Element element)
Returns the nearest enclosing |
| private ImmutableSet | |
| private ImmutableSet | |
| public final ImmutableSet | getSupportedAnnotationTypes()
Overrides javax. Implements javax. |
| private ImmutableSetMultimap | indexByAnnotation(Set<BasicAnnotationProcessor.
|
| public final synchronized void | init(ProcessingEnvironment
environment to access facilities the tool framework
provides to the processor processingEnv)Overrides javax. Implements javax. processingEnv field to the value of the
processingEnv argument.
|
| protected Iterable | |
| protected void | postProcess()
Deprecated
use
An optional hook for logic to be executed at the end of each round.
postRound(RoundEnvironment) instead
|
| protected void | postRound(RoundEnvironment roundEnv)
An optional hook for logic to be executed at the end of each round. |
| public final boolean | process(Set<? extends TypeElement>
the annotation interfaces requested to be processed annotations, RoundEnvironment environment for information about the current and prior round roundEnv)Implements abstract javax. Implements javax. |
| private void | process(ImmutableSetMultimap<TypeElement, Element> validElements)
Processes the valid elements, including those previously deferred by each step. |
| private String | |
| private void | |
| protected Iterable | |
| private static ImmutableSetMultimap | |
| private ImmutableSetMultimap | validElements(RoundEnvironment roundEnv)
Returns the valid annotated elements contained in all of the deferred elements. |
| deferredElementNames | back to summary |
|---|---|
| private final Set<BasicAnnotationProcessor. | |
| elements | back to summary |
|---|---|
| private Elements elements | |
| elementsDeferredBySteps | back to summary |
|---|---|
| private final SetMultimap<BasicAnnotationProcessor. | |
| messager | back to summary |
|---|---|
| private Messager messager | |
| steps | back to summary |
|---|---|
| private ImmutableList<? extends BasicAnnotationProcessor. | |
| BasicAnnotationProcessor | back to summary |
|---|---|
| public BasicAnnotationProcessor() | |
| asStep | back to summary |
|---|---|
| protected static BasicAnnotationProcessor. Deprecated as a consequence of Wraps the passed | |
| findAnnotatedElements | back to summary |
|---|---|
| private static void findAnnotatedElements(Element element, ImmutableSet<TypeElement> annotationTypes, ImmutableSetMultimap. Adds
| |
| getEnclosingType | back to summary |
|---|---|
| private static TypeElement getEnclosingType(Element element) Returns the nearest enclosing | |
| getSupportedAnnotationTypeElements | back to summary |
|---|---|
| private ImmutableSet | |
| getSupportedAnnotationTypeElements | back to summary |
|---|---|
| private ImmutableSet | |
| getSupportedAnnotationTypes | back to summary |
|---|---|
| public final ImmutableSet Overrides javax. Implements javax. Returns the set of supported annotation types as collected from registered processing steps.
| |
| indexByAnnotation | back to summary |
|---|---|
| private ImmutableSetMultimap | |
| init | back to summary |
|---|---|
| public final synchronized void init(ProcessingEnvironment processingEnv) Overrides javax. Implements javax. Doc from javax. Initializes the processor with the processing environment by
setting the
| |
| initSteps | back to summary |
|---|---|
| protected Iterable Deprecated Implement Creates processing steps for this processor.
| |
| postProcess | back to summary |
|---|---|
| protected void postProcess()
Deprecated use An optional hook for logic to be executed at the end of each round.
| |
| postRound | back to summary |
|---|---|
| protected void postRound(RoundEnvironment roundEnv) An optional hook for logic to be executed at the end of each round. | |
| process | back to summary |
|---|---|
| public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Implements abstract javax. Implements javax. Doc from javax. Processes a set of annotation interfaces on root elements originating
from the prior round and returns whether or not these
annotation interfaces are claimed by this processor. If The input set will be empty if the processor supports
| |
| process | back to summary |
|---|---|
| private void process(ImmutableSetMultimap<TypeElement, Element> validElements) Processes the valid elements, including those previously deferred by each step. | |
| processingErrorMessage | back to summary |
|---|---|
| private String processingErrorMessage(String target) | |
| reportMissingElements | back to summary |
|---|---|
| private void reportMissingElements(Set<BasicAnnotationProcessor. | |
| steps | back to summary |
|---|---|
| protected Iterable Creates processing steps for this processor. Note If you are migrating some steps from | |
| toClassNameKeyedMultimap | back to summary |
|---|---|
| private static ImmutableSetMultimap | |
| validElements | back to summary |
|---|---|
| private ImmutableSetMultimap Returns the valid annotated elements contained in all of the deferred elements. If none are found for a deferred element, defers it again. | |
It's unfortunate that we have to track types and packages separately, but since there are
two different methods to look them up in Elements, we end up with a lot of parallel
logic. :(
Packages declared (and annotated) in package-info.java are tracked as deferred
packages, type elements are tracked directly, and all other elements are tracked via their
nearest enclosing type.
| Modifier and Type | Class and Description |
|---|---|
| private static enum |
| Modifier and Type | Field and Description |
|---|---|
| private final BasicAnnotationProcessor. | |
| private final String |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(@Nullable Object
the reference object with which to compare. object)Overrides java. |
| pack-priv static BasicAnnotationProcessor. | |
| pack-priv Optional | |
| public int | |
| pack-priv String |
| kind | back to summary |
|---|---|
| private final BasicAnnotationProcessor. | |
| name | back to summary |
|---|---|
| private final String name | |
| ElementName | back to summary |
|---|---|
| private ElementName(BasicAnnotationProcessor. | |
| equals | back to summary |
|---|---|
| public boolean equals(@Nullable Object object) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| forAnnotatedElement | back to summary |
|---|---|
| pack-priv static BasicAnnotationProcessor. An A package can be annotated if it has a | |
| getElement | back to summary |
|---|---|
| pack-priv Optional The | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| name | back to summary |
|---|---|
| pack-priv String name() The fully-qualified name of the element. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final BasicAnnotationProcessor. | |
| public static final BasicAnnotationProcessor. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static BasicAnnotationProcessor. | |
| public static BasicAnnotationProcessor. |
| PACKAGE_NAME | back to summary |
|---|---|
| public static final BasicAnnotationProcessor. | |
| TYPE_NAME | back to summary |
|---|---|
| public static final BasicAnnotationProcessor. | |
| Kind | back to summary |
|---|---|
| private Kind() | |
| valueOf | back to summary |
|---|---|
| public static BasicAnnotationProcessor. | |
| values | back to summary |
|---|---|
| public static BasicAnnotationProcessor. | |
Deprecated
Implement Step instead. See BasicAnnotationProcessor#steps().
| Modifier and Type | Method and Description |
|---|---|
| public Set | |
| public Set | Returns: the elements (a subset of the values ofelementsByAnnotation) that this step
is unable to process, possibly until a later processing round. These elements will be
passed back to this step at the next round of processing.The implementation of processing logic for the step. |
| annotations | back to summary |
|---|---|
| public Set The set of annotation types processed by this step. | |
| process | back to summary |
|---|---|
| public Set The implementation of processing logic for the step. It is guaranteed that the keys in | |
| Modifier and Type | Field and Description |
|---|---|
| private final ImmutableMap | |
| private final BasicAnnotationProcessor. | processingStep
Deprecated
as a consequence of
BasicAnnotationProcessor.ProcessingStep being deprecated.
|
| Access | Constructor and Description |
|---|---|
| pack-priv | ProcessingStepAsStep(BasicAnnotationProcessor.
Deprecated
as a consequence of
BasicAnnotationProcessor.ProcessingStep being deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
| public Set | annotations()
Implements com. |
| public Set | process(ImmutableSetMultimap<String, Element> elementsByAnnotation)
Implements com. |
| private ImmutableSetMultimap |
| annotationsByName | back to summary |
|---|---|
| private final ImmutableMap<String, Class<? extends Annotation>> annotationsByName | |
| processingStep | back to summary |
|---|---|
| private final BasicAnnotationProcessor. Deprecated as a consequence of | |
| ProcessingStepAsStep | back to summary |
|---|---|
| pack-priv ProcessingStepAsStep(BasicAnnotationProcessor. Deprecated as a consequence of | |
| annotations | back to summary |
|---|---|
| public Set Implements com. Doc from com. The set of fully-qualified annotation type names processed by this step. Warning If the returned names are not names of annotations, they'll be ignored.
| |
| process | back to summary |
|---|---|
| public Set Implements com. Doc from com. The implementation of processing logic for the step. It is guaranteed that the keys in | |
| toClassKeyedMultimap | back to summary |
|---|---|
| private ImmutableSetMultimap | |
| Modifier and Type | Method and Description |
|---|---|
| public Set | |
| public Set | Returns: the elements (a subset of the values ofelementsByAnnotation) that this step
is unable to process, possibly until a later processing round. These elements will be
passed back to this step at the next round of processing.The implementation of processing logic for the step. |
| annotations | back to summary |
|---|---|
| public Set The set of fully-qualified annotation type names processed by this step. Warning If the returned names are not names of annotations, they'll be ignored. | |
| process | back to summary |
|---|---|
| public Set The implementation of processing logic for the step. It is guaranteed that the keys in | |