KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > processing > Processor


1 package spoon.processing;
2
3 import java.util.Set JavaDoc;
4
5 import spoon.reflect.declaration.CtElement;
6
7 /**
8  * This interface defines a generic code processor. To define a new processor,
9  * the user should subclass {@link spoon.processing.AbstractProcessor}, the
10  * abstract default implementation of this interface.
11  */

12
13 public interface Processor<E extends CtElement> extends FactoryAccessor {
14
15     /**
16      * Gets the model's traversal strategy for this processor (default is
17      * {@link TraversalStrategy#PRE_ORDER}). Programmers should override this
18      * method to return another strategy if needed.
19      */

20     TraversalStrategy getTraversalStrategy();
21
22     /**
23      * Gets the environment of this processor.
24      */

25     Environment getEnvironment();
26
27     /**
28      * Tells if this element is to be processed (returns <code>true</code> in
29      * the default implementation).
30      *
31      * @param candidate
32      * the candidate
33      * @return true if the candidate is to be processed by the
34      * {@link #process(CtElement)}
35      */

36     boolean isToBeProcessed(E candidate);
37
38     /**
39      * A callback method upcalled by the meta-model scanner to perform a
40      * dedicated job on the currently scanned element. The way Spoon upcalls
41      * this method depends on the processed element types ({@link #getProcessedElementTypes()}),
42      * the traversal strategy ({@link #getTraversalStrategy()}), and the used
43      * processing manager ({@link Environment#getManager()}. Also, this method
44      * is upcalled only if the method {@link #isToBeProcessed(CtElement)}
45      * returns true for a given scanned element. In order to manually scan the
46      * meta-model, one can define the {@link #process()} method instead.
47      *
48      * @param element
49      * the element that is currenly being scanned
50      */

51     void process(E element);
52
53     /**
54      * A callback method upcalled by the manager so that this processor can
55      * manually implement a processing job. On contrary to
56      * {@link #process(CtElement)}, this method does not rely on a built-in
57      * meta-model scanner and has to implement its own traversal strategy on the
58      * meta-model, which is stored in the factory ({@link FactoryAccessor#getFactory}).
59      * Note that if a processor implements both process methods, this one is
60      * upcalled first. This method does nothing in default implementations ({@link spoon.processing.AbstractProcessor}).
61      */

62     void process();
63
64     /**
65      * Do the processing job for a given element. This method is upcalled on an
66      * element if the method {@link #isToBeProcessed(CtElement)} returns true.
67      *
68      * @param element
69      * the element that holds the processed annotations
70      */

71
72     /**
73      * Gets all the element types than need to be processed.
74      */

75     Set JavaDoc<Class JavaDoc<? extends CtElement>> getProcessedElementTypes();
76
77     /**
78      * This method is upcalled by the {@link ProcessingManager} when this
79      * processor has finished a full processing round on the program's model. It
80      * is convenient to overload this method to tune the application's strategy
81      * of a set of processors, for instance by dynamically adding processors to
82      * the processing manager when a processing round ends (see
83      * {@link ProcessingManager#addProcessor(Class)}). Does nothing by default.
84      */

85     void processingDone();
86
87     /**
88      * This method is upcalled to initialize the processor before each
89      * processing round. It is convenient to overload this method rather than
90      * using a default constructor to initialize the processor, since the
91      * factory is not initialized at construction time. When overloading, do not
92      * forget to call super.init() first so that all the initializations
93      * performed by superclasses are also applied.
94      */

95     void init();
96
97 }
98
Popular Tags