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 java.util.*; 30 31 39 40 public abstract class EventRequestWrapper { 41 42 43 protected Debugger debugger; 44 45 public EventRequestWrapper(Debugger debugger) { 46 this.debugger = debugger; 47 } 48 49 56 public abstract EventRequest resolve(ReferenceType refType); 57 58 protected VirtualMachine vm() throws NoVMException { 59 return debugger.getVM(); 60 } 61 } 62 63 class ClassLineBreakpointRequestWrapper extends EventRequestWrapper { 64 65 66 private String className; 67 68 69 private int line; 70 71 ClassLineBreakpointRequestWrapper(Debugger debugger, String className, int line) { 72 super(debugger); 73 this.className = className; 74 this.line = line; 75 } 76 77 public EventRequest resolve(ReferenceType refType) { 78 BreakpointRequest request = null; 79 try { 80 if (refType.name().equals(className)) { 81 EventRequestManager em = vm().eventRequestManager(); 82 Location location = findLocation(); 83 if (location == null) { 84 return null; 85 } 86 request = em.createBreakpointRequest(location); 87 request.enable(); 88 request.setSuspendPolicy(EventRequest.SUSPEND_NONE); } 90 } catch (NoVMException e) { 91 } 92 return request; 93 } 94 95 public String toString() { 96 return "breakpoint " + className + ":" + line; 97 } 98 99 private Location findLocation() throws NoVMException { 100 Location location = null; 101 Iterator iter = vm().classesByName(className).iterator(); 102 while (iter.hasNext()) { 103 ReferenceType refType = (ReferenceType) iter.next(); 104 if (refType.name().equals(className)) { 105 try { 106 Iterator linesIter = refType.locationsOfLine(line).iterator(); 107 while (linesIter.hasNext()) { 108 return (Location) linesIter.next(); 109 } 110 } catch (AbsentInformationException e) { 111 return null; 112 } 113 } 114 } 115 return location; 116 } 117 } 118 | Popular Tags |