AbstractProcessor (Java Platform SE 8 ) (original) (raw)
- javax.annotation.processing.AbstractProcessor
All Implemented Interfaces:
Processor
public abstract class AbstractProcessor
extends Object
implements Processor
An abstract annotation processor designed to be a convenient superclass for most concrete annotation processors. This class examines annotation values to compute the options, annotation types, and source version supported by its subtypes.
The getter methods may issue warnings about noteworthy conditions using the facilities available after the processor has been initialized.
Subclasses are free to override the implementation and specification of any of the methods in this class as long as the general Processor contract for that method is obeyed.
Since:
1.6
Field Summary
Fields
Modifier and Type Field Description protected ProcessingEnvironment processingEnv Processing environment providing by the tool framework. Constructor Summary
Constructors
Modifier Constructor Description protected AbstractProcessor() Constructor for subclasses to call. Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods
Modifier and Type Method Description Iterable<? extends Completion> getCompletions(Element element,AnnotationMirror annotation,ExecutableElement member,String userText) Returns an empty iterable of completions. Set<String> getSupportedAnnotationTypes() If the processor class is annotated with SupportedAnnotationTypes, return an unmodifiable set with the same set of strings as the annotation. Set<String> getSupportedOptions() If the processor class is annotated with SupportedOptions, return an unmodifiable set with the same set of strings as the annotation. SourceVersion getSupportedSourceVersion() If the processor class is annotated with SupportedSourceVersion, return the source version in the annotation. void init(ProcessingEnvironment processingEnv) Initializes the processor with the processing environment by setting the processingEnv field to the value of theprocessingEnv argument. protected boolean isInitialized() Returns true if this object has been initialized, false otherwise. abstract boolean process(Set<? extends TypeElement> annotations,RoundEnvironment roundEnv) Processes a set of annotation types on type elements originating from the prior round and returns whether or not these annotation types are claimed by this processor. * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone--), [equals](../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [hashCode](../../../java/lang/Object.html#hashCode--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [toString](../../../java/lang/Object.html#toString--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Field Detail
* #### processingEnv protected [ProcessingEnvironment](../../../javax/annotation/processing/ProcessingEnvironment.html "interface in javax.annotation.processing") processingEnv Processing environment providing by the tool framework.
Constructor Detail
* #### AbstractProcessor protected AbstractProcessor() Constructor for subclasses to call.
Method Detail
* #### getSupportedOptions public [Set](../../../java/util/Set.html "interface in java.util")<[String](../../../java/lang/String.html "class in java.lang")> getSupportedOptions() If the processor class is annotated with [SupportedOptions](../../../javax/annotation/processing/SupportedOptions.html "annotation in javax.annotation.processing"), return an unmodifiable set with the same set of strings as the annotation. If the class is not so annotated, an empty set is returned. Specified by: `[getSupportedOptions](../../../javax/annotation/processing/Processor.html#getSupportedOptions--)` in interface `[Processor](../../../javax/annotation/processing/Processor.html "interface in javax.annotation.processing")` Returns: the options recognized by this processor, or an empty set if none See Also: [SupportedOptions](../../../javax/annotation/processing/SupportedOptions.html "annotation in javax.annotation.processing") * #### getSupportedAnnotationTypes public [Set](../../../java/util/Set.html "interface in java.util")<[String](../../../java/lang/String.html "class in java.lang")> getSupportedAnnotationTypes() If the processor class is annotated with [SupportedAnnotationTypes](../../../javax/annotation/processing/SupportedAnnotationTypes.html "annotation in javax.annotation.processing"), return an unmodifiable set with the same set of strings as the annotation. If the class is not so annotated, an empty set is returned. Specified by: `[getSupportedAnnotationTypes](../../../javax/annotation/processing/Processor.html#getSupportedAnnotationTypes--)` in interface `[Processor](../../../javax/annotation/processing/Processor.html "interface in javax.annotation.processing")` Returns: the names of the annotation types supported by this processor, or an empty set if none See Also: [SupportedAnnotationTypes](../../../javax/annotation/processing/SupportedAnnotationTypes.html "annotation in javax.annotation.processing") * #### getSupportedSourceVersion public [SourceVersion](../../../javax/lang/model/SourceVersion.html "enum in javax.lang.model") getSupportedSourceVersion() Specified by: `[getSupportedSourceVersion](../../../javax/annotation/processing/Processor.html#getSupportedSourceVersion--)` in interface `[Processor](../../../javax/annotation/processing/Processor.html "interface in javax.annotation.processing")` Returns: the latest source version supported by this processor See Also: [SupportedSourceVersion](../../../javax/annotation/processing/SupportedSourceVersion.html "annotation in javax.annotation.processing"), [ProcessingEnvironment.getSourceVersion()](../../../javax/annotation/processing/ProcessingEnvironment.html#getSourceVersion--) * #### init public void init([ProcessingEnvironment](../../../javax/annotation/processing/ProcessingEnvironment.html "interface in javax.annotation.processing") processingEnv) Initializes the processor with the processing environment by setting the `processingEnv` field to the value of the`processingEnv` argument. An `IllegalStateException` will be thrown if this method is called more than once on the same object. Specified by: `[init](../../../javax/annotation/processing/Processor.html#init-javax.annotation.processing.ProcessingEnvironment-)` in interface `[Processor](../../../javax/annotation/processing/Processor.html "interface in javax.annotation.processing")` Parameters: `processingEnv` \- environment to access facilities the tool framework provides to the processor Throws: `[IllegalStateException](../../../java/lang/IllegalStateException.html "class in java.lang")` \- if this method is called more than once. * #### process public abstract boolean process([Set](../../../java/util/Set.html "interface in java.util")<? extends [TypeElement](../../../javax/lang/model/element/TypeElement.html "interface in javax.lang.model.element")> annotations, [RoundEnvironment](../../../javax/annotation/processing/RoundEnvironment.html "interface in javax.annotation.processing") roundEnv) Processes a set of annotation types on type elements originating from the prior round and returns whether or not these annotation types are claimed by this processor. If `true` is returned, the annotation types are claimed and subsequent processors will not be asked to process them; if `false` is returned, the annotation types are unclaimed and subsequent processors may be asked to process them. A processor may always return the same boolean value or may vary the result based on chosen criteria. The input set will be empty if the processor supports `"*"` and the root elements have no annotations. A `Processor` must gracefully handle an empty set of annotations. Specified by: `[process](../../../javax/annotation/processing/Processor.html#process-java.util.Set-javax.annotation.processing.RoundEnvironment-)` in interface `[Processor](../../../javax/annotation/processing/Processor.html "interface in javax.annotation.processing")` Parameters: `annotations` \- the annotation types requested to be processed `roundEnv` \- environment for information about the current and prior round Returns: whether or not the set of annotation types are claimed by this processor * #### getCompletions public [Iterable](../../../java/lang/Iterable.html "interface in java.lang")<? extends [Completion](../../../javax/annotation/processing/Completion.html "interface in javax.annotation.processing")> getCompletions([Element](../../../javax/lang/model/element/Element.html "interface in javax.lang.model.element") element, [AnnotationMirror](../../../javax/lang/model/element/AnnotationMirror.html "interface in javax.lang.model.element") annotation, [ExecutableElement](../../../javax/lang/model/element/ExecutableElement.html "interface in javax.lang.model.element") member, [String](../../../java/lang/String.html "class in java.lang") userText) Returns an empty iterable of completions. Specified by: `[getCompletions](../../../javax/annotation/processing/Processor.html#getCompletions-javax.lang.model.element.Element-javax.lang.model.element.AnnotationMirror-javax.lang.model.element.ExecutableElement-java.lang.String-)` in interface `[Processor](../../../javax/annotation/processing/Processor.html "interface in javax.annotation.processing")` Parameters: `element` \- the element being annotated `annotation` \- the (perhaps partial) annotation being applied to the element `member` \- the annotation member to return possible completions for `userText` \- source code text to be completed Returns: suggested completions to the annotation * #### isInitialized protected boolean isInitialized() Returns `true` if this object has been [initialized](../../../javax/annotation/processing/AbstractProcessor.html#init-javax.annotation.processing.ProcessingEnvironment-), `false` otherwise. Returns: `true` if this object has been initialized,`false` otherwise.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.