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
ConstructorsConstructorDescriptionEmpty constructor only for all processors (invoked by Spoon). -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConsumedAnnotationType(Class<? extends A> annotationType)Adds a consumed annotation type (to be used in subclasses constructors).protected voidaddProcessedAnnotationType(Class<? extends A> annotationType)Adds a processed annotation type (to be used in subclasses constructors).protected voidClears the consumed annotation types.protected voidClears 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.booleanReturns true (default) if the processor automatically infers the consumed annotation type to theAactual type.booleanisToBeProcessed(E element)Returns true if the element is annotated with an annotation whose type is processed.voidA callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element.protected voidremoveConsumedAnnotationType(Class<? extends A> annotationType)Removes a processed annotation type.protected voidremoveProcessedAnnotationType(Class<? extends A> annotationType)Removes a processed annotation type.booleanshoudBeConsumed(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, setFactoryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface spoon.processing.AnnotationProcessor
processMethods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactoryMethods 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:AnnotationProcessorGets 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:
getConsumedAnnotationTypesin interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>- Returns:
- the annotation classes
-
getProcessedAnnotationTypes
Description copied from interface:AnnotationProcessorGets 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:
getProcessedAnnotationTypesin interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>- Returns:
- the annotation classes
-
inferConsumedAnnotationType
public boolean inferConsumedAnnotationType()Description copied from interface:AnnotationProcessorReturns true (default) if the processor automatically infers the consumed annotation type to theAactual type.- Specified by:
inferConsumedAnnotationTypein interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>
-
isToBeProcessed
Returns true if the element is annotated with an annotation whose type is processed.- Specified by:
isToBeProcessedin interfaceProcessor<A extends Annotation>- Overrides:
isToBeProcessedin 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:ProcessorA 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:
processin 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:
shoudBeConsumedin interfaceAnnotationProcessor<A extends Annotation,E extends CtElement>
-