1 7 34 35 package com.sun.tools.example.debug.bdi; 36 37 import com.sun.jdi.*; 38 import com.sun.jdi.request.*; 39 40 import java.util.ArrayList ; 41 import java.util.List ; 42 import java.util.Iterator ; 43 44 public class LineBreakpointSpec extends BreakpointSpec { 45 int lineNumber; 46 47 LineBreakpointSpec(EventRequestSpecList specs, 48 ReferenceTypeSpec refSpec, int lineNumber) { 49 super(specs, refSpec); 50 this.lineNumber = lineNumber; 51 } 52 53 56 void resolve(ReferenceType refType) throws InvalidTypeException, 57 LineNotFoundException { 58 if (!(refType instanceof ClassType)) { 59 throw new InvalidTypeException(); 60 } 61 Location location = location((ClassType)refType); 62 setRequest(refType.virtualMachine().eventRequestManager() 63 .createBreakpointRequest(location)); 64 } 65 66 private Location location(ClassType clazz) throws 67 LineNotFoundException { 68 Location location = null; 69 try { 70 List locs = clazz.locationsOfLine(lineNumber()); 71 if (locs.size() == 0) { 72 throw new LineNotFoundException(); 73 } 74 location = (Location)locs.get(0); 76 if (location.method() == null) { 77 throw new LineNotFoundException(); 78 } 79 } catch (AbsentInformationException e) { 80 84 throw new LineNotFoundException(); 85 } 86 return location; 87 } 88 89 public int lineNumber() { 90 return lineNumber; 91 } 92 93 public int hashCode() { 94 return refSpec.hashCode() + lineNumber; 95 } 96 97 public boolean equals(Object obj) { 98 if (obj instanceof LineBreakpointSpec) { 99 LineBreakpointSpec breakpoint = (LineBreakpointSpec)obj; 100 101 return refSpec.equals(breakpoint.refSpec) && 102 (lineNumber == breakpoint.lineNumber); 103 } else { 104 return false; 105 } 106 } 107 108 public String errorMessageFor(Exception e) { 109 if (e instanceof LineNotFoundException) { 110 return ("No code at line " + lineNumber() + " in " + refSpec); 111 } else if (e instanceof InvalidTypeException) { 112 return ("Breakpoints can be located only in classes. " + 113 refSpec + " is an interface or array"); 114 } else { 115 return super.errorMessageFor( e); 116 } 117 } 118 119 public String toString() { 120 StringBuffer buffer = new StringBuffer ("breakpoint "); 121 buffer.append(refSpec.toString()); 122 buffer.append(':'); 123 buffer.append(lineNumber); 124 buffer.append(" ("); 125 buffer.append(getStatusString()); 126 buffer.append(')'); 127 return buffer.toString(); 128 } 129 } 130 | Popular Tags |