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 Details

    • AbstractAnnotationProcessor

      public AbstractAnnotationProcessor()
      Empty constructor only for all processors (invoked by Spoon).
  • Method Details

    • 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 (see AnnotationProcessor.getProcessedAnnotationTypes() that is automatically removed from the program once the associated processor has finished its job.
      Specified by:
      getConsumedAnnotationTypes in interface AnnotationProcessor<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 the AnnotationProcessor.process(Annotation, CtElement) method when visiting a program element. The processed annotation types includes all the consumed annotation types.
      Specified by:
      getProcessedAnnotationTypes in interface AnnotationProcessor<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 the A actual type.
      Specified by:
      inferConsumedAnnotationType in interface AnnotationProcessor<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 interface Processor<A extends Annotation>
      Overrides:
      isToBeProcessed in class AbstractProcessor<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 method Processor.isToBeProcessed(CtElement) returns true for a given scanned element. In order to manually scan the meta-model, one can define the Processor.process() method instead.
      Specified by:
      process in interface Processor<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 interface AnnotationProcessor<A extends Annotation,​E extends CtElement>