Interface Processor<E extends CtElement>

All Superinterfaces:
FactoryAccessor
All Known Subinterfaces:
AnnotationProcessor<A,​E>, FileGenerator<T>
All Known Implementing Classes:
AbstractAnnotationProcessor, AbstractManualProcessor, AbstractParallelProcessor, AbstractProcessor, ForceFullyQualifiedProcessor, ForceImportProcessor, ImportCleaner, ImportConflictDetector, JavaOutputProcessor, SpoonTagger

public interface Processor<E extends CtElement> extends FactoryAccessor
This interface defines a generic code processor. To define a new processor, the user should subclass AbstractProcessor, the abstract default implementation of this interface. If a processor contains fields annotated with @Property, they can be set using a ProcessorProperties
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the environment of this processor.
    Set<Class<? extends CtElement>>
    Gets all the element types than need to be processed.
    Gets the model's traversal strategy for this processor (default is TraversalStrategy.POST_ORDER).
    void
    This method is called to initialize the processor before each processing round.
    void
    Initializes the properties defined by this processor by using the environment.
    void
    Interrupts the processing of this processor but changes on your AST are kept and the invocation of this method doesn't interrupt the processing of all processors specified in the ProcessingManager.
    boolean
    isToBeProcessed​(E candidate)
    Tells if this element is to be processed (returns true in the default implementation).
    void
    A callback method called by the manager so that this processor can manually implement a processing job.
    void
    process​(E element)
    A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element.
    void
    This method is called by the ProcessingManager when this processor has finished a full processing round on the program's model.

    Methods inherited from interface spoon.processing.FactoryAccessor

    getFactory, setFactory
  • Method Details

    • getTraversalStrategy

      TraversalStrategy getTraversalStrategy()
      Gets the model's traversal strategy for this processor (default is TraversalStrategy.POST_ORDER). Programmers should override this method to return another strategy if needed.
    • getEnvironment

      Environment getEnvironment()
      Gets the environment of this processor.
    • isToBeProcessed

      boolean isToBeProcessed(E candidate)
      Tells if this element is to be processed (returns true in the default implementation).
      Parameters:
      candidate - the candidate
      Returns:
      true if the candidate is to be processed by the process(CtElement)
    • process

      void process(E element)
      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 ( getProcessedElementTypes()), the traversal strategy ( getTraversalStrategy()), and the used processing manager ( Environment.getManager(). Also, this method is called only if the method isToBeProcessed(CtElement) returns true for a given scanned element. In order to manually scan the meta-model, one can define the process() method instead.
      Parameters:
      element - the element that is currently being scanned
    • process

      void process()
      A callback method called by the manager so that this processor can manually implement a processing job. On contrary to process(CtElement), this method does not rely on a built-in meta-model scanner and has to implement its own traversal strategy on the meta-model, which is stored in the factory ( FactoryAccessor.getFactory()). Note that if a processor implements both process methods, this one is called first. This method does nothing in default implementations ( AbstractProcessor).
    • getProcessedElementTypes

      Set<Class<? extends CtElement>> getProcessedElementTypes()
      Gets all the element types than need to be processed.
    • processingDone

      void processingDone()
      This method is called by the ProcessingManager when this processor has finished a full processing round on the program's model. It is convenient to override this method to tune the application's strategy of a set of processors, for instance by dynamically adding processors to the processing manager when a processing round ends (see ProcessingManager.addProcessor(Class)). Does nothing by default.
    • init

      void init()
      This method is called to initialize the processor before each processing round. It is convenient to override this method rather than using a default constructor to initialize the processor, since the factory is not initialized at construction time. When overriding, do not forget to call super.init() first so that all the initializations performed by superclasses are also applied.
    • initProperties

      void initProperties(ProcessorProperties properties)
      Initializes the properties defined by this processor by using the environment.
      See Also:
      Environment.getProcessorProperties(String)
    • interrupt

      void interrupt()
      Interrupts the processing of this processor but changes on your AST are kept and the invocation of this method doesn't interrupt the processing of all processors specified in the ProcessingManager.