1 19 20 package org.netbeans.modules.debugger.jpda.models; 21 22 import com.sun.jdi.ClassNotLoadedException; 23 import com.sun.jdi.ClassType; 24 import com.sun.jdi.Field; 25 import com.sun.jdi.InvalidTypeException; 26 import com.sun.jdi.ObjectReference; 27 import com.sun.jdi.ReferenceType; 28 import com.sun.jdi.Value; 29 import org.netbeans.api.debugger.jpda.InvalidExpressionException; 30 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 31 32 33 36 class FieldVariable extends AbstractVariable implements 37 org.netbeans.api.debugger.jpda.Field { 38 39 protected Field field; 40 private ObjectReference objectReference; 42 private String genericSignature; 43 44 45 FieldVariable ( 46 JPDADebuggerImpl debugger, 47 Value value, 48 Field field, 50 String parentID, 51 ObjectReference objectReference 52 ) { 53 super ( 54 debugger, 55 value, 56 parentID + '.' + field.name () + 57 (value instanceof ObjectReference ? "^" : "") 58 ); 59 this.field = field; 60 this.objectReference = objectReference; 62 } 63 64 FieldVariable ( 65 JPDADebuggerImpl debugger, 66 Value value, 67 Field field, 69 String parentID, 70 String genericSignature 71 ) { 72 super(debugger, value, genericSignature, parentID + '.' + field.name () + 73 (value instanceof ObjectReference ? "^" : "")); 74 this.field = field; 75 this.genericSignature = genericSignature; 76 } 78 79 81 82 87 public String getName () { 88 return field.name (); 89 } 90 91 96 public String getClassName () { 97 return field.declaringType ().name (); } 99 100 105 public String getDeclaredType () { 106 return field.typeName (); 107 } 108 109 114 public boolean isStatic () { 115 return field.isStatic (); 116 } 117 118 protected void setValue (Value value) throws InvalidExpressionException { 119 try { 120 boolean set = false; 121 if (objectReference != null) { 122 objectReference.setValue (field, value); 123 set = true; 124 } else { 125 ReferenceType rt = field.declaringType(); 126 if (rt instanceof ClassType) { 127 ClassType ct = (ClassType) rt; 128 ct.setValue(field, value); 129 set = true; 130 } 131 } 132 if (!set) { 133 throw new InvalidExpressionException(field.toString()); 134 } 135 } catch (InvalidTypeException ex) { 136 throw new InvalidExpressionException (ex); 137 } catch (ClassNotLoadedException ex) { 138 throw new InvalidExpressionException (ex); 139 } 140 } 141 142 public FieldVariable clone() { 143 FieldVariable clon; 144 if (genericSignature == null) { 145 clon = new FieldVariable(getDebugger(), getJDIValue(), field, 146 getID().substring(0, getID().length() - ("." + field.name() + (getJDIValue() instanceof ObjectReference ? "^" : "")).length()), 147 objectReference); 148 } else { 149 clon = new FieldVariable(getDebugger(), getJDIValue(), field, 150 getID().substring(0, getID().length() - ("." + field.name() + (getJDIValue() instanceof ObjectReference ? "^" : "")).length()), 151 genericSignature); 152 } 153 return clon; 154 } 155 156 158 public String toString () { 159 return "FieldVariable " + field.name (); 160 } 161 } 162 163 | Popular Tags |