Class AbstractProcessor<E extends CtElement>

java.lang.Object
spoon.processing.AbstractProcessor<E>
All Implemented Interfaces:
FactoryAccessor, Processor<E>
Direct Known Subclasses:
AbstractAnnotationProcessor, AbstractParallelProcessor, ForceFullyQualifiedProcessor, ForceImportProcessor, ImportCleaner, ImportConflictDetector, JavaOutputProcessor

public abstract class AbstractProcessor<E extends CtElement> extends Object implements Processor<E>
This class defines an abstract processor to be subclassed by the user for defining new processors.
  • Constructor Details

    • AbstractProcessor

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

    • addProcessedElementType

      protected void addProcessedElementType(Class<? extends CtElement> elementType)
      Adds a processed element type. This method is typically invoked in subclasses' constructors.
    • clearProcessedElementType

      protected void clearProcessedElementType()
      Clears the processed element types.
    • getEnvironment

      public Environment getEnvironment()
      Description copied from interface: Processor
      Gets the environment of this processor.
      Specified by:
      getEnvironment in interface Processor<E extends CtElement>
    • getFactory

      public Factory getFactory()
      Description copied from interface: FactoryAccessor
      Gets the factory of this object.
      Specified by:
      getFactory in interface FactoryAccessor
    • getProcessedElementTypes

      public Set<Class<? extends CtElement>> getProcessedElementTypes()
      Description copied from interface: Processor
      Gets all the element types than need to be processed.
      Specified by:
      getProcessedElementTypes in interface Processor<E extends CtElement>
    • loadProperties

      public ProcessorProperties loadProperties()
      Helper method to load the properties of the given processor (uses Environment.getProcessorProperties(String)).
    • getTraversalStrategy

      public TraversalStrategy getTraversalStrategy()
      Description copied from interface: Processor
      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.
      Specified by:
      getTraversalStrategy in interface Processor<E extends CtElement>
    • init

      public void init()
      Description copied from interface: Processor
      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.
      Specified by:
      init in interface Processor<E extends CtElement>
    • isToBeProcessed

      public boolean isToBeProcessed(E candidate)
      Description copied from interface: Processor
      Tells if this element is to be processed (returns true in the default implementation).
      Specified by:
      isToBeProcessed in interface Processor<E extends CtElement>
      Parameters:
      candidate - the candidate
      Returns:
      true if the candidate is to be processed by the Processor.process(CtElement)
    • initProperties

      public void initProperties(ProcessorProperties properties)
      Helper method to initialize the properties of a given processor.
      Specified by:
      initProperties in interface Processor<E extends CtElement>
      See Also:
      Environment.getProcessorProperties(String)
    • process

      public final void process()
      The manual meta-model processing cannot be overridden (use AbstractManualProcessor) to do so.
      Specified by:
      process in interface Processor<E extends CtElement>
    • processingDone

      public void processingDone()
      Description copied from interface: Processor
      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.
      Specified by:
      processingDone in interface Processor<E extends CtElement>
    • removeProcessedElementType

      protected void removeProcessedElementType(Class<? extends CtElement> elementType)
      Removes a processed element type.
    • setFactory

      public void setFactory(Factory factory)
      Description copied from interface: FactoryAccessor
      Sets the factory object.
      Specified by:
      setFactory in interface FactoryAccessor
    • interrupt

      public void interrupt()
      Description copied from interface: Processor
      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.
      Specified by:
      interrupt in interface Processor<E extends CtElement>