Package spoon.processing
Class AbstractAnnotationProcessor<A extends Annotation,E extends CtElement>
java.lang.Object
spoon.processing.AbstractProcessor<E>
spoon.processing.AbstractAnnotationProcessor<A,E>
- All Implemented Interfaces:
AnnotationProcessor<A,E>
,FactoryAccessor
,Processor<E>
public abstract class AbstractAnnotationProcessor<A extends Annotation,E extends CtElement>
extends AbstractProcessor<E>
implements AnnotationProcessor<A,E>
This class defines an abstract annotation processor to be subclassed by the
user for defining new annotation processors including Java 8 annotations.
-
Constructor Summary
ConstructorDescriptionEmpty constructor only for all processors (invoked by Spoon). -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addConsumedAnnotationType(Class<? extends A> annotationType)
Adds a consumed annotation type (to be used in subclasses constructors).protected void
addProcessedAnnotationType(Class<? extends A> annotationType)
Adds a processed annotation type (to be used in subclasses constructors).protected void
Clears the consumed annotation types.protected void
Clears the processed annotation types.Gets the annotations types consumed by this processor.Gets the annotations processed by this annotation processor, that is to say the annotation types that trigger theAnnotationProcessor.process(Annotation, CtElement)
method when visiting a program element.boolean
Returns true (default) if the processor automatically infers the consumed annotation type to theA
actual type.boolean
isToBeProcessed(E element)
Returns true if the element is annotated with an annotation whose type is processed.void
A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element.protected void
removeConsumedAnnotationType(Class<? extends A> annotationType)
Removes a processed annotation type.protected void
removeProcessedAnnotationType(Class<? extends A> annotationType)
Removes a processed annotation type.boolean
shoudBeConsumed(CtAnnotation<? extends Annotation> annotation)
Returns true if this annotation should be removed from the processed code.Methods inherited from class spoon.processing.AbstractProcessor
addProcessedElementType, clearProcessedElementType, getEnvironment, getFactory, getProcessedElementTypes, getTraversalStrategy, init, initProperties, interrupt, loadProperties, process, processingDone, removeProcessedElementType, setFactory
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface spoon.processing.AnnotationProcessor
process
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
Methods inherited from interface spoon.processing.Processor
getEnvironment, getProcessedElementTypes, getTraversalStrategy, init, initProperties, interrupt, process, processingDone
-
Constructor Details
-
AbstractAnnotationProcessor
public AbstractAnnotationProcessor()Empty constructor only for all processors (invoked by Spoon).
-
-
Method Details
-
addConsumedAnnotationType
Adds a consumed annotation type (to be used in subclasses constructors). A consumed annotation type is also part of the processed annotation types. -
addProcessedAnnotationType
Adds a processed annotation type (to be used in subclasses constructors). -
removeProcessedAnnotationType
Removes a processed annotation type. -
clearProcessedAnnotationTypes
protected final void clearProcessedAnnotationTypes()Clears the processed annotation types. -
clearConsumedAnnotationTypes
protected final void clearConsumedAnnotationTypes()Clears the consumed annotation types. -
removeConsumedAnnotationType
Removes a processed annotation type. -
getConsumedAnnotationTypes
Description copied from interface:AnnotationProcessor
Gets the annotations types consumed by this processor. A consumed annotation is a special kind of processed annotation (seeAnnotationProcessor.getProcessedAnnotationTypes()
that is automatically removed from the program once the associated processor has finished its job.- Specified by:
getConsumedAnnotationTypes
in interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>
- Returns:
- the annotation classes
-
getProcessedAnnotationTypes
Description copied from interface:AnnotationProcessor
Gets the annotations processed by this annotation processor, that is to say the annotation types that trigger theAnnotationProcessor.process(Annotation, CtElement)
method when visiting a program element. The processed annotation types includes all the consumed annotation types.- Specified by:
getProcessedAnnotationTypes
in interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>
- Returns:
- the annotation classes
-
inferConsumedAnnotationType
public boolean inferConsumedAnnotationType()Description copied from interface:AnnotationProcessor
Returns true (default) if the processor automatically infers the consumed annotation type to theA
actual type.- Specified by:
inferConsumedAnnotationType
in interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>
-
isToBeProcessed
Returns true if the element is annotated with an annotation whose type is processed.- Specified by:
isToBeProcessed
in interfaceProcessor<A extends Annotation>
- Overrides:
isToBeProcessed
in classAbstractProcessor<E extends CtElement>
- Parameters:
element
- the candidate- Returns:
- true if the candidate is to be processed by the
Processor.process(CtElement)
-
process
Description copied from interface:Processor
A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element. The way Spoon calls this method depends on the processed element types (Processor.getProcessedElementTypes()
), the traversal strategy (Processor.getTraversalStrategy()
), and the used processing manager (Environment.getManager()
. Also, this method is called only if the methodProcessor.isToBeProcessed(CtElement)
returns true for a given scanned element. In order to manually scan the meta-model, one can define theProcessor.process()
method instead.- Specified by:
process
in interfaceProcessor<A extends Annotation>
- Parameters:
element
- the element that is currently being scanned
-
shoudBeConsumed
Returns true if this annotation should be removed from the processed code. Removes all annotations A on elements E.- Specified by:
shoudBeConsumed
in interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>
-