1 33 34 package edu.rice.cs.drjava.model.debug; 35 36 import com.sun.jdi.*; 37 import com.sun.jdi.request.*; 38 39 import java.util.Vector ; 40 import java.util.List ; 41 import java.io.File ; 42 43 import edu.rice.cs.drjava.model.*; 44 import edu.rice.cs.drjava.model.definitions.ClassNameNotFoundException; 45 import javax.swing.text.BadLocationException ; 46 47 50 public abstract class DocumentDebugAction<T extends EventRequest> extends DebugAction<T> { 51 52 protected volatile String _className; 53 protected volatile String _exactClassName; 54 protected volatile File _file; 55 protected volatile OpenDefinitionsDocument _doc; 56 protected int _offset; 57 58 59 66 public DocumentDebugAction (JPDADebugger manager, OpenDefinitionsDocument doc, int offset) throws DebugException { 67 super(manager); 68 _exactClassName = null; 69 try { 70 if (offset >= 0) { 71 if (doc.getNumberOfLines() < 500) { 72 _exactClassName = doc.getEnclosingClassName(offset, true); 75 } 76 } 77 } 78 catch(ClassNameNotFoundException cnnfe) { } 79 catch(BadLocationException ble) { } 80 try { 81 if (offset >= 0) { 82 _className = doc.getQualifiedClassName(offset); 83 } 84 } 85 catch (ClassNameNotFoundException cnnfe) { 86 _className = ""; 88 } 89 91 try { 92 _file = doc.getFile(); 93 if (_file == null) throw new DebugException("This document has no source file."); 94 } 95 catch (FileMovedException fme) { 96 throw new DebugException("This document's file no longer exists: " + fme.getMessage()); 97 } 98 _doc = doc; 99 _offset = offset; 100 } 101 102 103 public String getClassName() { return _className; } 104 105 106 public File getFile() { return _file; } 107 108 109 public OpenDefinitionsDocument getDocument() { return _doc; } 110 111 112 public int getOffset() { return _offset; } 113 114 115 public String getExactClassName() { return _exactClassName; } 116 117 122 public boolean createRequests(Vector <ReferenceType> refTypes) throws DebugException { 123 _createRequests(refTypes); 124 if (_requests.size() > 0) { 125 _prepareRequests(_requests); 126 return true; 127 } 128 else return false; 129 } 130 131 135 protected void _initializeRequests(Vector <ReferenceType> refTypes) throws DebugException { 136 if (refTypes.size() > 0) createRequests(refTypes); 137 else { 138 if (_exactClassName!=null) { 139 List <ReferenceType> referenceTypes = _manager.getVM().classesByName(_exactClassName); 140 if (referenceTypes.size()>0) { 141 throw new LineNotExecutableException("Cannot set breakpoint, line "+getLineNumber()+" is not an executable line."); 143 } 144 } 145 } 146 149 _manager.getPendingRequestManager().addPendingRequest(this); 151 } 153 154 159 protected abstract void _createRequests(Vector <ReferenceType> refTypes) throws DebugException; 160 161 164 protected void _prepareRequest(T request) { 165 super._prepareRequest(request); 166 request.putProperty("document", _doc); 167 } 168 } 169 | Popular Tags |