1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 import org.aspectj.debugger.request.*; 27 import org.aspectj.debugger.tty.*; 28 29 import com.sun.jdi.*; 30 import com.sun.jdi.request.*; 31 import com.sun.jdi.event.*; 32 import java.awt.event.*; 33 import java.util.*; 34 35 43 44 public class GUIDebugger extends CommandLineDebugger { 45 46 private final static String [] emptyArgs = new String [0]; 47 48 protected GUIDebugger() { 49 this(emptyArgs); 50 } 51 52 protected GUIDebugger(String [] args) { 53 super(args, false); 54 } 55 56 public GUIDebugger(ComponentDirector gui, String [] args) { 57 super(args, false); 58 setGui(gui); 59 } 60 61 public boolean isGUI() { 62 return true; 63 } 64 65 private ComponentDirector gui; 66 public ComponentDirector getGui() { 67 return gui; 68 } 69 public void setGui(ComponentDirector gui) { 70 this.gui = gui; 71 } 72 73 public String getClassNameToRun() { 74 return null; 75 } 76 77 public String getClasspath() { 78 return null; 79 } 80 81 public String getVMParameters() { 82 return null; 83 } 84 85 86 87 88 public void viewCommand(String sourceName, List sourceLines) 89 throws NoVMException, DebuggerException { 90 ComponentRepository.getSourcePane().showSource(sourceName); 91 } 92 93 public void whereCommand(String threadName, List frames) 94 throws NoVMException, DebuggerException { 95 if (frames == null || frames.size() == 0) return; 96 StackFrame frame = (StackFrame) frames.get(0); 97 if (frame == null) return; 98 expand(frame); 99 ComponentRepository.getSourcePane(). 100 showSourceForFrame(frame, false); 101 ThreadReference threadRef = getDebugger().getThread(threadName); 102 ComponentRepository.getStackTablePane(). 103 showForThread(threadRef); 104 } 105 106 public void localsCommand(List locals) 107 throws NoVMException, DebuggerException { 108 super.localsCommand(locals); 109 expandToLocals(); 110 } 111 112 public void printCommand(Object valueRep, Value value) 113 throws NoVMException, DebuggerException { 114 super.printCommand(valueRep, value); 115 expandToValue(value, valueRep); 116 } 117 118 public void dumpCommand(Object valueRep, Value value) 119 throws NoVMException, DebuggerException { 120 super.dumpCommand(valueRep, value); 121 expandToValue(value, valueRep); 122 } 123 124 public void evalCommand(Object valueRep, Value value) 125 throws NoVMException, DebuggerException { 126 super.evalCommand(valueRep, value); 127 expandToValue(value, valueRep); 128 } 129 130 public void listCommand(List sourceLines) 131 throws NoVMException, DebuggerException { 132 if (sourceLines.size() == 0) { 133 return; 134 } 135 SourceManager.SourceLine slFirst = 136 (SourceManager.SourceLine)sourceLines.get(0); 137 SourceManager.SourceLine slLast = 138 (SourceManager.SourceLine)sourceLines.get(sourceLines.size()-1); 139 String sourceName = slFirst.getSourceName(); 140 int first = slFirst.getLineNumber(); 141 int last = slLast.getLineNumber(); 142 if (first > 0 && last > 0) { 143 int middle = first; 144 ComponentRepository.getSourcePane(). 145 showSourceForFileAndLine(sourceName, middle); 146 } else { 147 ComponentRepository.getSourcePane(). 148 showSource(sourceName); 149 } 150 } 151 152 public void listCommand(String sourceName, List sourceLines) 153 throws NoVMException, DebuggerException { 154 listCommand(sourceLines); 155 } 156 157 public void listCommand(String sourceName, 158 int lineNumber, 159 SourceManager.SourceLine sl) 160 throws NoVMException, DebuggerException { 161 List sourceLines = new Vector(); 162 sourceLines.add(sl); 163 listCommand(sourceLines); 164 } 165 166 public void listCommand(String sourceName, 167 int startLine, 168 int endLine, 169 List sourceLines) 170 throws NoVMException, DebuggerException { 171 listCommand(sourceLines); 172 } 173 174 public void useCommand(String sourcePath, String newSourcePath) 175 throws NoVMException, DebuggerException { 176 super.useCommand(sourcePath, newSourcePath); 177 } 180 181 public void connectCommand(VirtualMachine vm) 182 throws NoVMException, DebuggerException { 183 if (vm != null) { 184 result("Connected to " + vm.name()); 185 } 186 } 187 188 private void expand(LocatableEvent e) { 189 try { 190 expand(e.thread().frame(0)); 191 } catch (IncompatibleThreadStateException itse) { 192 } 193 } 194 195 private void expand(StackFrame frame) { 196 ComponentRepository.getThreadGroupTreePane().expandToFrame(frame); 197 } 200 201 private void expandToLocals() { 202 try { 203 ComponentRepository.getThreadGroupTreePane(). 204 expandToLocals(getDebugger().getDefaultFrame()); 205 } catch (NoVMException nvme) { 206 } 207 } 208 209 private void expandToValue(Value value, Object valueRep) { 210 ComponentRepository.getThreadGroupTreePane(). 211 expandToValue(value, valueRep + ""); 212 } 213 214 public boolean wantsToExit() { 215 return false; 216 } 217 218 public void exit() { 219 gui.shutDown(); 220 debugger.shutDown(); 221 super.exit(); 222 } 223 224 public boolean canRestart() { 225 return true; 226 } 227 228 public static String d() { return "GUI Debugger"; } 229 public String toString() { return d(); } 230 231 public VirtualMachine connect(String vmArgs, 232 String className, 233 String commandLine) { 234 return ConnectFrame.vm(this, vmArgs, className, commandLine); 235 } 236 } 237 | Popular Tags |