Package spoon.processing
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 subclassAbstractProcessor
, the abstract default implementation of this interface. If a processor contains fields annotated with @Property
, they can be set using aProcessorProperties
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Environment
getEnvironment()
Gets the environment of this processor.Set<Class<? extends CtElement>>
getProcessedElementTypes()
Gets all the element types than need to be processed.TraversalStrategy
getTraversalStrategy()
Gets the model's traversal strategy for this processor (default isTraversalStrategy.POST_ORDER
).void
init()
This method is upcalled to initialize the processor before each processing round.void
initProperties(ProcessorProperties properties)
Initializes the properties defined by this processor by using the environment.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 theProcessingManager
.boolean
isToBeProcessed(E candidate)
Tells if this element is to be processed (returnstrue
in the default implementation).void
process()
A callback method upcalled by the manager so that this processor can manually implement a processing job.void
process(E element)
A callback method upcalled by the meta-model scanner to perform a dedicated job on the currently scanned element.void
processingDone()
This method is upcalled by theProcessingManager
when this processor has finished a full processing round on the program's model.-
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
-
-
-
Method Detail
-
getTraversalStrategy
TraversalStrategy getTraversalStrategy()
Gets the model's traversal strategy for this processor (default isTraversalStrategy.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 (returnstrue
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 upcalled by the meta-model scanner to perform a dedicated job on the currently scanned element. The way Spoon upcalls this method depends on the processed element types (getProcessedElementTypes()
), the traversal strategy (getTraversalStrategy()
), and the used processing manager (Environment.getManager()
. Also, this method is upcalled only if the methodisToBeProcessed(CtElement)
returns true for a given scanned element. In order to manually scan the meta-model, one can define theprocess()
method instead.- Parameters:
element
- the element that is currently being scanned
-
process
void process()
A callback method upcalled by the manager so that this processor can manually implement a processing job. On contrary toprocess(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 upcalled 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 upcalled by theProcessingManager
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 (seeProcessingManager.addProcessor(Class)
). Does nothing by default.
-
init
void init()
This method is upcalled 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.
-
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 theProcessingManager
.
-
-