6 public class ClassDescriptor extends Descriptor {
7 private static int UIDCount=1; // start from 1 instead of 0 for multicore gc
8 private final int classid;
10 ClassDescriptor superdesc;
11 boolean hasFlags=false;
21 int numstaticblocks = 0;
22 int numstaticfields = 0;
25 Vector<String> superinterfaces;
26 SymbolTable superIFdesc;
27 private boolean isInterface;
30 boolean isInnerClass=false;
32 // inner classes/enum can have these
33 String surroundingclass=null;
34 ClassDescriptor surroudingdesc=null;
35 SymbolTable innerdescs;
38 boolean isEnum = false;
39 SymbolTable enumdescs;
40 HashMap<String, Integer> enumConstantTbl;
41 int enumconstantid = 0;
44 Lattice<String> locOrder;
46 public ClassDescriptor(String classname, boolean isInterface) {
47 this("", classname, isInterface);
50 public ClassDescriptor(String packagename, String classname, boolean isInterface) {
53 flags=new SymbolTable();
54 fields=new SymbolTable();
55 fieldvec=new Vector();
56 methods=new SymbolTable();
57 this.isInterface = isInterface;
59 this.packagename=packagename;
60 superinterfaces = new Vector<String>();
61 superIFdesc = new SymbolTable();
62 this.innerdescs = new SymbolTable();
63 this.enumdescs = new SymbolTable();
64 this.locOrder=new Lattice<String>();
71 public Iterator getMethods() {
72 return methods.getDescriptorsIterator();
75 public Iterator getFields() {
76 return fields.getDescriptorsIterator();
79 public Iterator getFlags() {
80 return flags.getDescriptorsIterator();
83 public Iterator getSuperInterfaces() {
84 return this.superIFdesc.getDescriptorsIterator();
87 public SymbolTable getFieldTable() {
91 public Vector getFieldVec() {
95 public SymbolTable getFlagTable() {
99 public SymbolTable getMethodTable() {
103 public SymbolTable getSuperInterfaceTable() {
104 return this.superIFdesc;
107 public String getSafeDescriptor() {
108 return "L"+safename.replace('.','/');
111 public String printTree(State state) {
113 String st=modifiers.toString()+"class "+getSymbol();
114 if (superclass!=null)
115 st+="extends "+superclass.toString();
116 if(this.superinterfaces != null) {
118 boolean needcomma = false;
119 for(int i = 0; i < this.superinterfaces.size(); i++) {
123 st += this.superinterfaces.elementAt(i);
128 indent=TreeNode.INDENT;
129 boolean printcr=false;
131 for(Iterator it=getFlags(); it.hasNext();) {
132 FlagDescriptor fd=(FlagDescriptor)it.next();
133 st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
141 for(Iterator it=getFields(); it.hasNext();) {
142 FieldDescriptor fd=(FieldDescriptor)it.next();
143 st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
149 for(Iterator it=this.getInnerClasses(); it.hasNext();) {
150 ClassDescriptor icd=(ClassDescriptor)it.next();
151 st+=icd.printTree(state)+"\n";
157 for(Iterator it=this.getEnum(); it.hasNext();) {
158 ClassDescriptor icd = (ClassDescriptor)it.next();
159 st += icd.getModifier().toString() + " enum " + icd.getSymbol() + " {\n ";
160 Set keys = icd.getEnumConstantTbl().keySet();
161 String[] econstants = new String[keys.size()];
162 Iterator it_keys = keys.iterator();
163 while(it_keys.hasNext()) {
164 String key = (String)it_keys.next();
165 econstants[icd.getEnumConstant(key)] = key;
167 for(int i = 0; i < econstants.length; i++) {
169 if(i < econstants.length-1) {
179 for(Iterator it=getMethods(); it.hasNext();) {
180 MethodDescriptor md=(MethodDescriptor)it.next();
181 st+=TreeNode.printSpace(indent)+md.toString()+" ";
182 BlockNode bn=state.getMethodBody(md);
183 st+=bn.printNode(indent)+"\n\n";
189 public MethodDescriptor getCalledMethod(MethodDescriptor md) {
190 ClassDescriptor cn=this;
192 Iterator methodit=cn.getMethods();
193 //Iterator through methods
194 while(methodit.hasNext()) {
195 Set possiblematches=cn.getMethodTable().getSet(md.getSymbol());
196 boolean foundmatch=false;
197 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
198 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
199 if (md.matches(matchmd)) {
204 //Not found...walk one level up
205 cn=cn.getSuperDesc();
209 public void addFlag(FlagDescriptor fd) {
210 if (flags.contains(fd.getSymbol()))
211 throw new Error(fd.getSymbol()+" already defined");
216 public boolean hasFlags() {
217 return hasFlags||getSuperDesc()!=null&&getSuperDesc().hasFlags();
220 public void addField(FieldDescriptor fd) {
221 if (fields.contains(fd.getSymbol()))
222 throw new Error(fd.getSymbol()+" already defined");
226 this.incStaticFields();
228 fd.setClassDescriptor(this);
231 public void addMethod(MethodDescriptor md) {
235 public void setModifiers(Modifiers modifiers) {
236 this.modifiers=modifiers;
239 public void setSuper(String superclass) {
240 this.superclass=superclass;
243 public ClassDescriptor getSuperDesc() {
247 public void setSuper(ClassDescriptor scd) {
251 public String getSuper() {
255 public void addSuperInterface(String superif) {
256 this.superinterfaces.addElement(superif);
259 public Vector<String> getSuperInterface() {
260 return this.superinterfaces;
263 public void addSuperInterfaces(ClassDescriptor sif) {
264 this.superIFdesc.add(sif);
267 public void incStaticBlocks() {
268 this.numstaticblocks++;
271 public int getNumStaticBlocks() {
272 return this.numstaticblocks;
275 public void incStaticFields() {
276 this.numstaticfields++;
279 public int getNumStaticFields() {
280 return this.numstaticfields;
283 public boolean isAbstract() {
284 return this.modifiers.isAbstract();
287 public boolean isInterface() {
288 return this.isInterface;
291 public boolean isStatic() {
292 return this.modifiers.isStatic();
295 public void setAsInnerClass() {
296 this.isInnerClass = true;
299 public boolean isInnerClass() {
300 return this.isInnerClass;
303 public void setSurroundingClass(String sclass) {
304 this.surroundingclass=sclass;
307 public String getSurrounding() {
308 return this.surroundingclass;
311 public ClassDescriptor getSurroundingDesc() {
312 return this.surroudingdesc;
315 public void setSurrounding(ClassDescriptor scd) {
316 this.surroudingdesc=scd;
319 public void addInnerClass(ClassDescriptor icd) {
320 this.innerdescs.add(icd);
323 public Iterator getInnerClasses() {
324 return this.innerdescs.getDescriptorsIterator();
327 public SymbolTable getInnerClassTable() {
328 return this.innerdescs;
331 public void setAsEnum() {
335 public boolean isEnum() {
339 public void addEnum(ClassDescriptor icd) {
340 this.enumdescs.add(icd);
343 public Iterator getEnum() {
344 return this.enumdescs.getDescriptorsIterator();
347 public SymbolTable getEnumTable() {
348 return this.enumdescs;
351 public void addEnumConstant(String econstant) {
352 if(this.enumConstantTbl == null) {
353 this.enumConstantTbl = new HashMap<String, Integer>();
355 if(this.enumConstantTbl.containsKey(econstant)) {
358 this.enumConstantTbl.put(econstant, this.enumconstantid++);
363 public int getEnumConstant(String econstant) {
364 if(this.enumConstantTbl.containsKey(econstant)) {
365 return this.enumConstantTbl.get(econstant).intValue();
371 public HashMap<String, Integer> getEnumConstantTbl() {
372 return this.enumConstantTbl;
375 public Modifiers getModifier() {
376 return this.modifiers;
379 public Lattice<String> getLocOrder(){
380 return this.locOrder;
383 public void setLocOrder(Lattice<String> locOrder){
384 this.locOrder=locOrder;