1 22 23 package org.aspectj.debugger.request; 24 25 import org.aspectj.debugger.base.*; 26 27 import com.sun.jdi.*; 28 import java.util.*; 29 30 38 39 public class ListRequest extends Request { 40 41 private String sourceName = null; 42 private int startLineNumber = -1; 43 private int endLineNumber = -1; 44 45 public ListRequest(Debugger debugger) { 46 this(debugger, null, -1, -1); 47 } 48 49 public ListRequest(Debugger debugger, String sourceName) { 50 this(debugger, sourceName, -1, -1); 51 } 52 53 public ListRequest(Debugger debugger, String sourceName, int startLineNumber) { 54 this(debugger, sourceName, startLineNumber, -1); 55 } 56 57 public ListRequest(Debugger debugger, String sourceName, int startLineNumber, int endLineNumber) { 58 super(debugger); 59 this.sourceName = sourceName; 60 this.startLineNumber = startLineNumber; 61 this.endLineNumber = endLineNumber; 62 } 63 64 private SourceAndLines empty(String sourceName) { 65 Vector v = new Vector(); 66 v.add(ajdbg().emptySourceLine()); 67 return new SourceAndLines(sourceName, v); 68 } 69 70 public static class SourceAndLines { 71 private String sourceName; 72 public String getSourceName() { return sourceName; } 73 private List lines; 74 public List getLines() { return lines; } 75 public SourceAndLines(String sourceName, List lines) { 76 this.sourceName = sourceName; 77 this.lines = lines; 78 } 79 public String toString() { 80 return sourceName + ":" + lines; 81 } 82 } 83 84 public Object go() throws NoVMException, DebuggerException { 85 SourceManager sm = debugger.getSourceManager(); 86 if (sourceName == null) { 87 try { 88 StackFrame frame = dbg().getDefaultFrame(); 89 if (frame == null) { 90 return empty(sn()); 91 } 92 int line = ajdbg().lineNumber(frame.location()); 93 int start = line; 94 int end = line; 95 if (line > 0) { 96 for (int i = 0; i < 4; i++) { 97 end++; 98 if (start > 1) { 99 start--; 100 } 101 } 102 sourceName = ajdbg().sourceName(frame.location()); 103 if (sourceName == null) { 104 return empty(sn()); 105 } 106 } 107 startLineNumber = start; 108 endLineNumber = end + 2; 109 } catch (AbsentInformationException aie) { 110 return empty(sn()); 111 } 112 } 113 if (startLineNumber == -1) { 114 return sal(sm.getSourceLines(sourceName)); 115 } else if (endLineNumber == -1) { 116 return sal(sm.getSourceLine(sourceName, startLineNumber-1)); 117 } else { 118 return sal(sm.getSourceLines(sourceName, startLineNumber-1, endLineNumber)); 119 } 120 } 121 122 private String sn() { 123 return sourceName == null ? "<not found>" : sourceName; 124 } 125 126 private SourceAndLines sal(SourceManager.SourceLine line) { 127 List lines = new Vector(); 128 lines.add(line); 129 return sal(lines); 130 } 131 132 private SourceAndLines sal(List lines) { 133 return new SourceAndLines(sourceName, lines); 134 } 135 } 136 | Popular Tags |