1 24 package org.aspectj.debugger.ide; 25 26 import org.aspectj.debugger.base.*; 27 import org.aspectj.debugger.gui.*; 28 import org.aspectj.debugger.request.*; 29 import org.aspectj.tools.ide.SourceLine; 30 import java.util.List ; 31 import javax.swing.JComponent ; 32 33 import javax.swing.*; 35 36 public abstract class IDEInterfaceHelper implements IDEInterface { 37 38 42 43 public abstract String getClasspath(); 44 public abstract String getVMParameters(); 45 public abstract String getClassNameToRun(); 46 public abstract String findClassName(); 47 public abstract String findFileName(); 48 public abstract List getInitialBreakpoints(); 49 50 protected abstract void markLine(String className, List argumentTypeNames); 51 protected abstract void markLineWithClass(String className, int line); 52 protected abstract void markLine(String sourceName, int line); 53 protected abstract void unmarkLine(String sourceName, int line); 54 55 public void toggle(String sourceName, int lineNumber) {} 56 57 58 public static IDEInterfaceHelper singletonInstance = null; 59 61 62 protected abstract void handle(Throwable t); 63 64 67 public void toggleBreakpoint(String sourcePath, int lineNumber) { 68 this.ajdb().toggleBreakpoint(sourcePath, lineNumber); 69 } 70 71 72 76 77 82 public void exit() {} 83 84 89 public void init(IDEComponentDirector director) {} 90 91 94 public void settingBreakpointsFromIDE() { 95 downSettingFromDebugger(); 96 } 97 98 101 public void doneSettingBreakpointsFromIDE() { 102 upSettingFromDebugger(); 103 } 104 105 106 110 111 protected ComponentDirector director; 112 public void setComponentDirector(ComponentDirector director) { 113 this.director = director; 114 init(director); 115 } 116 117 118 122 123 public ComponentDirector getComponentDirector() { 124 return director; 125 } 126 127 public AJDebugger ajdb() { 128 GUIDebugger guid = guid(); 129 return guid != null ? (AJDebugger)guid.getDebugger() : null; 130 } 131 132 public GUIDebugger guid() { 133 return director != null ? director.getGUIDebugger() : null; 134 } 135 136 public void init(ComponentDirector _director) { 137 director = _director; 138 director.getDebugger().addDebuggerListener(new RequestListener()); 139 } 140 141 final class RequestListener implements DebuggerListener { 142 public void requestSetEvent(RequestEvent re) { 143 debug("requestSetEvent:" + re); 144 set(re); 145 } 146 public void requestClearEvent(RequestEvent re) { 147 debug("requestClearEvent:" + re); 148 clear(re); 149 } 150 public void requestDeferredEvent(RequestEvent re) { 151 debug("requestDeferredEvent:" + re); 152 set(re); 153 } 154 public void requestFailedEvent(RequestEvent re) { 155 debug("requestFailedEvent:" + re); 156 clear(re); 157 } 158 private void set(RequestEvent re) { 159 if (!downSettingFromDebugger()) return; 160 markLine(re); 161 upSettingFromDebugger(); 162 } 163 private void clear(RequestEvent re) { 164 if (!downSettingFromDebugger()) return; 165 unmarkLine(re); 166 upSettingFromDebugger(); 167 } 168 } 169 170 private boolean settingFromIDE = false; 172 protected boolean downSettingFromIDE() { 173 return settingFromIDE ? false : (settingFromIDE = true); 174 } 175 protected void upSettingFromIDE() { 176 settingFromIDE = false; 177 } 178 private boolean settingFromDebugger = false; 179 protected boolean downSettingFromDebugger() { 180 return settingFromDebugger ? false : (settingFromDebugger = true); 181 } 182 protected void upSettingFromDebugger() { 183 settingFromDebugger = false; 184 } 185 186 protected final boolean breakpoint 187 (IDEInterface.AbstractSourceLineBreakpoint breakpoint, 188 boolean stopping) { 189 return breakpoint(breakpoint.getSourceName(), 190 breakpoint.getLine(), 191 stopping); 192 } 193 194 protected final boolean breakpoint(String sourceName, 195 int line, 196 boolean stopping) { 197 try { 198 if (!downSettingFromDebugger()) { 199 return false; 200 } 201 if (stopping) { 202 debug("stopping " + sourceName + ":" + line); 203 director.getDebugger().stopOnCommand(sourceName, line); 204 } else { 205 debug("clearing " + sourceName + ":" + line); 206 director.getDebugger().clearOnCommand(sourceName, line); 207 } 208 } catch (Exception t) { 209 handle(t); 210 } finally { 211 upSettingFromDebugger(); 212 } 213 return true; 214 } 215 216 private void unmarkLine(RequestEvent re) { 217 Request request = re.getRequest(); 218 219 debug("request:" + request); 220 221 if (request == null) { 222 return; 223 } 224 225 String sourceName; 226 int line; 227 228 if (request instanceof BreakpointRequestAction) { 229 BreakpointRequestAction bra = 230 (BreakpointRequestAction)request; 231 sourceName = bra.getRealSourceName(); 232 line = bra.getRealLine(); 233 if (ajdb().isAjcFile(sourceName)) { 234 SourceLine sourceLine = ajdb().getSourceLine(bra); 235 sourceName = ajdb().getFullSourcePath(bra.getRealSourceName()); 236 debug("*** unmarking.real:" + sourceName + ":" + line); 237 debug("*** but sourceLine:" + sourceLine); 238 debug("*** bra:" + bra + ",bra.class:" + bra.getClass()); 239 downSettingFromIDE(); 240 unmarkLine(sourceLine.filename, sourceLine.line); 242 upSettingFromIDE(); 243 244 return; 245 } 246 } 247 } 248 249 public final void atomicMarkLine(String sourceFilename, 250 int lineNumber) { 251 downSettingFromIDE(); 252 markLine(sourceFilename, lineNumber); 253 upSettingFromIDE(); 254 } 255 256 private final void markLine(RequestEvent re) { 257 Request request = re.getRequest(); 258 259 debug("request:" + request); 260 261 if (request == null) { 262 return; 263 } 264 265 String sourceName; 266 int line; 267 268 if (request instanceof BreakpointRequestAction) { 269 BreakpointRequestAction bra = (BreakpointRequestAction)request; 270 sourceName = bra.getRealSourceName(); 271 debug("sourceName:" + sourceName); 272 line = bra.getRealLine(); 273 if (ajdb().isAjcFile(sourceName)) { 274 SourceLine sourceLine = ajdb().getSourceLine(bra); 275 sourceName = ajdb().getFullSourcePath(bra.getRealSourceName()); 276 debug("*** marking sourceLine:" + sourceLine + " " + 277 sourceName + ":" + line + "," + 278 bra.getLine() + ",class:" + 279 bra.getClass().getName()); 280 downSettingFromIDE(); 282 markLine(sourceLine.filename, sourceLine.line); 283 upSettingFromIDE(); 284 return; 285 } 286 } 287 288 if (request instanceof SourceLineBreakpointRequestAction) { 289 SourceLineBreakpointRequestAction ra = 290 (SourceLineBreakpointRequestAction)request; 291 SourceLine sl = ajdb().getSourceLine(ra); 292 downSettingFromIDE(); 293 markLine(sl.filename, sl.line); 294 upSettingFromIDE(); 295 } else if (request instanceof ClassLineBreakpointRequestAction) { 296 ClassLineBreakpointRequestAction ra = 297 (ClassLineBreakpointRequestAction)request; 298 String className = ra.getClassName(); 299 line = ra.getLine(); 300 downSettingFromIDE(); 301 markLineWithClass(className, line); 302 upSettingFromIDE(); 303 } else if (request instanceof ClassMethodBreakpointRequestAction) { 304 ClassMethodBreakpointRequestAction ra = 305 (ClassMethodBreakpointRequestAction)request; 306 String methodProto = ra.getMethodProto(); 307 List argNames = ra.getArgumentTypeNames(); 308 String className = ra.getClassName(); 309 downSettingFromIDE(); 310 markLine(className, argNames); 311 upSettingFromIDE(); 312 } else if (request instanceof BreakpointRequestAction) { 313 BreakpointRequestAction ra = 314 (BreakpointRequestAction)request; 315 SourceLine sl = ajdb().getSourceLine(ra); 316 downSettingFromIDE(); 317 markLine(sl.filename, sl.line); 318 upSettingFromIDE(); 319 } 320 321 sourceName = "asdf"; 322 line = -123; 323 if (request instanceof BreakpointRequestAction) { 324 BreakpointRequestAction bra = 325 (BreakpointRequestAction)request; 326 sourceName = bra.getSourceName(); 327 line = bra.getLine(); 328 } 329 debug("sourceName:" + sourceName + " line:" + line); 330 } 331 332 public final static Log log = new Log(); 333 public static void debug(Object msg) { 334 log.println(msg); 335 } 336 public static class Log { 337 private JTextArea area = new JTextArea(30,100); 338 private boolean ok = false; 339 public void up() { 340 if (!ok) return; 341 println("up"); 342 area.setForeground(java.awt.Color.black); 343 } 344 public void down() { 345 if (!ok) return; 346 println("down"); 347 area.setForeground(java.awt.Color.red.darker()); 348 } 349 { 350 JFrame frame = new JFrame("IDE Logger"); 351 if ((ok = 352 System.getProperty("user.name").equals("palm") && 353 System.getProperty("no.logger") != null)) { 354 frame.getContentPane().add(new JScrollPane(area)); 355 frame.pack(); 356 frame.setVisible(true); 357 } 358 } 359 public void println() { 360 println(""); 361 } 362 public void println(Object msg) { 363 if (ok) area.append(msg + "\n"); 364 } 365 } 366 } 367 | Popular Tags |