| 1 22 package org.aspectj.debugger.gui; 23 24 import com.sun.jdi.*; 25 import java.util.*; 26 27 public class AJClassNode extends AJTreeNode { 28 29 private ReferenceType refType; 30 31 public AJClassNode(ReferenceType refType) { 32 super(AJIcons.CLASS_ICON); 33 this.refType = refType; 34 setUserObject(refType); 35 if (!callsAddKids()) addKids(); 36 } 37 38 private byte numAddKids = 0; 39 protected void addKids() { 40 if (numAddKids++ > 1) throw new RuntimeException ("Only call addKids() once"); 41 addSuperTypes(); 42 addStaticFields(); 43 addMethods(); 44 } 45 46 protected boolean callsAddKids() { 47 return false; 48 } 49 50 private void addSuperTypes() { 51 if (refType instanceof ClassType) addSuperTypes((ClassType) refType); 52 else if (refType instanceof InterfaceType) addSuperTypes((InterfaceType) refType); 53 else if (refType instanceof ArrayType) addSuperTypes((ArrayType) refType); 54 } 55 56 private void addSuperTypes(ClassType classType) { 57 if (classType.name().equals("java.lang.Object")) { 58 return; 59 } 60 ClassType superClass = classType.superclass(); 61 if (superClass != null) { 62 add(newClassNode(superClass)); 63 } 64 addSuperTypes(classType.allInterfaces()); 65 } 66 67 protected AJClassNode newClassNode(ReferenceType refType) { 68 return new AJClassNode(refType); 69 } 70 71 private void addSuperTypes(InterfaceType interfaceType) { 72 addSuperTypes(interfaceType.superinterfaces()); 73 } 74 75 private void addSuperTypes(List interfaces) { 76 Iterator iter = interfaces.iterator(); 77 while (iter.hasNext()) { 78 InterfaceType interfaceType = (InterfaceType) iter.next(); 79 add(newClassNode(interfaceType)); 80 } 81 } 82 83 private void addSuperTypes(ArrayType arrayType) { 84 } 85 86 private void addStaticFields() { 87 if (refType == null) return; 88 Iterator iter = refType.allFields().iterator(); 89 while (iter.hasNext()) { 90 Field field = (Field) iter.next(); 91 if (field.isStatic() && field.declaringType().equals(refType)) { 92 AJValueNode valueNode = AJValueNodeFactory.make(refType, field); 93 94 if (valueNode.getName().indexOf("$") == -1) { 96 add(valueNode); 97 } 98 } 99 } 100 } 101 102 105 protected void addMethods() { 106 } 107 108 public int getType() { 109 if (refType == null) { 110 } else if (refType instanceof ClassType) { 113 ClassType type = (ClassType) refType; 114 if (type.isStatic()) { 115 if (type.isPublic()) return AJIcons.CLASS_STATIC_PUBLIC_ICON; 116 if (type.isPackagePrivate()) return AJIcons.CLASS_STATIC_PACKAGE_ICON; 117 if (type.isProtected()) return AJIcons.CLASS_STATIC_PROTECTED_ICON; 118 if (type.isPrivate()) return AJIcons.CLASS_STATIC_PRIVATE_ICON; 119 } else { 120 if (type.isPublic()) return AJIcons.CLASS_PUBLIC_ICON; 121 if (type.isPackagePrivate()) return AJIcons.CLASS_PACKAGE_ICON; 122 if (type.isProtected()) return AJIcons.CLASS_PROTECTED_ICON; 123 if (type.isPrivate()) return AJIcons.CLASS_PRIVATE_ICON; 124 } 125 return AJIcons.CLASS_ICON; 126 } else if (refType instanceof InterfaceType) { 127 return AJIcons.INTERFACE_ICON; 128 } 129 return AJIcons.CLASS_ICON; 132 } 133 134 public String toString() { 135 return ((ReferenceType)getUserObject()).name(); 136 } 137 138 } 139 | Popular Tags |