KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > types > ParsedClassType_c


1 package polyglot.ext.jl.types;
2
3 import java.util.LinkedList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import polyglot.frontend.Source;
7 import polyglot.types.*;
8 import polyglot.types.Package;
9 import polyglot.util.InternalCompilerError;
10 import polyglot.util.Position;
11 import polyglot.util.TypedList;
12
13 /**
14  * ParsedClassType
15  *
16  * Overview:
17  * A ParsedClassType represents a information that has been parsed (but not
18  * necessarily type checked) from a .java file.
19  **/

20 public class ParsedClassType_c extends ClassType_c implements ParsedClassType
21 {
22     protected transient LazyClassInitializer init;
23     protected transient Source fromSource;
24     protected Type superType;
25     protected List JavaDoc interfaces;
26     protected List JavaDoc methods;
27     protected List JavaDoc fields;
28     protected List JavaDoc constructors;
29     protected List JavaDoc memberClasses;
30     protected Package JavaDoc package_;
31     protected Flags flags;
32     protected Kind kind;
33     protected String JavaDoc name;
34     protected ClassType outer;
35     /** Was the class declared in a static context? */
36     protected boolean inStaticContext = false;
37
38     protected ParsedClassType_c() {
39     super();
40     }
41
42     public ParsedClassType_c(TypeSystem ts, LazyClassInitializer init,
43                              Source fromSource) {
44     super(ts);
45         this.init = init;
46         this.fromSource = fromSource;
47
48         if (init == null) {
49           throw new InternalCompilerError("Null lazy class initializer");
50         }
51     }
52
53     public Source fromSource() {
54         return fromSource;
55     }
56     
57     public Kind kind() {
58         return kind;
59     }
60
61     public void inStaticContext(boolean inStaticContext) {
62         this.inStaticContext = inStaticContext;
63     }
64
65     public boolean inStaticContext() {
66         return inStaticContext;
67     }
68     
69     public ClassType outer() {
70         if (isTopLevel())
71             return null;
72         if (outer == null)
73             throw new InternalCompilerError("Nested classes must have outer classes.");
74             
75         return outer;
76     }
77
78     public String JavaDoc name() {
79         if (isAnonymous())
80             throw new InternalCompilerError("Anonymous classes cannot have names.");
81
82         if (name == null)
83             throw new InternalCompilerError("Non-anonymous classes must have names.");
84         return name;
85     }
86
87     /** Get the class's super type. */
88     public Type superType() {
89         return this.superType;
90     }
91
92     /** Get the class's package. */
93     public Package JavaDoc package_() {
94         return package_;
95     }
96
97     /** Get the class's flags. */
98     public Flags flags() {
99         if (isAnonymous())
100             return Flags.NONE;
101         return flags;
102     }
103
104     /** Return true if we no longer need the initializer object. */
105     protected boolean initialized() {
106         return this.methods != null &&
107                this.constructors != null &&
108                this.fields != null &&
109                this.memberClasses != null &&
110                this.interfaces != null;
111     }
112
113     /** Free the initializer object if we no longer need it. */
114     protected void freeInit() {
115         if (initialized()) {
116             init = null;
117         }
118         else if (init == null) {
119           throw new InternalCompilerError("Null lazy class initializer");
120         }
121     }
122
123     public void flags(Flags flags) {
124     this.flags = flags;
125     }
126
127     public void kind(Kind kind) {
128         this.kind = kind;
129     }
130
131     public void outer(ClassType outer) {
132         if (isTopLevel())
133             throw new InternalCompilerError("Top-level classes cannot have outer classes.");
134         this.outer = outer;
135     }
136
137     public void name(String JavaDoc name) {
138         if (isAnonymous())
139             throw new InternalCompilerError("Anonymous classes cannot have names.");
140         this.name = name;
141     }
142
143     public void position(Position pos) {
144     this.position = pos;
145     }
146
147     public void package_(Package JavaDoc p) {
148     this.package_ = p;
149     }
150
151     public void superType(Type t) {
152     this.superType = t;
153     }
154
155     public void addInterface(Type t) {
156     interfaces().add(t);
157     }
158
159     public void addMethod(MethodInstance mi) {
160     methods().add(mi);
161     }
162
163     public void addConstructor(ConstructorInstance ci) {
164     constructors().add(ci);
165     }
166
167     public void addField(FieldInstance fi) {
168     fields().add(fi);
169     }
170
171     public void addMemberClass(ClassType t) {
172     memberClasses().add(t);
173     }
174
175     /** Return a mutable list of constructors */
176     public List JavaDoc constructors() {
177         if (constructors == null) {
178             constructors = new TypedList(new LinkedList JavaDoc(), ConstructorInstance.class, false);
179             init.initConstructors(this);
180             freeInit();
181         }
182         return constructors;
183     }
184
185     /** Return a mutable list of member classes */
186     public List JavaDoc memberClasses() {
187         if (memberClasses == null) {
188             memberClasses = new TypedList(new LinkedList JavaDoc(), Type.class, false);
189             init.initMemberClasses(this);
190             freeInit();
191         }
192         return memberClasses;
193     }
194
195     /** Return a mutable list of methods */
196     public List JavaDoc methods() {
197         if (methods == null) {
198             methods = new TypedList(new LinkedList JavaDoc(), MethodInstance.class, false);
199             init.initMethods(this);
200             freeInit();
201         }
202         return methods;
203     }
204
205     /** Return a mutable list of fields */
206     public List JavaDoc fields() {
207         if (fields == null) {
208             fields = new TypedList(new LinkedList JavaDoc(), FieldInstance.class, false);
209             init.initFields(this);
210             freeInit();
211         }
212         return fields;
213     }
214
215     /** Return a mutable list of interfaces */
216     public List JavaDoc interfaces() {
217         if (interfaces == null) {
218             interfaces = new TypedList(new LinkedList JavaDoc(), Type.class, false);
219             init.initInterfaces(this);
220             freeInit();
221         }
222         return interfaces;
223     }
224 }
225
Popular Tags