1 11 package org.eclipse.jdt.debug.core; 12 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.IWorkspaceRunnable; 20 import org.eclipse.core.resources.ResourcesPlugin; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.core.runtime.Preferences; 24 import org.eclipse.debug.core.DebugPlugin; 25 import org.eclipse.debug.core.IBreakpointManager; 26 import org.eclipse.debug.core.ILaunch; 27 import org.eclipse.debug.core.model.IBreakpoint; 28 import org.eclipse.debug.core.model.IDebugTarget; 29 import org.eclipse.debug.core.model.IProcess; 30 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 31 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaClassPrepareBreakpoint; 32 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaExceptionBreakpoint; 33 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint; 34 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaMethodBreakpoint; 35 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaMethodEntryBreakpoint; 36 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaPatternBreakpoint; 37 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaStratumLineBreakpoint; 38 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaTargetPatternBreakpoint; 39 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaWatchpoint; 40 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 41 42 import com.sun.jdi.VirtualMachine; 43 44 61 public class JDIDebugModel { 62 63 66 public static final String PREF_REQUEST_TIMEOUT = getPluginIdentifier() + ".PREF_REQUEST_TIMEOUT"; 68 72 public static final String PREF_HCR_WITH_COMPILATION_ERRORS= getPluginIdentifier() + ".PREF_HCR_WITH_COMPILATION_ERRORS"; 74 77 public static final int DEF_REQUEST_TIMEOUT = 3000; 78 79 88 public static final String PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION = getPluginIdentifier() + ".suspend_for_breakpoints_during_evaluation"; 90 93 private JDIDebugModel() { 94 super(); 95 } 96 97 122 public static IDebugTarget newDebugTarget(ILaunch launch, VirtualMachine vm, String name, IProcess process, boolean allowTerminate, boolean allowDisconnect) { 123 return newDebugTarget(launch, vm, name, process, allowTerminate, allowDisconnect, true); 124 } 125 126 155 public static IDebugTarget newDebugTarget(final ILaunch launch, final VirtualMachine vm, final String name, final IProcess process, final boolean allowTerminate, final boolean allowDisconnect, final boolean resume) { 156 final IJavaDebugTarget[] target = new IJavaDebugTarget[1]; 157 IWorkspaceRunnable r = new IWorkspaceRunnable() { 158 public void run(IProgressMonitor m) { 159 target[0]= new JDIDebugTarget(launch, vm, name, allowTerminate, allowDisconnect, process, resume); 160 } 161 }; 162 try { 163 ResourcesPlugin.getWorkspace().run(r, null, 0, null); 164 } catch (CoreException e) { 165 JDIDebugPlugin.log(e); 166 } 167 return target[0]; 168 } 169 170 175 public static String getPluginIdentifier() { 176 return JDIDebugPlugin.getUniqueIdentifier(); 177 } 178 179 187 public static void addHotCodeReplaceListener(IJavaHotCodeReplaceListener listener) { 188 JDIDebugPlugin.getDefault().addHotCodeReplaceListener(listener); 189 } 190 191 199 public static void removeHotCodeReplaceListener(IJavaHotCodeReplaceListener listener) { 200 JDIDebugPlugin.getDefault().removeHotCodeReplaceListener(listener); 201 } 202 203 211 public static void addJavaBreakpointListener(IJavaBreakpointListener listener) { 212 JDIDebugPlugin.getDefault().addJavaBreakpointListener(listener); 213 } 214 215 223 public static void removeJavaBreakpointListener(IJavaBreakpointListener listener) { 224 JDIDebugPlugin.getDefault().removeJavaBreakpointListener(listener); 225 } 226 227 228 263 public static IJavaLineBreakpoint createLineBreakpoint(IResource resource, String typeName, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 264 if (attributes == null) { 265 attributes = new HashMap (10); 266 } 267 return new JavaLineBreakpoint(resource, typeName, lineNumber, charStart, charEnd, hitCount, register, attributes); 268 } 269 270 304 public static IJavaPatternBreakpoint createPatternBreakpoint(IResource resource, String sourceName, String pattern, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 305 if (attributes == null) { 306 attributes = new HashMap (10); 307 } 308 return new JavaPatternBreakpoint(resource, sourceName, pattern, lineNumber, charStart, charEnd, hitCount, register, attributes); 309 } 310 311 358 public static IJavaStratumLineBreakpoint createStratumBreakpoint(IResource resource, String stratum, String sourceName, String sourcePath, String classNamePattern, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 359 if (attributes == null) { 360 attributes = new HashMap (10); 361 } 362 return new JavaStratumLineBreakpoint(resource, stratum, sourceName, sourcePath, classNamePattern, lineNumber, charStart, charEnd, hitCount, register, attributes); 363 } 364 365 395 public static IJavaTargetPatternBreakpoint createTargetPatternBreakpoint(IResource resource, String sourceName, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 396 if (attributes == null) { 397 attributes = new HashMap (10); 398 } 399 return new JavaTargetPatternBreakpoint(resource, sourceName, lineNumber, charStart, charEnd, hitCount, register, attributes); 400 } 401 402 426 public static IJavaExceptionBreakpoint createExceptionBreakpoint(IResource resource, String exceptionName, boolean caught, boolean uncaught, boolean checked, boolean register, Map attributes) throws CoreException { 427 if (attributes == null) { 428 attributes = new HashMap (10); 429 } 430 return new JavaExceptionBreakpoint(resource, exceptionName, caught, uncaught, checked, register, attributes); 431 } 432 433 468 public static IJavaWatchpoint createWatchpoint(IResource resource, String typeName, String fieldName, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 469 if (attributes == null) { 470 attributes = new HashMap (10); 471 } 472 return new JavaWatchpoint(resource, typeName, fieldName, lineNumber, charStart, charEnd, hitCount, register, attributes); 473 } 474 475 514 public static IJavaMethodBreakpoint createMethodBreakpoint(IResource resource, String typePattern, String methodName, String methodSignature, boolean entry, boolean exit, boolean nativeOnly, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 515 if (attributes == null) { 516 attributes = new HashMap (10); 517 } 518 return new JavaMethodBreakpoint(resource, typePattern, methodName, methodSignature, entry, exit, nativeOnly, lineNumber, charStart, charEnd, hitCount, register, attributes); 519 } 520 521 552 public static IJavaMethodEntryBreakpoint createMethodEntryBreakpoint(IResource resource, String typeName, String methodName, String methodSignature, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map attributes) throws CoreException { 553 if (attributes == null) { 554 attributes = new HashMap (10); 555 } 556 return new JavaMethodEntryBreakpoint(resource, typeName, methodName, methodSignature, lineNumber, charStart, charEnd, hitCount, register, attributes); 557 } 558 559 571 public static IJavaLineBreakpoint lineBreakpointExists(String typeName, int lineNumber) throws CoreException { 572 String modelId= getPluginIdentifier(); 573 String markerType= JavaLineBreakpoint.getMarkerType(); 574 IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager(); 575 IBreakpoint[] breakpoints= manager.getBreakpoints(modelId); 576 for (int i = 0; i < breakpoints.length; i++) { 577 if (!(breakpoints[i] instanceof IJavaLineBreakpoint)) { 578 continue; 579 } 580 IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) breakpoints[i]; 581 IMarker marker = breakpoint.getMarker(); 582 if (marker != null && marker.exists() && marker.getType().equals(markerType)) { 583 String breakpointTypeName = breakpoint.getTypeName(); 584 if (breakpointTypeName.equals(typeName) || breakpointTypeName.startsWith(typeName + '$')) { 585 if (breakpoint.getLineNumber() == lineNumber) { 586 return breakpoint; 587 } 588 } 589 } 590 } 591 return null; 592 } 593 594 608 public static IJavaLineBreakpoint lineBreakpointExists(IResource resource, String typeName, int lineNumber) throws CoreException { 609 String modelId= getPluginIdentifier(); 610 String markerType= JavaLineBreakpoint.getMarkerType(); 611 IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager(); 612 IBreakpoint[] breakpoints= manager.getBreakpoints(modelId); 613 for (int i = 0; i < breakpoints.length; i++) { 614 if (!(breakpoints[i] instanceof IJavaLineBreakpoint)) { 615 continue; 616 } 617 IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) breakpoints[i]; 618 IMarker marker = breakpoint.getMarker(); 619 if (marker != null && marker.exists() && marker.getType().equals(markerType)) { 620 String breakpointTypeName = breakpoint.getTypeName(); 621 if ((breakpointTypeName.equals(typeName) || breakpointTypeName.startsWith(typeName + '$')) && 622 breakpoint.getLineNumber() == lineNumber && 623 resource.equals(marker.getResource())) { 624 return breakpoint; 625 } 626 } 627 } 628 return null; 629 } 630 631 638 public static Preferences getPreferences() { 639 JDIDebugPlugin deflt= JDIDebugPlugin.getDefault(); 640 if (deflt != null) { 641 return deflt.getPluginPreferences(); 642 } 643 return null; 644 } 645 646 651 public static void savePreferences() { 652 JDIDebugPlugin.getDefault().savePluginPreferences(); 653 } 654 655 677 public static IJavaClassPrepareBreakpoint createClassPrepareBreakpoint(IResource resource, String typeName, int memberType, int charStart, int charEnd, boolean register, Map attributes) throws CoreException { 678 if (attributes == null) { 679 attributes = new HashMap (10); 680 } 681 return new JavaClassPrepareBreakpoint(resource, typeName, memberType, charStart, charEnd, register, attributes); 682 } 683 } 684 | Popular Tags |