1 33 34 package edu.rice.cs.drjava.model.debug; 35 36 import com.sun.jdi.*; 37 import com.sun.jdi.request.*; 38 import com.sun.jdi.event.*; 39 40 import java.util.Hashtable ; 41 import java.util.List ; 42 import java.util.Vector ; 43 44 import java.io.*; 45 46 50 51 public class PendingRequestManager { 52 private JPDADebugger _manager; 53 private Hashtable <String , Vector <DocumentDebugAction<?>>> _pendingActions; 54 55 public PendingRequestManager(JPDADebugger manager) { 56 _manager = manager; 57 _pendingActions = new Hashtable <String , Vector <DocumentDebugAction<?>>>(); 58 } 59 60 63 public void addPendingRequest (DocumentDebugAction<?> action) { 64 String className = action.getClassName(); 65 Vector <DocumentDebugAction<?>> actions = _pendingActions.get(className); 66 if (actions == null) { 67 actions = new Vector <DocumentDebugAction<?>>(); 68 69 ClassPrepareRequest request = 71 _manager.getEventRequestManager().createClassPrepareRequest(); 72 request.addClassFilter(className + "*"); 74 request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); 75 request.enable(); 76 } 78 actions.add(action); 79 _pendingActions.put(className, actions); 80 } 81 82 86 public void removePendingRequest (DocumentDebugAction<?> action) { 87 String className = action.getClassName(); 88 Vector <DocumentDebugAction<?>> actions = _pendingActions.get(className); 89 if (actions == null) { 90 return; 91 } 92 actions.remove(action); 93 if (actions.size() == 0) { 95 _pendingActions.remove(className); 96 } 97 } 98 99 104 private boolean recursiveFindLineNumber(int lineNumber, ReferenceType rt) { 105 try { 106 for(Location l: rt.allLineLocations()) { 107 if (l.lineNumber()==lineNumber) { return true; } 108 } 109 for(ReferenceType nested: rt.nestedTypes()) { 110 if (recursiveFindLineNumber(lineNumber, nested)==true) { return true; } 111 } 112 } 113 catch (AbsentInformationException aie) { 114 } 116 117 return false; 118 } 119 120 134 public void classPrepared (ClassPrepareEvent event) throws DebugException { 135 ReferenceType rt = event.referenceType(); 136 String className = rt.name(); 140 141 int indexOfDollar = className.indexOf('$'); 143 if (indexOfDollar > 1) { 144 className = className.substring(0, indexOfDollar); 145 } 146 147 Vector <DocumentDebugAction<?>> actions = _pendingActions.get(className); 149 Vector <DocumentDebugAction<?>> failedActions = 150 new Vector <DocumentDebugAction<?>>(); 151 if (actions == null) { 153 return; 156 } 157 else if (actions.isEmpty()) { 158 _manager.getEventRequestManager().deleteEventRequest(event.request()); 161 return; 162 } 163 for (int i = 0; i < actions.size(); i++) { 164 DocumentDebugAction<?> a = actions.get(i); 165 int lineNumber = a.getLineNumber(); 166 if (lineNumber != DebugAction.ANY_LINE) { 167 try { 168 List lines = rt.locationsOfLine(lineNumber); 169 if (lines.size() == 0) { 170 String exactClassName = a.getExactClassName(); 172 if ((exactClassName!=null) && (exactClassName.equals(rt.name()))) { 173 _manager.printMessage(actions.get(i).toString()+" not on an executable line; disabled."); 174 actions.get(i).setEnabled(false); 175 } 176 177 continue; 179 } 180 } 181 catch (AbsentInformationException aie) { 182 continue; 184 } 185 } 186 try { 188 Vector <ReferenceType> refTypes = new Vector <ReferenceType>(); 189 refTypes.add(rt); 190 a.createRequests(refTypes); } 192 catch (DebugException e) { 193 failedActions.add(a); 194 } 196 } 197 198 210 if (failedActions.size() > 0) { 211 throw new DebugException("Failed actions: " + failedActions); 213 } 214 } 215 } 216 | Popular Tags |