1 22 23 package org.aspectj.debugger.request; 24 25 import org.aspectj.debugger.base.*; 26 27 import com.sun.jdi.*; 28 import com.sun.jdi.request.*; 29 import com.sun.jdi.event.*; 30 import org.aspectj.tools.ide.SourceLine; 31 import java.io.*; 32 import java.util.*; 33 34 42 43 public abstract class SourceLineBreakpointRequestAction 44 extends BreakpointRequestAction { 45 46 protected String sourceName; 47 protected int line; 48 49 public SourceLineBreakpointRequestAction(Debugger debugger, 50 String sourceName, int line) { 51 super(debugger); 52 System.err.println(">> source line request: " + sourceName + " : " + line); 53 this.sourceName = ensureDriveIsUpperCase(sourceName); 54 this.line = line; 55 } 56 57 EventRequest resolve(ReferenceType refType) throws MultipleLocationsException, 58 UnableToSetRequestException { 59 BreakpointRequest request = null; 60 try { 61 String refTypeSourceName = refType.sourceName(); 62 String strippedName = ajdbg().strip(getSourceName()); 63 if (refTypeSourceName.equals(strippedName)) { 64 EventRequestManager em = vm().eventRequestManager(); 65 Location location = findLocation(refType); 66 if (location == null) { 67 return null; 68 } 69 request = request(location); 70 } 71 } catch (NoVMException e) { 72 } catch (AbsentInformationException aie) { 73 } 74 return request; 75 } 76 77 81 private String ensureDriveIsUpperCase(String sourceName) { 82 try { 83 if (Character.isLetter(sourceName.charAt(0)) && 84 sourceName.charAt(1) == ':' && 85 isFileSeparator(sourceName.charAt(2))) { 86 return Character.toUpperCase(sourceName.charAt(0)) + 87 sourceName.substring(1); 88 } 89 } catch (ArrayIndexOutOfBoundsException aoobe) { 90 } 91 return sourceName; 92 } 93 94 private boolean isFileSeparator(char c) { 95 return c == File.separatorChar || c == '/' || c == '\\'; 96 } 97 98 private Location findLocation(ReferenceType refType) 99 throws MultipleLocationsException, 100 UnableToSetRequestException { 101 Location location = null; 102 try { 103 List lines = refType.locationsOfLine(line); 104 if (lines == null || lines.size() == 0) { 105 106 110 return null; 112 } 113 location = (Location) lines.get(0); 114 } catch (AbsentInformationException aie) { 115 ajdbg().exception("Unable to set " + this + " : No code at line " + 116 line + " in " + refType.name(), aie); 117 } catch (ClassNotPreparedException cpe) { 118 ajdbg().classNotPreparedException(cpe, refType.name()); 119 } catch (ObjectCollectedException oce) { 120 ajdbg().objectCollectedException(oce, refType.name()); 121 } catch (InvalidLineNumberException ilne){ 122 ajdbg().invalidLineNumberException(ilne, refType.name(), line); 123 } 124 return location; 125 } 126 127 public int getLine() { 128 return line; 129 } 130 131 public String getSourceName() { 132 return sourceName; 133 } 134 135 public int getRealLine() { 136 SourceLine sl = sourceLine(); 137 if (sl == null || sl.line < 0) { 138 return super.getRealLine(); 139 } 140 return sl.line; 141 } 142 143 public String getRealSourceName() { 144 SourceLine sl = sourceLine(); 145 if (sl == null) { 146 return super.getRealSourceName(); 147 } 148 return sl.filename; 149 } 150 151 public SourceLine sourceLine() { 152 return ajdbg().getSourceLineFromSource(getSourceName(), getLine()); 153 } 154 155 public String getProto() { 156 SourceLine sl = ajdbg().getSourceLineFromSource(getSourceName(), getLine()); 157 String newSource = "<source-unkown>"; 158 if (sl != null) { 159 newSource = ajdbg().strip(ajdbg().removeFullWorkingDir(sl.filename)); 160 } else { 161 System.out.println("sl is NULL: " + sourceName + ":" + getLine()); 162 } 163 return newSource + ":" + sl.line; 164 } 165 166 public boolean equals(Object other) { 167 if (other == null || !(other instanceof SourceLineBreakpointRequestAction)) { 168 return super.equals(other); 169 } 170 SourceLineBreakpointRequestAction ba = (SourceLineBreakpointRequestAction) other; 171 return (getSourceName().equals(ba.getSourceName()) && 172 getLine() == ba.getLine()); 173 } 177 178 public String getErrorMessage() { 179 SourceLine sl = ajdbg().getSourceLineFromSource(getSourceName(), getLine()); 180 String newSourceName = getSourceName(); 181 int newLine = getLine(); 182 if (sl != null) { 183 newSourceName = ajdbg().removeSourcePath(sl.filename); 184 newLine = sl.line; 185 } 186 return "No code at line " + newLine + " in file " + newSourceName; 187 } 188 } 189 | Popular Tags |