1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 27 import java.awt.datatransfer.*; 28 import java.awt.event.MouseEvent ; 29 import java.util.*; 30 import javax.swing.tree.*; 31 import com.sun.jdi.*; 32 33 public class AJValueNode extends AJTreeNode { 34 35 protected AJValueGetter getter = null; 36 37 public AJValueNode(AJValueGetter getter, int type) { 38 super(type); 39 this.getter = getter; 40 } 42 public AJValueNode(AJValueGetter getter) { 43 this(getter, AJIcons.BAD_ICON); 44 setType(_getType()); 45 } 46 47 public Value getValue() { 48 return getter.getValue(); 49 } 50 51 public Value getValue(String s) { 52 return getter.getValue(s); 53 } 54 55 public ReferenceType getDeclaringClass() { 56 return getter.getDeclaringClass(); 57 } 58 59 public boolean canSetWatchPoint() { 60 return (getDeclaringClass() != null); 61 } 62 63 public void setValue(Object o) throws DebuggerException { 64 if (o == null) return; 65 AJTreeNode parent = (AJTreeNode) getParent(); 66 while (!parent.isStackFrame()) { 67 parent = (AJTreeNode) parent.getParent(); 68 } 69 AJStackFrameNode parentHack = (AJStackFrameNode) parent; 70 try { 71 getter.setValue(ComponentRepository.getAJDebugger().getValue(o, parentHack.getStackFrame())); 72 } catch (ClassNotLoadedException cnle) { 73 } catch (InvalidTypeException ite) { 74 AJUtil.ex(ite); 75 } 76 } 77 78 public void setWatchPoint() { 79 ReferenceType refType = getDeclaringClass(); 80 if (refType == null) { 81 AJUtil.warn("You cannot set a watchpoint on: " + this); 82 return; 83 } 84 String declaringType = refType.name(); 85 String name = getName(); 86 String command = "watch " + declaringType + "." + name; 87 ComponentRepository.getCommandLine().executeCommand(command); 88 } 89 90 public ThreadReference getThread() 94 throws ClassNotLoadedException, 95 IncompatibleThreadStateException { 96 return getter.getThread(); 97 } 98 99 public String getName() { 100 return getter.getName(); 101 } 102 103 public Type getTypeRef() throws ClassNotLoadedException { 104 return getter.getTypeRef(); 105 } 106 107 public String getTypeName() { 111 try { 112 return getter.getTypeName(); 113 } catch (Exception e) { Util.error(e); } 114 return ""; 115 } 116 117 public String getValueString() { 121 try { 122 return "" + getter.getValue(); 123 } catch (Exception e) { 124 } 125 return ""; 126 } 127 128 public String toString() { 132 String name = "<no-name>"; 133 String type = "<no-type>"; 134 Value value = null; 135 try { 136 name = getter.getName(); 137 } catch (Exception e) { 138 } 139 try { 140 type = AJUtil.stripParens(getter.getTypeName()); 141 } catch (Exception e) { 142 } 143 try { 144 value = getValue(); 145 } catch (InvalidStackFrameException isfe) { 146 } 147 return name + ": " + type + " = " + format(value); 148 } 149 150 protected String format(Value value) { 152 return value + ""; 153 } 154 155 public boolean isField() { 156 return g() instanceof FieldGetter; 157 } 158 159 private int _getType() { 164 if (isField()) { 165 FieldGetter g = (FieldGetter) g(); 166 Field field = g.getField(); 167 if (field.isStatic()) { 168 if (field.isPublic()) return AJIcons.FIELD_STATIC_PUBLIC_ICON; 169 if (field.isPackagePrivate()) return AJIcons.FIELD_STATIC_PACKAGE_ICON; 170 if (field.isProtected()) return AJIcons.FIELD_STATIC_PROTECTED_ICON; 171 if (field.isPrivate()) return AJIcons.FIELD_STATIC_PRIVATE_ICON; 172 } else { 173 if (field.isPublic()) return AJIcons.FIELD_PUBLIC_ICON; 174 if (field.isPackagePrivate()) return AJIcons.FIELD_PACKAGE_ICON; 175 if (field.isProtected()) return AJIcons.FIELD_PROTECTED_ICON; 176 if (field.isPrivate()) return AJIcons.FIELD_PRIVATE_ICON; 177 } 178 } 179 return getType(); 180 } 181 182 protected AJValueGetter g() { 183 return getter; 184 } 185 186 public void leftMouseButton(MouseEvent e) { 187 } 188 189 public void middleMouseButton(MouseEvent e) { 190 AJTreeNodeMenu.showValueNodeMenu(this, e.getComponent(), e.getX(), e.getY()); 191 } 192 193 public void rightMouseButton(MouseEvent e) { 194 AJTreeNodeMenu.showValueNodeMenu(this, e.getComponent(), e.getX(), e.getY()); 195 } 196 197 public void setValue() { 198 Dialogs.showNewValueDialog(this); 199 } 200 201 public boolean isValueNode() { 202 return true; 203 } 204 } 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | Popular Tags |