KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > reflect > visitor > CtStackScanner


1 package spoon.reflect.visitor;
2
3 import java.util.Stack JavaDoc;
4
5 import spoon.reflect.declaration.CtElement;
6 import spoon.reflect.reference.CtReference;
7
8 /**
9  * This class defines a scanner that maintains a scanning stack for contextual
10  * awareness.
11  */

12 public class CtStackScanner extends CtScanner {
13
14     /**
15      * Default constructor.
16      */

17     public CtStackScanner() {
18     }
19
20     /**
21      * The stack of elements.
22      */

23     protected Stack JavaDoc<CtElement> elementStack = new Stack JavaDoc<CtElement>();
24
25     /**
26      * The stack of element references.
27      */

28     protected Stack JavaDoc<CtReference> referenceStack = new Stack JavaDoc<CtReference>();
29
30     /**
31      * Pops the element.
32      */

33     protected void exit(CtElement e) {
34         CtElement ret = elementStack.pop();
35         if (ret != e)
36             throw new RuntimeException JavaDoc("Unconsitant Stack");
37         super.exit(e);
38     }
39
40     /**
41      * Pops the element reference.
42      */

43     protected void exitReference(CtReference e) {
44         CtReference ret = referenceStack.pop();
45         if (ret != e)
46             throw new RuntimeException JavaDoc("Unconsitant Stack");
47         super.exitReference(e);
48     }
49
50     /**
51      * Pushes the element.
52      */

53     protected void enter(CtElement e) {
54         elementStack.push(e);
55         super.enter(e);
56     }
57
58     /**
59      * Pushes the element reference.
60      */

61     protected void enterReference(CtReference e) {
62         referenceStack.push(e);
63         enterReference(e);
64         super.enterReference(e);
65     }
66 }
67
Popular Tags