1 19 20 package org.netbeans.modules.debugger.jpda.models; 21 22 import com.sun.jdi.AbsentInformationException; 23 import com.sun.jdi.IncompatibleThreadStateException; 24 import com.sun.jdi.InvalidStackFrameException; 25 import com.sun.jdi.NativeMethodException; 26 import com.sun.jdi.ObjectReference; 27 import com.sun.jdi.StackFrame; 28 import com.sun.jdi.ThreadReference; 29 import com.sun.jdi.VMDisconnectedException; 30 import com.sun.jdi.Value; 31 32 import java.util.ArrayList ; 33 import java.util.Collections ; 34 import java.util.List ; 35 36 import org.netbeans.api.debugger.jpda.CallStackFrame; 37 import org.netbeans.api.debugger.jpda.JPDAThread; 38 import org.netbeans.api.debugger.jpda.LocalVariable; 39 import org.netbeans.api.debugger.jpda.This; 40 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 41 import org.netbeans.spi.debugger.jpda.EditorContext.Operation; 42 43 44 47 public class CallStackFrameImpl implements CallStackFrame { 48 49 private StackFrame sf; 50 private int depth; 51 private JPDADebuggerImpl debugger; 52 private Operation currentOperation; 54 private boolean valid; 55 56 public CallStackFrameImpl ( 57 StackFrame sf, 58 int depth, 59 JPDADebuggerImpl debugger 60 ) { 61 this.sf = sf; 62 this.depth = depth; 63 this.debugger = debugger; 64 this.valid = true; } 66 67 69 74 public synchronized int getLineNumber (String struts) { 75 if (!valid) return 0; 76 try { 77 return getStackFrame().location ().lineNumber (struts); 78 } catch (InvalidStackFrameException isfex) { 79 valid = false; 81 return 0; 82 } catch (VMDisconnectedException ex) { 83 return 0; 84 } 85 } 86 87 public synchronized Operation getCurrentOperation(String struts) { 88 return currentOperation; 89 } 90 91 public synchronized void setCurrentOperation(Operation operation) { 92 this.currentOperation = operation; 93 } 94 95 100 public synchronized String getMethodName () { 101 if (!valid) return ""; 102 try { 103 return getStackFrame().location ().method ().name (); 104 } catch (InvalidStackFrameException ex) { 105 valid = false; 107 return ""; 108 } catch (VMDisconnectedException ex) { 109 return ""; 110 } 111 } 112 113 118 public synchronized String getClassName () { 119 if (!valid) return ""; 120 try { 121 return getStackFrame().location ().declaringType ().name (); 122 } catch (InvalidStackFrameException ex) { 123 valid = false; 125 return ""; 126 } catch (VMDisconnectedException ex) { 127 return ""; 128 } 129 } 130 131 136 public synchronized String getDefaultStratum () { 137 if (!valid) return ""; 138 try { 139 return getStackFrame().location ().declaringType ().defaultStratum (); 140 } catch (InvalidStackFrameException ex) { 141 valid = false; 143 return ""; 144 } catch (VMDisconnectedException ex) { 145 return ""; 146 } 147 } 148 149 154 public synchronized List <String > getAvailableStrata () { 155 if (!valid) return Collections.emptyList(); 156 try { 157 return getStackFrame().location ().declaringType ().availableStrata (); 158 } catch (InvalidStackFrameException ex) { 159 valid = false; 161 return Collections.emptyList(); 162 } catch (VMDisconnectedException ex) { 163 return Collections.emptyList(); 164 } 165 } 166 167 174 public synchronized String getSourceName (String stratum) throws AbsentInformationException { 175 if (!valid) return ""; 176 try { 177 return getStackFrame().location ().sourceName (stratum); 178 } catch (InvalidStackFrameException ex) { 179 valid = false; 181 return ""; 182 } catch (VMDisconnectedException ex) { 183 return ""; 184 } 185 } 186 187 192 public synchronized String getSourcePath (String stratum) throws AbsentInformationException { 193 if (!valid) return ""; 194 try { 195 return getStackFrame().location ().sourcePath (stratum); 196 } catch (InvalidStackFrameException ex) { 197 valid = false; 199 return ""; 200 } catch (VMDisconnectedException ex) { 201 return ""; 202 } 203 } 204 205 210 public org.netbeans.api.debugger.jpda.LocalVariable[] getLocalVariables () 211 throws AbsentInformationException { 212 try { 213 String className = getStackFrame ().location ().declaringType ().name (); 214 List l = getStackFrame ().visibleVariables (); 215 int n = l.size(); 216 LocalVariable[] locals = new LocalVariable [n]; 217 for (int i = 0; i < n; i++) { 218 com.sun.jdi.LocalVariable lv = (com.sun.jdi.LocalVariable) l.get (i); 219 Value v = getStackFrame ().getValue (lv); 220 Local local = (Local) debugger.getLocalVariable(lv, v); 221 local.setFrame(this); 222 local.setInnerValue(v); 223 local.setClassName(className); 224 locals[i] = local; 225 } 226 return locals; 227 } catch (NativeMethodException ex) { 228 throw new AbsentInformationException ("native method"); 229 } catch (InvalidStackFrameException ex) { 230 throw new AbsentInformationException ("thread is running"); 231 } catch (VMDisconnectedException ex) { 232 return new LocalVariable [0]; 233 } 234 } 235 236 242 public synchronized This getThisVariable () { 243 if (!valid) return null; 244 ObjectReference thisR; 245 try { 246 thisR = getStackFrame().thisObject (); 247 } catch (InvalidStackFrameException ex) { 248 valid = false; 249 return null; 250 } 251 if (thisR == null) return null; 252 return new ThisVariable (debugger, thisR, ""); 253 } 254 255 260 public void makeCurrent () { 261 debugger.setCurrentCallStackFrame (this); 262 } 263 264 270 public synchronized boolean isObsolete () { 271 return getStackFrame ().location ().method ().isObsolete (); 272 } 273 274 public boolean canPop() { 275 if (!debugger.canPopFrames()) return false; 276 ThreadReference t = getStackFrame().thread(); 277 try { 278 if (t.frameCount() <= 1) { return false; 280 } 281 List topFrames = t.frames(0, 2); 282 if (((StackFrame) topFrames.get(0)).location().method().isNative() || 283 ((StackFrame) topFrames.get(1)).location().method().isNative()) { 284 return
|