1 11 package org.eclipse.jdt.internal.debug.core.breakpoints; 12 13 import java.util.Iterator ; 14 import java.util.List ; 15 import java.util.ListIterator ; 16 import java.util.Map ; 17 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.IWorkspaceRunnable; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.IStatus; 23 import org.eclipse.core.runtime.Status; 24 import org.eclipse.debug.core.DebugException; 25 import org.eclipse.debug.core.DebugPlugin; 26 import org.eclipse.debug.core.IStatusHandler; 27 import org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint; 28 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 29 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 30 31 import com.sun.jdi.AbsentInformationException; 32 import com.sun.jdi.ClassNotPreparedException; 33 import com.sun.jdi.Location; 34 import com.sun.jdi.NativeMethodException; 35 import com.sun.jdi.ReferenceType; 36 import com.sun.jdi.VMDisconnectedException; 37 import com.sun.jdi.VirtualMachine; 38 39 45 public class JavaStratumLineBreakpoint extends JavaLineBreakpoint implements IJavaStratumLineBreakpoint { 46 private static final String PATTERN= "org.eclipse.jdt.debug.pattern"; private static final String STRATUM= "org.eclipse.jdt.debug.stratum"; private static final String SOURCE_PATH= "org.eclipse.jdt.debug.source_path"; private static final String STRATUM_BREAKPOINT= "org.eclipse.jdt.debug.javaStratumLineBreakpointMarker"; private String [] fTypeNamePatterns; 51 private String [] fSuffix; 53 private String [] fPrefix; 54 55 public JavaStratumLineBreakpoint() { 56 } 57 58 102 public JavaStratumLineBreakpoint(IResource resource, String stratum, String sourceName, String sourcePath, String classNamePattern, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws DebugException { 103 this(resource, stratum, sourceName, sourcePath, classNamePattern, lineNumber, charStart, charEnd, hitCount, register, attributes, STRATUM_BREAKPOINT); 104 } 105 106 protected JavaStratumLineBreakpoint(final IResource resource, final String stratum, final String sourceName, final String sourcePath, final String classNamePattern, final int lineNumber, final int charStart, final int charEnd, final int hitCount, final boolean register, final Map attributes, final String markerType) throws DebugException { 107 IWorkspaceRunnable wr= new IWorkspaceRunnable() { 108 public void run(IProgressMonitor monitor) throws CoreException { 109 110 setMarker(resource.createMarker(markerType)); 112 113 String pattern = classNamePattern; 115 if (pattern != null && pattern.length() == 0) { 116 pattern = null; 117 } 118 119 addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd); 121 addStratumPatternAndHitCount(attributes, stratum, sourceName, sourcePath, pattern, hitCount); 122 attributes.put(SUSPEND_POLICY, new Integer (getDefaultSuspendPolicy())); 124 ensureMarker().setAttributes(attributes); 125 126 register(register); 127 } 128 }; 129 run(getMarkerRule(resource), wr); 130 } 131 132 135 protected void addStratumPatternAndHitCount(Map attributes, String stratum, String sourceName, String sourcePath, String pattern, int hitCount) { 136 attributes.put(PATTERN, pattern); 137 attributes.put(STRATUM, stratum); 138 if (sourceName != null) { 139 attributes.put(SOURCE_NAME, sourceName); 140 } 141 if (sourcePath != null) { 142 attributes.put(SOURCE_PATH, sourcePath); 143 } 144 if (hitCount > 0) { 145 attributes.put(HIT_COUNT, new Integer (hitCount)); 146 attributes.put(EXPIRED, Boolean.FALSE); 147 } 148 } 149 150 153 protected boolean installableReferenceType(ReferenceType type, JDIDebugTarget target) throws CoreException { 154 155 String typeName= type.name(); 157 if (!validType(typeName)) { 158 return false; 159 } 160 String stratum = getStratum(); 161 String bpSourceName= getSourceName(); 163 if (bpSourceName != null) { 164 List sourceNames; 165 try { 166 sourceNames= type.sourceNames(stratum); 167 } catch (AbsentInformationException e1) { 168 return false; 169 } catch (VMDisconnectedException e) { 170 if (!target.isAvailable()) { 171 return false; 172 } 173 throw e; 174 } 175 if (!containsMatch(sourceNames, bpSourceName)) { 176 return false; 177 } 178 } 179 180 String bpSourcePath= getSourcePath(); 181 if (bpSourcePath != null) { 182 List sourcePaths; 184 try { 185 sourcePaths= type.sourcePaths(stratum); 186 } catch (AbsentInformationException e1) { 187 return false; 188 } catch (VMDisconnectedException e) { 189 if (!target.isAvailable()) { 190 return false; 191 } 192 throw e; 193 } 194 if (!containsMatch(sourcePaths, bpSourcePath)) { 195 return false; 196 } 197 } 198 return queryInstallListeners(target, type); 199 } 200 201 private boolean containsMatch(List strings, String key) { 202 for (Iterator iter = strings.iterator(); iter.hasNext();) { 203 if (((String ) iter.next()).equals(key)) { 204 return true; 205 } 206 } 207 return false; 208 } 209 210 214 private boolean validType(String typeName) throws CoreException { 215 216 String [] patterns = getTypeNamePatterns(); 217 for (int i=0; i<patterns.length; i++) { 218 if (fSuffix[i] != null) { 219 if (fSuffix[i].length() == 0) { 221 return true; 222 } 223 if (typeName.endsWith(fSuffix[i])) 224 return true; 225 } else if (fPrefix[i] != null) { 226 if (typeName.startsWith(fPrefix[i])) 227 return true; 228 } else { 229 if (typeName.startsWith(patterns[i])) 230 return true; 231 } 232 } 233 234 return false; 236 } 237 238 242 protected List determineLocations(int lineNumber, ReferenceType type, JDIDebugTarget target) { 243 List locations; 244 String sourcePath; 245 try { 246 locations= type.locationsOfLine(getStratum(), getSourceName(), lineNumber); 247 sourcePath= getSourcePath(); 248 } catch (AbsentInformationException aie) { 249 IStatus status= new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), NO_LINE_NUMBERS, JDIDebugBreakpointMessages.JavaLineBreakpoint_Absent_Line_Number_Information_1, null); 250 IStatusHandler handler= DebugPlugin.getDefault().getStatusHandler(status); 251 if (handler != null) { 252 try { 253 handler.handleStatus(status, type); 254 } catch (CoreException e) { 255 } 256 } 257 return null; 258 } catch (NativeMethodException e) { 259 return null; 260 } catch (VMDisconnectedException e) { 261 return null; 262 } catch (ClassNotPreparedException e) { 263 return null; 265 } catch (RuntimeException e) { 266 target.internalError(e); 268 return null; 269 } catch (CoreException e) { 270 JDIDebugPlugin.log(e); 272 return null; 273 } 274 275 if (sourcePath == null) { 276 if (locations.size() > 0) { 277 return locations; 278 } 279 } else { 280 for (ListIterator iter = locations.listIterator(); iter.hasNext();) { 281 Location location = (Location) iter.next(); 282 try { 283 if (!sourcePath.equals(location.sourcePath())) { 284 iter.remove(); 285 } 286 } catch (AbsentInformationException e1) { 287 } 289 } 290 if (locations.size() > 0) { 291 return locations; 292 } 293 } 294 295 return null; 296 } 297 298 301 public String getPattern() throws CoreException { 302 return ensureMarker().getAttribute(PATTERN, "*"); } 304 305 308 public String getSourceName() throws CoreException { 309 return (String ) ensureMarker().getAttribute(SOURCE_NAME); 310 } 311 312 315 public String getStratum() throws CoreException { 316 return (String ) ensureMarker().getAttribute(STRATUM); 317 } 318 319 322 public String getSourcePath() throws CoreException { 323 return (String ) ensureMarker().getAttribute(SOURCE_PATH); 324 } 325 326 protected void createRequests(JDIDebugTarget target) throws CoreException { 327 if (target.isTerminated() || shouldSkipBreakpoint()) { 328 return; 329 } 330 331 String [] patterns = null; 332 try { 333 patterns = getTypeNamePatterns(); 334 } catch (CoreException e1) { 335 JDIDebugPlugin.log(e1); 336 return; 337 } 338 339 String sourceName = getSourceName(); 340 for (int i=0; i<patterns.length; i++) 341 { 342 String classPrepareTypeName= patterns[i]; 343 registerRequest(target.createClassPrepareRequest(classPrepareTypeName, null, true, sourceName), target); 346 } 347 348 VirtualMachine vm = target.getVM(); 350 if (vm == null) { 351 target.requestFailed(JDIDebugBreakpointMessages.JavaPatternBreakpoint_Unable_to_add_breakpoint___VM_disconnected__1, null); 352 } 353 List classes = null; 354 try { 355 classes= vm.allClasses(); 356 } catch (RuntimeException e) { 357 target.targetRequestFailed(JDIDebugBreakpointMessages.JavaPatternBreakpoint_0, e); 358 } 359 if (classes != null) { 360 Iterator iter = classes.iterator(); 361 while (iter.hasNext()) { 362 ReferenceType type= (ReferenceType)iter.next(); 363 if (installableReferenceType(type, target)) { 364 createRequest(target, type); 365 } 366 } 367 } 368 } 369 370 public synchronized String [] getTypeNamePatterns() throws CoreException 371 { 372 if (fTypeNamePatterns != null) 373 return fTypeNamePatterns; 374 375 String patterns = getPattern(); 376 377 fTypeNamePatterns = patterns.split(","); fSuffix = new String [fTypeNamePatterns.length]; 380 fPrefix = new String [fTypeNamePatterns.length]; 381 for (int i = 0; i < fTypeNamePatterns.length; i++) { 382 fTypeNamePatterns[i] = fTypeNamePatterns[i].trim(); 383 String pattern = fTypeNamePatterns[i]; 384 if (pattern.charAt(0) == '*') { 385 if (pattern.length() > 1) { 386 fSuffix[i] = pattern.substring(1); 387 } else { 388 fSuffix[i] = ""; } 390 } else if (pattern.charAt(pattern.length() - 1) == '*') { 391 fPrefix[i] = pattern.substring(0, pattern.length() - 1); 392 } 393 } 394 395 return fTypeNamePatterns; 396 } 397 398 } 399 | Popular Tags |