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.InvalidTypeException; 25 import com.sun.jdi.LocalVariable; 26 import com.sun.jdi.ObjectReference; 27 import com.sun.jdi.Value; 28 import org.netbeans.api.debugger.Watch; 29 import org.netbeans.api.debugger.jpda.InvalidExpressionException; 30 import org.netbeans.api.debugger.jpda.JPDAWatch; 31 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 32 33 38 39 class JPDAWatchImpl extends AbstractVariable implements JPDAWatch { 40 41 private JPDADebuggerImpl debugger; 42 private Watch watch; 43 private String exceptionDescription; 44 private java.lang.ref.Reference <Object > nodeRef; 45 46 47 JPDAWatchImpl (JPDADebuggerImpl debugger, Watch watch, Value v, Object node) { 48 super ( 49 debugger, 50 v, 51 "" + watch + 52 (v instanceof ObjectReference ? "^" : "") 53 ); 54 this.debugger = debugger; 55 this.watch = watch; 56 this.nodeRef = new java.lang.ref.WeakReference <Object >(node); 57 } 58 59 JPDAWatchImpl ( 60 JPDADebuggerImpl debugger, 61 Watch watch, 62 Exception exception, 63 Object node 64 ) { 65 super ( 66 debugger, 67 null, 68 "" + watch 69 ); 70 this.debugger = debugger; 71 this.watch = watch; 72 this.exceptionDescription = exception.getLocalizedMessage (); 73 if (exceptionDescription == null) 74 exceptionDescription = exception.getMessage (); 75 this.nodeRef = new java.lang.ref.WeakReference <Object >(node); 76 } 77 78 83 public String getExpression () { 84 return watch.getExpression (); 85 } 86 87 92 public void setExpression (String expression) { 93 watch.setExpression (expression); 94 } 95 96 99 public void remove () { 100 watch.remove (); 101 } 102 103 109 public String getExceptionDescription () { 110 return exceptionDescription; 111 } 112 113 132 133 protected void setInnerValue (Value v) { 134 super.setInnerValue (v); 135 exceptionDescription = null; 136 } 137 138 protected void setValue (Value value) throws InvalidExpressionException { 139 CallStackFrameImpl frame = (CallStackFrameImpl) debugger. 140 getCurrentCallStackFrame (); 141 if (frame == null) 142 throw new InvalidExpressionException ("No curent frame."); 143 LocalVariable local = null; 144 try { 145 local = frame.getStackFrame ().visibleVariableByName 146 (getExpression ()); 147 } catch (AbsentInformationException ex) { 148 throw new InvalidExpressionException ("Can not set value to expression."); 149 } 150 if (local == null) 151 throw new InvalidExpressionException ("Can not set value to expression."); 152 try { 153 frame.getStackFrame ().setValue (local, value); 154 } catch (InvalidTypeException ex) { 155 throw new InvalidExpressionException (ex); 156 } catch (ClassNotLoadedException ex) { 157 throw new InvalidExpressionException (ex); 158 } 159 } 160 161 void setException (String exceptionDescription) { 162 setInnerValue (null); 163 this.exceptionDescription = exceptionDescription; 164 } 165 166 boolean isPrimitive () { 167 return !(getInnerValue () instanceof ObjectReference); 168 } 169 170 public JPDAWatchImpl clone() { 171 JPDAWatchImpl clon; 172 if (exceptionDescription == null) { 173 clon = new JPDAWatchImpl(getDebugger(), watch, getJDIValue(), nodeRef.get()); 174 } else { 175 clon = new JPDAWatchImpl(getDebugger(), watch, new Exception (exceptionDescription), nodeRef.get()); 176 } 177 return clon; 178 } 179 180 } 181 182 | Popular Tags |