KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > ast > CofferClassDecl_c


1 package polyglot.ext.coffer.ast;
2
3 import polyglot.ext.jl.ast.*;
4 import polyglot.ext.param.types.*;
5 import polyglot.ext.coffer.types.*;
6 import polyglot.ast.*;
7 import polyglot.types.*;
8 import polyglot.visit.*;
9 import polyglot.util.*;
10 import java.util.*;
11
12 /**
13  * An implementation of the <code>CofferClassDecl</code> interface.
14  * <code>ClassDecl</code> is extended with a possibly-null key name.
15  */

16 public class CofferClassDecl_c extends ClassDecl_c implements CofferClassDecl
17 {
18     protected KeyNode key;
19
20     public CofferClassDecl_c(Position pos, Flags flags, String JavaDoc name,
21         KeyNode key, TypeNode superClass, List interfaces,
22         ClassBody body) {
23     super(pos, flags, name, superClass, interfaces, body);
24         this.key = key;
25     }
26
27     public KeyNode key() {
28     return this.key;
29     }
30
31     public CofferClassDecl key(KeyNode key) {
32     CofferClassDecl_c n = (CofferClassDecl_c) copy();
33     n.key = key;
34     return n;
35     }
36
37     protected CofferClassDecl_c reconstruct(KeyNode key, TypeNode superClass,
38                                            List interfaces, ClassBody body) {
39         CofferClassDecl_c n = this;
40
41     if (this.key != key) {
42         n = (CofferClassDecl_c) copy();
43         n.key = key;
44     }
45
46         return (CofferClassDecl_c) n.reconstruct(superClass, interfaces, body);
47     }
48
49     public Node visitChildren(NodeVisitor v) {
50     KeyNode key = (KeyNode) visitChild(this.key, v);
51     TypeNode superClass = (TypeNode) visitChild(this.superClass, v);
52     List interfaces = visitList(this.interfaces, v);
53     ClassBody body = (ClassBody) visitChild(this.body, v);
54     return reconstruct(key, superClass, interfaces, body);
55     }
56
57     public Context enterScope(Context context) {
58         CofferContext c = (CofferContext) context;
59         CofferTypeSystem ts = (CofferTypeSystem) c.typeSystem();
60
61         CofferParsedClassType ct = (CofferParsedClassType) this.type;
62         CofferClassType inst = (CofferClassType) ct;
63
64         c = (CofferContext) c.pushClass(ct, inst);
65
66         if (key != null)
67             c.addKey(key.key());
68
69         return c;
70     }
71
72     public Node buildTypes(TypeBuilder tb) throws SemanticException {
73         CofferClassDecl_c n = (CofferClassDecl_c) super.buildTypes(tb);
74
75         CofferTypeSystem ts = (CofferTypeSystem) tb.typeSystem();
76
77         CofferParsedClassType ct = (CofferParsedClassType) n.type;
78
79         MuPClass pc = ts.mutablePClass(ct.position());
80         ct.setInstantiatedFrom(pc);
81         pc.clazz(ct);
82
83         if (key != null) {
84             ct.setKey(key.key());
85         }
86
87         return n;
88     }
89
90     public void prettyPrintHeader(CodeWriter w, PrettyPrinter tr) {
91         if (flags.isInterface()) {
92             w.write(flags.clearInterface().clearAbstract().translate());
93         }
94         else {
95             w.write(flags.translate());
96         }
97
98         if (key != null) {
99             w.write("tracked(");
100             print(key, w, tr);
101             w.write(") ");
102         }
103
104         if (flags.isInterface()) {
105             w.write("interface ");
106         }
107         else {
108             w.write("class ");
109         }
110
111         w.write(name);
112
113         if (superClass() != null) {
114             w.write(" extends ");
115             print(superClass(), w, tr);
116         }
117
118         if (! interfaces.isEmpty()) {
119             if (flags.isInterface()) {
120                 w.write(" extends ");
121             }
122             else {
123                 w.write(" implements ");
124             }
125
126             for (Iterator i = interfaces().iterator(); i.hasNext(); ) {
127                 TypeNode tn = (TypeNode) i.next();
128                 print(tn, w, tr);
129
130                 if (i.hasNext()) {
131                     w.write (", ");
132                 }
133             }
134         }
135
136         w.write(" {");
137     }
138
139     public void translate(CodeWriter w, Translator tr) {
140         ((CofferClassDecl_c) key(null)).superTranslate(w, tr);
141     }
142
143     public void superTranslate(CodeWriter w, Translator tr) {
144         super.translate(w, tr);
145     }
146 }
147
Popular Tags