KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > Ext_c


1 package polyglot.ext.jl.ast;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.visit.*;
6 import polyglot.util.*;
7
8 /**
9  * <code>Ext</code> is the super type of all node extension objects.
10  * It contains a pointer back to the node it is extending and a possibly-null
11  * pointer to another extension node.
12  */

13 public abstract class Ext_c implements Ext {
14     protected Node node;
15     protected Ext ext;
16
17     public Ext_c(Ext ext) {
18         this.node = null;
19         this.ext = ext;
20     }
21
22     public Ext_c() {
23         this(null);
24         this.node = null;
25     }
26
27     /** Initialize the extension object's pointer back to the node.
28      * This also initializes the back pointers for all extensions of
29      * the extension.
30      */

31     public void init(Node node) {
32         if (this.node != null) {
33             throw new InternalCompilerError("Already initialized.");
34         }
35
36         this.node = node;
37
38         if (this.ext != null) {
39             this.ext.init(node);
40         }
41     }
42
43     /**
44      * Return the node we ultimately extend.
45      */

46     public Node node() {
47     return node;
48     }
49
50     /**
51      * Return our extension object, or null.
52      */

53     public Ext ext() {
54         return ext;
55     }
56
57     public Ext ext(Ext ext) {
58         Ext old = this.ext;
59         this.ext = null;
60
61         Ext_c copy = (Ext_c) copy();
62
63         copy.ext = ext;
64
65         this.ext = old;
66
67         return copy;
68     }
69
70     /**
71      * Copy the extension.
72      */

73     public Object JavaDoc copy() {
74         try {
75             Ext_c copy = (Ext_c) super.clone();
76             if (ext != null) {
77                 copy.ext = (Ext) ext.copy();
78             }
79             copy.node = null; // uninitialize
80
return copy;
81         }
82         catch (CloneNotSupportedException JavaDoc e) {
83             throw new InternalCompilerError("Java clone() weirdness.");
84         }
85     }
86
87     public String JavaDoc toString() {
88         return StringUtil.getShortNameComponent(getClass().getName());
89     }
90
91     /**
92      * Dump the AST node for debugging purposes.
93      */

94     public void dump(CodeWriter w) {
95       w.write(toString());
96     }
97 }
98
Popular Tags