1 19 20 package org.netbeans.modules.debugger.jpda.models; 21 22 import com.sun.jdi.AbsentInformationException; 23 import com.sun.jdi.ClassNotLoadedException; 24 import com.sun.jdi.Field; 25 import com.sun.jdi.InvalidTypeException; 26 import com.sun.jdi.LocalVariable; 27 import com.sun.jdi.ObjectReference; 28 import com.sun.jdi.Value; 29 30 import org.netbeans.api.debugger.Watch; 31 import org.netbeans.api.debugger.jpda.InvalidExpressionException; 32 import org.netbeans.api.debugger.jpda.JPDAWatch; 33 import org.netbeans.api.debugger.jpda.ObjectVariable; 34 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 35 36 37 42 43 class JPDAObjectWatchImpl extends AbstractVariable implements JPDAWatch, 44 ObjectVariable { 45 46 private JPDADebuggerImpl debugger; 47 private Watch watch; 48 private String exceptionDescription; 49 50 51 JPDAObjectWatchImpl (JPDADebuggerImpl debugger, Watch watch, ObjectReference v) { 52 super ( 53 debugger, 54 v, 55 "" + watch + 56 (v instanceof ObjectReference ? "^" : "") 57 ); 58 this.debugger = debugger; 59 this.watch = watch; 60 } 61 62 JPDAObjectWatchImpl (JPDADebuggerImpl debugger, Watch watch, String exceptionDescription) { 63 super ( 64 debugger, 65 null, 66 "" + watch 67 ); 68 this.debugger = debugger; 69 this.watch = watch; 70 this.exceptionDescription = exceptionDescription; 71 } 72 73 78 public String getExpression () { 79 return watch.getExpression (); 80 } 81 82 87 public void setExpression (String expression) { 88 watch.setExpression (expression); 89 } 90 91 94 public void remove () { 95 watch.remove (); 96 } 97 98 104 public String getExceptionDescription () { 105 return exceptionDescription; 106 } 107 108 124 125 protected void setValue (final Value value) 126 throws InvalidExpressionException { 127 128 CallStackFrameImpl frame = (CallStackFrameImpl) debugger. 130 getCurrentCallStackFrame (); 131 if (frame == null) 132 throw new InvalidExpressionException ("No curent frame."); 133 134 try { 136 LocalVariable local = frame.getStackFrame ().visibleVariableByName 137 (getExpression ()); 138 if (local != null) 139 try { 140 frame.getStackFrame ().setValue (local, value); 141 return; 142 } catch (InvalidTypeException ex) { 143 throw new InvalidExpressionException (ex); 144 } catch (ClassNotLoadedException ex) { 145 throw new InvalidExpressionException (ex); 146 } 147 } catch (AbsentInformationException ex) { 148 } 150 151 ObjectReference thisObject = frame.getStackFrame ().thisObject (); 153 if (thisObject == null) 154 throw new InvalidExpressionException 155 ("Can not set value to expression."); 156 Field field = thisObject.referenceType ().fieldByName 157 (getExpression ()); 158 if (field == null) 159 throw new InvalidExpressionException 160 ("Can not set value to expression."); 161 try { 162 thisObject.setValue (field, value); 163 } catch (InvalidTypeException ex) { 164 throw new InvalidExpressionException (ex); 165 } catch (ClassNotLoadedException ex) { 166 throw new InvalidExpressionException (ex); 167 } 168 } 169 170 protected void setInnerValue (Value v) { 171 super.setInnerValue (v); 172 exceptionDescription = null; 173 } 174 175 void setException (String exceptionDescription) { 176 super.setInnerValue (null); 177 this.exceptionDescription = exceptionDescription; 178 } 179 180 boolean isPrimitive () { 181 return !(getInnerValue () instanceof ObjectReference); 182 } 183 184 public JPDAObjectWatchImpl clone() { 185 JPDAObjectWatchImpl clon; 186 if (exceptionDescription == null) { 187 clon = new JPDAObjectWatchImpl(getDebugger(), watch, (ObjectReference) getJDIValue()); 188 } else { 189 clon = new JPDAObjectWatchImpl(getDebugger(), watch, exceptionDescription); 190 } 191 return clon; 192 } 193 194 } 195 196 | Popular Tags |