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
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 TypeMethodDescriptionGets the environment of this processor.Gets all the element types than need to be processed.Gets the model's traversal strategy for this processor (default isTraversalStrategy.POST_ORDER
).void
init()
This method is called to initialize the processor before each processing round.void
initProperties(ProcessorProperties properties)
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 theProcessingManager
.boolean
isToBeProcessed(E candidate)
Tells if this element is to be processed (returnstrue
in the default implementation).void
process()
A callback method called by the manager so that this processor can manually implement a processing job.void
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 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 Details
-
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
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
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 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 called 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 called first. This method does nothing in default implementations (AbstractProcessor
). -
getProcessedElementTypes
Gets all the element types than need to be processed. -
processingDone
void processingDone()This method is called 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 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
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
.
-