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");
202 if((fd.isStatic()) || (fd.isVolatile())) {
203 this.incStaticFields();
207 public void addMethod(MethodDescriptor md) {
211 public void setModifiers(Modifiers modifiers) {
212 this.modifiers=modifiers;
215 public void setSuper(String superclass) {
216 this.superclass=superclass;
219 public ClassDescriptor getSuperDesc() {
223 public void setSuper(ClassDescriptor scd) {
227 public String getSuper() {
231 public void addSuperInterface(String superif) {
232 this.superinterfaces.addElement(superif);
235 public Vector<String> getSuperInterface() {
236 return this.superinterfaces;
239 public void addSuperInterfaces(ClassDescriptor sif) {
240 this.superIFdesc.add(sif);
243 public void incStaticBlocks() {
244 this.numstaticblocks++;
247 public int getNumStaticBlocks() {
248 return this.numstaticblocks;
251 public void incStaticFields() {
252 this.numstaticfields++;
255 public int getNumStaticFields() {
256 return this.numstaticfields;
259 public boolean isAbstract() {
260 return this.modifiers.isAbstract();
263 public boolean isInterface() {
264 return this.classid == -2;
267 public boolean isStatic() {
268 return this.modifiers.isStatic();
271 public void setAsInnerClass() {
272 this.isInnerClass = true;
275 public boolean isInnerClass() {
276 return this.isInnerClass;
279 public void setSurroundingClass(String sclass) {
280 this.surroundingclass=sclass;
283 public String getSurrounding() {
284 return this.surroundingclass;
287 public ClassDescriptor getSurroundingDesc() {
288 return this.surroudingdesc;
291 public void setSurrounding(ClassDescriptor scd) {
292 this.surroudingdesc=scd;
295 public void addInnerClass(ClassDescriptor icd) {
296 this.innerdescs.add(icd);
299 public Iterator getInnerClasses() {
300 return this.innerdescs.getDescriptorsIterator();
303 public SymbolTable getInnerClassTable() {
304 return this.innerdescs;
307 public void setAsEnum() {
311 public boolean isEnum() {
315 public void addEnum(ClassDescriptor icd) {
316 this.enumdescs.add(icd);
319 public Iterator getEnum() {
320 return this.enumdescs.getDescriptorsIterator();
323 public SymbolTable getEnumTable() {
324 return this.enumdescs;
327 public void addEnumConstant(String econstant) {
328 if(this.enumConstantTbl == null) {
329 this.enumConstantTbl = new HashMap<String, Integer>();
331 if(this.enumConstantTbl.containsKey(econstant)) {
334 this.enumConstantTbl.put(econstant, this.enumconstantid++);
339 public int getEnumConstant(String econstant) {
340 if(this.enumConstantTbl.containsKey(econstant)) {
341 return this.enumConstantTbl.get(econstant).intValue();
347 public HashMap<String, Integer> getEnumConstantTbl() {
348 return this.enumConstantTbl;
351 public Modifiers getModifier() {
352 return this.modifiers;