1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 import org.aspectj.debugger.request.*; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import javax.swing.*; 31 import javax.swing.event.*; 32 import javax.swing.tree.*; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Iterator ; 36 import com.sun.jdi.*; 37 38 public class AJStackFrameNode extends AJTreeNode { 39 40 43 protected StackFrame frame = null; 44 45 48 protected Location originalLocation = null; 49 50 53 protected AJStackFrameFormatter.MethodAndSource ms = null; 54 55 private String str = "<unititialized frame>"; 56 57 62 public AJStackFrameNode(StackFrame frame) { 63 super(AJIcons.STACKFRAME_ICON); 64 setUserObject(frame); 65 this.frame = frame; 67 originalLocation = frame.location(); ms = AJStackFrameFormatter.format(getStackFrame()); 69 str = ms + ""; 70 thread = frame.thread(); 71 } 72 73 ThreadReference thread = null; 75 76 public int index() { 78 int index = -1; 79 try { 80 index = 81 ComponentRepository.getAJDebugger(). 82 frames(frame.thread()).indexOf(frame); 83 } catch (Exception e) {} 85 return index; 86 } 87 88 public void rightMouseButton(MouseEvent e) { 89 JPopupMenu menu = null; 90 if (ms.isValid()) { 91 menu = new ShowMenu(); 92 } else { 93 menu = new NoShowMenu(); 94 } 95 menu.show(ComponentRepository. 96 getThreadGroupTreePane().getTree(), 97 e.getX(), 98 e.getY()); 99 } 100 101 class ShowMenu extends JPopupMenu { 102 ShowMenu() { 103 String s = AJStackFrameNode.this.ms.getFullPath() + ":" + 105 AJStackFrameNode.this.ms.lineNumber; 106 JMenuItem item; 107 item = new JMenuItem("goto " + s); 108 item.addActionListener(new ActionListener() { 109 public void actionPerformed(ActionEvent e) { 110 ComponentRepository.getSourcePane(). 111 showSourceForFileAndLine 112 (AJStackFrameNode.this.ms.getFullPath(), 113 AJStackFrameNode.this.ms.lineNumber); 114 } 115 }); 116 add(item); 117 Iterator iter = 118 ComponentRepository.getAJDebugger(). 119 getBreakpointRequests().iterator(); 120 String cmd = " " + AJStackFrameNode.this.ms.getProto(); 121 boolean found = false; 122 while (iter.hasNext()) { 123 BreakpointRequestAction req = 124 (BreakpointRequestAction)iter.next(); 125 if (req.equals(AJStackFrameNode.this.ms)) { 126 found = true; 127 break; 128 } 129 } 130 final String msg = (found ? "clear" : "stop on") + cmd; 131 item = new JMenuItem(msg); 132 item.addActionListener(new ActionListener() { 133 public void actionPerformed(ActionEvent e) { 134 ComponentRepository.execute(msg); 135 } 136 }); 137 add(item); 138 } 139 } 140 141 static class NoShowMenu extends JPopupMenu { 142 NoShowMenu() { 143 add(new JMenuItem("Source is unavailable")); 144 } 145 } 146 147 148 154 162 public Value getValue(LocalVariable variable) { 163 return frame.getValue(variable); 164 } 165 166 174 public Map getValues(java.util.List variables) { 175 return frame.getValues(variables); 176 } 177 178 190 public Location location() { 191 return frame.location(); 192 } 193 194 201 public ObjectReference thisObject() { 202 return frame.thisObject(); 203 } 204 205 210 public ThreadReference thread() { 211 return frame.thread(); 212 } 213 214 225 public LocalVariable visibleVariableByName(String name) 226 throws AbsentInformationException { 227 return frame.visibleVariableByName(name); 228 } 229 230 257 public List visibleVariables() 258 throws AbsentInformationException { 259 return frame.visibleVariables(); 260 } 261 262 266 271 public StackFrame getStackFrame() { 272 return frame; 273 } 274 275 280 public int lineNumber() { 281 return this.location().lineNumber(); 282 } 283 284 291 public String sourceName() 292 throws AbsentInformationException { 293 return this.location().sourceName(); 294 } 295 296 301 public Method method() { 302 return this.location().method(); 303 } 304 305 310 public boolean isStackFrame() { 311 return true; 312 } 313 314 317 public boolean isValid() { 318 try { 319 frame.location(); 320 } catch (InvalidStackFrameException ie) { 321 return false; 322 } 323 return true; 324 } 325 326 public void showKids() { 327 try { 329 removeAllChildren(); 330 showThisObject(); 331 showLocalVariables(); 332 } catch (InvalidStackFrameException isfe) { 333 } 334 } 335 336 public void hideKids() { 337 this.removeAllChildren(); 338 } 339 340 343 private void showLocalVariables() { 344 try { 345 Iterator iter = visibleVariables().iterator(); 346 while (iter.hasNext()) { 347 LocalVariable local = (LocalVariable) iter.next(); 348 StackFrame frame = getStackFrame(); 349 AJValueNode valueNode = AJValueNodeFactory.make(local, frame); 350 this.add(valueNode); 352 } 353 } catch (AbsentInformationException aie) { 354 } catch (NativeMethodException nme) { 355 } 356 } 357 358 361 private void showThisObject() { 362 ObjectReference object = frame.thisObject(); 363 364 if (object == null) { 366 return; 367 } 368 AJValueNode valueNode = AJValueNodeFactory.make(object, "this"); 369 this.add(valueNode); 370 } 371 372 375 boolean sdb = false; 376 public String toString() { 377 String t = "thread="; 378 try { 379 t += System.identityHashCode(frame.thread()) + ""; 380 } catch (Exception e) { 381 t += "***" + System.identityHashCode(thread); 382 } 383 t += ": "; 384 385 return (sdb ? dd() + t : "") + 386 str; 387 } 388 389 393 public int getType() { 394 if (isValid()) { 395 return super.getType(); 396 } 397 398 DefaultMutableTreeNode parent = (DefaultMutableTreeNode)getParent(); 400 if (parent != null) { 401 parent.removeAllChildren(); 402 } 403 return AJIcons.INVALID_ICON; 404 } 405 406 409 public Location getOriginalLocation() { 410 return this.originalLocation; 411 } 412 413 419 public void setFrame(StackFrame frame) { 420 this.frame = frame; 423 setUserObject(frame); 424 originalLocation = frame.location(); ms = AJStackFrameFormatter.format(getStackFrame()); 426 str = ms + ""; 427 thread = frame.thread(); 428 showKids(); 432 } 433 } 434 | Popular Tags |