1 33 34 package edu.rice.cs.drjava.model.debug; 35 36 import edu.rice.cs.drjava.model.DocumentRegion; 37 import edu.rice.cs.util.UnexpectedException; 38 import edu.rice.cs.drjava.model.OpenDefinitionsDocument; 39 40 import java.util.Vector ; 41 import java.util.List ; 42 43 import javax.swing.text.BadLocationException ; 44 import javax.swing.text.Position ; 45 46 import com.sun.jdi.*; 47 import com.sun.jdi.request.*; 48 49 import java.io.*; 50 51 52 public class Breakpoint extends DocumentDebugAction<BreakpointRequest> implements DebugBreakpointData, DocumentRegion { 53 54 private volatile Position _startPos; 55 private volatile Position _endPos; 56 57 58 public Breakpoint(OpenDefinitionsDocument doc, int offset, int lineNumber, boolean isEnabled, JPDADebugger manager) 59 throws DebugException { 60 61 super(manager, doc, offset); 62 _suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD; 63 _lineNumber = lineNumber; 64 _isEnabled = isEnabled; 65 66 try { 67 _startPos = doc.createPosition(doc.getLineStartPos(offset)); 68 _endPos = doc.createPosition(doc.getLineEndPos(offset)); 69 } 70 catch (BadLocationException ble) { 71 throw new UnexpectedException(ble); 72 } 73 74 if ((_manager != null) && (_manager.isReady())) { 75 Vector <ReferenceType> refTypes = _manager.getReferenceTypes(_className, _lineNumber); 78 _initializeRequests(refTypes); 79 setEnabled(isEnabled); 80 } 81 } 82 83 89 protected void _createRequests(Vector <ReferenceType> refTypes) throws DebugException { 90 try { 91 for (int i=0; i < refTypes.size(); i++) { 92 ReferenceType rt = refTypes.get(i); 93 94 if (!rt.isPrepared()) { 95 continue; 97 } 98 99 List lines = rt.locationsOfLine(_lineNumber); 101 if (lines.size() == 0) { 102 setEnabled(false); 104 throw new DebugException("Could not find line number: " + _lineNumber); 105 } 106 Location loc = (Location) lines.get(0); 107 108 BreakpointRequest request = _manager.getEventRequestManager().createBreakpointRequest(loc); 109 request.setEnabled(_isEnabled); 110 _requests.add(request); 111 } 112 } 113 catch (AbsentInformationException aie) { 114 throw new DebugException("Could not find line number: " + aie); 115 } 116 } 117 118 122 public int getStartOffset() { 123 return _startPos.getOffset(); 124 } 125 126 129 public int getEndOffset() { 130 return _endPos.getOffset(); 131 } 132 133 134 public void setEnabled(boolean isEnabled) { 135 boolean old = _isEnabled; 136 super.setEnabled(isEnabled); 137 try { 138 for(BreakpointRequest bpr: _requests) { 139 bpr.setEnabled(isEnabled); 140 } 141 } 142 catch(VMDisconnectedException vmde) { } 143 if (_isEnabled!=old) _manager.notifyBreakpointChange(this); 144 } 145 146 public String toString() { 147 String cn = getClassName(); 148 if (_exactClassName!=null) { cn = _exactClassName.replace('$', '.'); } 149 if (_requests.size() > 0) { 150 return "Breakpoint[class: " + cn + 153 ", lineNumber: " + getLineNumber() + 154 ", method: " + _requests.get(0).location().method() + 155 ", codeIndex: " + _requests.get(0).location().codeIndex() + 156 ", numRefTypes: " + _requests.size() + "]"; 157 } 158 else { 159 return "Breakpoint[class: " + cn + 160 ", lineNumber: " + getLineNumber() + "]"; 161 } 162 } 163 } 164 | Popular Tags |