1 22 23 package org.aspectj.debugger.gui; 24 25 import com.sun.jdi.*; 26 import com.sun.jdi.event.*; 27 import org.aspectj.debugger.base.*; 28 import org.aspectj.debugger.request.*; 29 import org.aspectj.tools.ide.*; 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.io.*; 33 import java.util.*; 34 import java.util.List ; 35 import javax.swing.*; 36 37 43 public abstract class AbstractSourcePane 44 extends AJPanel 45 implements DebuggerListener, 46 VMListener, 47 StopListener { 48 49 protected ComponentDirector director; 50 51 public AbstractSourcePane(GUIDebugger guid) { 52 super(guid); 53 debugger().addDebuggerListener(this); 54 debugger().addVMListener(this); 55 debugger().addStopListener(this); 56 this.director = guid.getGui(); 57 } 58 59 64 public abstract boolean showSource(String relativePath); 65 66 73 public abstract void showLineForCurrentModel(int line, boolean isAtBreakpoint); 74 75 80 public abstract String getSourceName(); 81 82 93 public abstract void requestSet(String filename, int line, 94 BreakpointRequestAction ba); 95 96 107 public abstract void requestClear(String filename, int line, 108 BreakpointRequestAction ba); 109 110 121 public abstract void requestDeferred(String filename, int line, 122 BreakpointRequestAction ba); 123 124 125 127 133 public boolean fileExists(String relativePath) { 134 String fullPath = debugger().getFullSourcePath(relativePath); 135 File file = new File(fullPath); 136 if (file != null && file.exists()) { 137 return true; 138 } 139 return false; 140 } 141 142 public String getSourcePath() { 143 return debugger().getSourceManager().getSourcePath(); 144 } 145 146 public SourceManager getSourceManager() { 147 return debugger.getSourceManager(); 148 } 149 150 public void showSourceForFrame(StackFrame frame, boolean isAtBreakpoint) { 151 try { 152 showSourceForLocation(frame.location(), isAtBreakpoint); 153 } catch (InvalidStackFrameException isfe) { 154 } 155 } 156 157 public void showSourceForLocation(Location loc, boolean isAtBreakpoint) { 158 SourceLine sl = null; 159 try { 160 sl = debugger().sourceLine(loc); 161 } catch (AbsentInformationException aie) { 162 return; 163 } 164 if (sl == null) { 165 return; 166 } 167 if (sl.line < 0) { 168 return; 169 } 170 if (fileExists(sl.filename)) { 171 if (showSource(sl.filename)) { 172 showLineForCurrentModel(sl.line, isAtBreakpoint); 173 } 174 } 175 director.makeTopLevel(); 176 } 177 178 public void showSourceForLocation(Location loc) { 179 showSourceForLocation(loc, false); 180 } 181 182 public void showSourceForFileAndLine(String relativePath, int line) { 183 if (line < 0) { 184 return; 185 } 186 if (!(new File(relativePath).exists()) && 187 !(new File(AJLineMapper.removeRoot(relativePath)).exists())) { 188 return; 189 } 190 if (fileExists(relativePath)) { 191 if (showSource(relativePath)) { 192 showLineForCurrentModel(line); 193 } 194 } 195 director.makeTopLevel(); 196 } 197 198 protected void showLineForCurrentModel(int line) { 199 showLineForCurrentModel(line, false); 200 } 201 202 public File getPath() { 203 return new File(getSourceName()); 204 } 205 206 207 208 public void requestSetEvent(RequestEvent re) { 209 Request request = re.getRequest(); 210 if (request instanceof BreakpointRequestAction) { 211 BreakpointRequestAction ba = (BreakpointRequestAction) request; 212 SourceLine sl = debugger().getSourceLine(ba); 213 requestSet(sl.filename, sl.line, ba); 214 } 215 } 216 public void requestClearEvent(RequestEvent re) { 217 Request request = re.getRequest(); 218 if (request instanceof BreakpointRequestAction) { 219 BreakpointRequestAction ba = (BreakpointRequestAction) request; 220 SourceLine sl = debugger().getSourceLine(ba); 221 requestClear(sl.filename, sl.line, ba); 222 } 223 } 224 public void requestDeferredEvent(RequestEvent re) { 225 Request request = re.getRequest(); 226 if (request instanceof BreakpointRequestAction) { 227 BreakpointRequestAction ba = (BreakpointRequestAction) request; 228 SourceLine sl = debugger().getSourceLine(ba); 229 requestDeferred(sl.filename, sl.line, ba); 230 } 231 } 232 public void requestFailedEvent(RequestEvent re) { 233 } 234 235 236 237 public void vmStartEvent(VMStartEvent e) { 238 } 239 public void vmDeathEvent(VMDeathEvent e) { 240 } 241 public void vmDisconnectEvent(VMDisconnectEvent e) { 242 } 243 244 245 public void accessWatchpointEvent(AccessWatchpointEvent e) { 246 showSourceForLocation(e.location()); 247 } 248 public void breakpointEvent(BreakpointEvent e) { 249 showSourceForLocation(e.location()); 250 } 251 public void exceptionEvent(ExceptionEvent e) { 252 showSourceForLocation(e.location()); 253 } 254 public void modificationWatchpointEvent(ModificationWatchpointEvent e) { 255 showSourceForLocation(e.location()); 256 } 257 public void stepEvent(StepEvent e) { 258 showSourceForLocation(e.location()); 259 } 260 261 public static String d() { return "Source Pane"; } 262 public String toString() { return d(); } 263 264 265 } 266 | Popular Tags |