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
Constructors Constructor Description AbstractAnnotationProcessor()
Empty constructor only for all processors (invoked by Spoon).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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
clearConsumedAnnotationTypes()
Clears the consumed annotation types.protected void
clearProcessedAnnotationTypes()
Clears the processed annotation types.Set<Class<? extends A>>
getConsumedAnnotationTypes()
Gets the annotations types consumed by this processor.Set<Class<? extends A>>
getProcessedAnnotationTypes()
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
inferConsumedAnnotationType()
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
process(E element)
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
-
-
-
-
Method Detail
-
addConsumedAnnotationType
protected final void addConsumedAnnotationType(Class<? extends A> annotationType)
Adds a consumed annotation type (to be used in subclasses constructors). A consumed annotation type is also part of the processed annotation types.
-
addProcessedAnnotationType
protected final void addProcessedAnnotationType(Class<? extends A> annotationType)
Adds a processed annotation type (to be used in subclasses constructors).
-
removeProcessedAnnotationType
protected final void removeProcessedAnnotationType(Class<? extends A> annotationType)
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
protected final void removeConsumedAnnotationType(Class<? extends A> annotationType)
Removes a processed annotation type.
-
getConsumedAnnotationTypes
public final Set<Class<? extends A>> 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
public final Set<Class<? extends A>> 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
public final boolean isToBeProcessed(E element)
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
public final void process(E element)
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
public boolean shoudBeConsumed(CtAnnotation<? extends Annotation> annotation)
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>
-
-