5 public class ClassDescriptor extends Descriptor {
6 private static int UIDCount=1; // start from 1 instead of 0 for multicore gc
7 private final int classid;
9 ClassDescriptor superdesc;
10 boolean hasFlags=false;
20 int numstaticblocks = 0;
21 int numstaticfields = 0;
24 Vector<String> superinterfaces;
25 SymbolTable superIFdesc;
28 boolean isInnerClass=false;
30 // inner classes/enum can have these
31 String surroundingclass=null;
32 ClassDescriptor surroudingdesc=null;
33 SymbolTable innerdescs;
36 boolean isEnum = false;
37 SymbolTable enumdescs;
38 HashMap<String, Integer> enumConstantTbl;
39 int enumconstantid = 0;
41 public ClassDescriptor(String classname, boolean isInterface) {
42 this("", classname, isInterface);
45 public ClassDescriptor(String packagename, String classname, boolean isInterface) {
48 flags=new SymbolTable();
49 fields=new SymbolTable();
50 fieldvec=new Vector();
51 methods=new SymbolTable();
57 this.packagename=packagename;
58 superinterfaces = new Vector<String>();
59 superIFdesc = new SymbolTable();
60 this.innerdescs = new SymbolTable();
61 this.enumdescs = new SymbolTable();
68 public Iterator getMethods() {
69 return methods.getDescriptorsIterator();
72 public Iterator getFields() {
73 return fields.getDescriptorsIterator();
76 public Iterator getFlags() {
77 return flags.getDescriptorsIterator();
80 public Iterator getSuperInterfaces() {
81 return this.superIFdesc.getDescriptorsIterator();
84 public SymbolTable getFieldTable() {
88 public Vector getFieldVec() {
92 public SymbolTable getFlagTable() {
96 public SymbolTable getMethodTable() {
100 public SymbolTable getSuperInterfaceTable() {
101 return this.superIFdesc;
104 public String getSafeDescriptor() {
105 return "L"+safename.replace('.','/');
108 public String printTree(State state) {
110 String st=modifiers.toString()+"class "+getSymbol();
111 if (superclass!=null)
112 st+="extends "+superclass.toString();
113 if(this.superinterfaces != null) {
115 boolean needcomma = false;
116 for(int i = 0; i < this.superinterfaces.size(); i++) {
120 st += this.superinterfaces.elementAt(i);
125 indent=TreeNode.INDENT;
126 boolean printcr=false;
128 for(Iterator it=getFlags(); it.hasNext();) {
129 FlagDescriptor fd=(FlagDescriptor)it.next();
130 st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
138 for(Iterator it=getFields(); it.hasNext();) {
139 FieldDescriptor fd=(FieldDescriptor)it.next();
140 st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
146 for(Iterator it=this.getInnerClasses(); it.hasNext();) {
147 ClassDescriptor icd=(ClassDescriptor)it.next();
148 st+=icd.printTree(state)+"\n";
154 for(Iterator it=this.getEnum(); it.hasNext();) {
155 ClassDescriptor icd = (ClassDescriptor)it.next();
156 st += icd.getModifier().toString() + " enum " + icd.getSymbol() + " {\n ";
157 Set keys = icd.getEnumConstantTbl().keySet();
158 String[] econstants = new String[keys.size()];
159 Iterator it_keys = keys.iterator();
160 while(it_keys.hasNext()) {
161 String key = (String)it_keys.next();
162 econstants[icd.getEnumConstant(key)] = key;
164 for(int i = 0; i < econstants.length; i++) {
166 if(i < econstants.length-1) {
176 for(Iterator it=getMethods(); it.hasNext();) {
177 MethodDescriptor md=(MethodDescriptor)it.next();
178 st+=TreeNode.printSpace(indent)+md.toString()+" ";
179 BlockNode bn=state.getMethodBody(md);
180 st+=bn.printNode(indent)+"\n\n";
186 public void addFlag(FlagDescriptor fd) {
187 if (flags.contains(fd.getSymbol()))
188 throw new Error(fd.getSymbol()+" already defined");
193 public boolean hasFlags() {
194 return hasFlags||getSuperDesc()!=null&&getSuperDesc().hasFlags();
197 public void addField(FieldDescriptor fd) {
198 if (fields.contains(fd.getSymbol()))
199 throw new Error(fd.getSymbol()+" already defined");
203 this.incStaticFields();
205 fd.setClassDescriptor(this);
208 public void addMethod(MethodDescriptor md) {
212 public void setModifiers(Modifiers modifiers) {
213 this.modifiers=modifiers;
216 public void setSuper(String superclass) {
217 this.superclass=superclass;
220 public ClassDescriptor getSuperDesc() {
224 public void setSuper(ClassDescriptor scd) {
228 public String getSuper() {
232 public void addSuperInterface(String superif) {
233 this.superinterfaces.addElement(superif);
236 public Vector<String> getSuperInterface() {
237 return this.superinterfaces;
240 public void addSuperInterfaces(ClassDescriptor sif) {
241 this.superIFdesc.add(sif);
244 public void incStaticBlocks() {
245 this.numstaticblocks++;
248 public int getNumStaticBlocks() {
249 return this.numstaticblocks;
252 public void incStaticFields() {
253 this.numstaticfields++;
256 public int getNumStaticFields() {
257 return this.numstaticfields;
260 public boolean isAbstract() {
261 return this.modifiers.isAbstract();
264 public boolean isInterface() {
265 return this.classid == -2;
268 public boolean isStatic() {
269 return this.modifiers.isStatic();
272 public void setAsInnerClass() {
273 this.isInnerClass = true;
276 public boolean isInnerClass() {
277 return this.isInnerClass;
280 public void setSurroundingClass(String sclass) {
281 this.surroundingclass=sclass;
284 public String getSurrounding() {
285 return this.surroundingclass;
288 public ClassDescriptor getSurroundingDesc() {
289 return this.surroudingdesc;
292 public void setSurrounding(ClassDescriptor scd) {
293 this.surroudingdesc=scd;
296 public void addInnerClass(ClassDescriptor icd) {
297 this.innerdescs.add(icd);
300 public Iterator getInnerClasses() {
301 return this.innerdescs.getDescriptorsIterator();
304 public SymbolTable getInnerClassTable() {
305 return this.innerdescs;
308 public void setAsEnum() {
312 public boolean isEnum() {
316 public void addEnum(ClassDescriptor icd) {
317 this.enumdescs.add(icd);
320 public Iterator getEnum() {
321 return this.enumdescs.getDescriptorsIterator();
324 public SymbolTable getEnumTable() {
325 return this.enumdescs;
328 public void addEnumConstant(String econstant) {
329 if(this.enumConstantTbl == null) {
330 this.enumConstantTbl = new HashMap<String, Integer>();
332 if(this.enumConstantTbl.containsKey(econstant)) {
335 this.enumConstantTbl.put(econstant, this.enumconstantid++);
340 public int getEnumConstant(String econstant) {
341 if(this.enumConstantTbl.containsKey(econstant)) {
342 return this.enumConstantTbl.get(econstant).intValue();
348 public HashMap<String, Integer> getEnumConstantTbl() {
349 return this.enumConstantTbl;
352 public Modifiers getModifier() {
353 return this.modifiers;