001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.debug.core;
011:
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: import org.eclipse.core.resources.IMarker;
016: import org.eclipse.core.resources.IResource;
017: import org.eclipse.core.resources.IWorkspaceRunnable;
018: import org.eclipse.core.resources.ResourcesPlugin;
019: import org.eclipse.core.runtime.CoreException;
020: import org.eclipse.core.runtime.IProgressMonitor;
021: import org.eclipse.core.runtime.Preferences;
022: import org.eclipse.debug.core.DebugPlugin;
023: import org.eclipse.debug.core.IBreakpointManager;
024: import org.eclipse.debug.core.ILaunch;
025: import org.eclipse.debug.core.model.IBreakpoint;
026: import org.eclipse.debug.core.model.IDebugTarget;
027: import org.eclipse.debug.core.model.IProcess;
028: import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
029: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaClassPrepareBreakpoint;
030: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaExceptionBreakpoint;
031: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
032: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaMethodBreakpoint;
033: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaMethodEntryBreakpoint;
034: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaPatternBreakpoint;
035: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaStratumLineBreakpoint;
036: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaTargetPatternBreakpoint;
037: import org.eclipse.jdt.internal.debug.core.breakpoints.JavaWatchpoint;
038: import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
039:
040: import com.sun.jdi.VirtualMachine;
041:
042: /**
043: * Provides utility methods for creating debug targets and breakpoints specific
044: * to the JDI debug model.
045: * <p>
046: * To provide access to behavior and information specific to the JDI
047: * debug model, a set of interfaces are defined which extend the base
048: * set of debug element interfaces. For example, <code>IJavaStackFrame</code>
049: * is declared to extend <code>IStackFrame</code>, and provides methods
050: * specific to this debug model. The specialized interfaces are also
051: * available as adapters from the debug elements generated from this
052: * model.
053: * </p>
054: * <p>
055: * Clients are not intended to instantiate or subclass this class;
056: * this class provides static utility methods only.
057: * </p>
058: */
059: public class JDIDebugModel {
060:
061: /**
062: * Preference key for default JDI request timeout value.
063: */
064: public static final String PREF_REQUEST_TIMEOUT = getPluginIdentifier()
065: + ".PREF_REQUEST_TIMEOUT"; //$NON-NLS-1$
066:
067: /**
068: * Preference key for specifying if hot code replace should be performed
069: * when a replacement class file contains compilation errors.
070: */
071: public static final String PREF_HCR_WITH_COMPILATION_ERRORS = getPluginIdentifier()
072: + ".PREF_HCR_WITH_COMPILATION_ERRORS"; //$NON-NLS-1$
073:
074: /**
075: * The default JDI request timeout when no preference is set.
076: */
077: public static final int DEF_REQUEST_TIMEOUT = 3000;
078:
079: /**
080: * Boolean preference controlling whether breakpoints are
081: * hit during an evaluation operation.
082: * If true, breakpoints will be hit as usual during evaluations.
083: * If false, the breakpoint manager will be automatically disabled
084: * during evaluations.
085: *
086: * @since 3.0
087: */
088: public static final String PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION = getPluginIdentifier()
089: + ".suspend_for_breakpoints_during_evaluation"; //$NON-NLS-1$
090:
091: /**
092: * Not to be instantiated.
093: */
094: private JDIDebugModel() {
095: super ();
096: }
097:
098: /**
099: * Creates and returns a debug target for the given VM, with
100: * the specified name, and associates the debug target with the
101: * given process for console I/O. The allow terminate flag specifies whether
102: * the debug target will support termination (<code>ITerminate</code>).
103: * The allow disconnect flag specifies whether the debug target will
104: * support disconnection (<code>IDisconnect</code>). Launching the actual
105: * VM is a client responsibility. By default, the target VM will be
106: * resumed on startup.
107: * The debug target is added to the given launch.
108: *
109: * @param launch the launch the new debug target will be contained in
110: * @param vm the VM to create a debug target for
111: * @param name the name to associate with the VM, which will be
112: * returned from <code>IDebugTarget.getName</code>. If <code>null</code>
113: * the name will be retrieved from the underlying VM.
114: * @param process the process to associate with the debug target,
115: * which will be returned from <code>IDebugTarget.getProcess</code>
116: * @param allowTerminate whether the target will support termination
117: * @param allowDisconnect whether the target will support disconnection
118: * @return a debug target
119: * @see org.eclipse.debug.core.model.ITerminate
120: * @see org.eclipse.debug.core.model.IDisconnect
121: * @since 2.0
122: */
123: public static IDebugTarget newDebugTarget(ILaunch launch,
124: VirtualMachine vm, String name, IProcess process,
125: boolean allowTerminate, boolean allowDisconnect) {
126: return newDebugTarget(launch, vm, name, process,
127: allowTerminate, allowDisconnect, true);
128: }
129:
130: /**
131: * Creates and returns a debug target for the given VM, with
132: * the specified name, and associates the debug target with the
133: * given process for console I/O. The allow terminate flag specifies whether
134: * the debug target will support termination (<code>ITerminate</code>).
135: * The allow disconnect flag specifies whether the debug target will
136: * support disconnection (<code>IDisconnect</code>). The resume
137: * flag specifies if the target VM should be resumed on startup (has
138: * no effect if the VM was already running when the connection to the
139: * VM was established). Launching the actual VM is a client responsibility.
140: * The debug target is added to the given launch.
141: *
142: * @param launch the launch the new debug target will be contained in
143: * @param vm the VM to create a debug target for
144: * @param name the name to associate with the VM, which will be
145: * returned from <code>IDebugTarget.getName</code>. If <code>null</code>
146: * the name will be retrieved from the underlying VM.
147: * @param process the process to associate with the debug target,
148: * which will be returned from <code>IDebugTarget.getProcess</code>
149: * @param allowTerminate whether the target will support termination
150: * @param allowDisconnect whether the target will support disconnection
151: * @param resume whether the target is to be resumed on startup. Has
152: * no effect if the target was already running when the connection
153: * to the VM was established.
154: * @return a debug target
155: * @see org.eclipse.debug.core.model.ITerminate
156: * @see org.eclipse.debug.core.model.IDisconnect
157: * @since 2.0
158: */
159: public static IDebugTarget newDebugTarget(final ILaunch launch,
160: final VirtualMachine vm, final String name,
161: final IProcess process, final boolean allowTerminate,
162: final boolean allowDisconnect, final boolean resume) {
163: final IJavaDebugTarget[] target = new IJavaDebugTarget[1];
164: IWorkspaceRunnable r = new IWorkspaceRunnable() {
165: public void run(IProgressMonitor m) {
166: target[0] = new JDIDebugTarget(launch, vm, name,
167: allowTerminate, allowDisconnect, process,
168: resume);
169: }
170: };
171: try {
172: ResourcesPlugin.getWorkspace().run(r, null, 0, null);
173: } catch (CoreException e) {
174: JDIDebugPlugin.log(e);
175: }
176: return target[0];
177: }
178:
179: /**
180: * Returns the identifier for the JDI debug model plug-in
181: *
182: * @return plug-in identifier
183: */
184: public static String getPluginIdentifier() {
185: return JDIDebugPlugin.getUniqueIdentifier();
186: }
187:
188: /**
189: * Registers the given listener for hot code replace notifications. Has no
190: * effect if an identical listener is already registered.
191: *
192: * @param listener hot code replace listener
193: * @see IJavaHotCodeReplaceListener
194: * @since 2.0
195: */
196: public static void addHotCodeReplaceListener(
197: IJavaHotCodeReplaceListener listener) {
198: JDIDebugPlugin.getDefault().addHotCodeReplaceListener(listener);
199: }
200:
201: /**
202: * Unregisters the given listener for hot code replace notifications. Has no
203: * effect if an identical listener is not already registered.
204: *
205: * @param listener hot code replace listener
206: * @see IJavaHotCodeReplaceListener
207: * @since 2.0
208: */
209: public static void removeHotCodeReplaceListener(
210: IJavaHotCodeReplaceListener listener) {
211: JDIDebugPlugin.getDefault().removeHotCodeReplaceListener(
212: listener);
213: }
214:
215: /**
216: * Registers the given listener for breakpoint notifications. Has no
217: * effect if an identical listener is already registered.
218: *
219: * @param listener breakpoint listener
220: * @see IJavaBreakpointListener
221: * @since 2.0
222: */
223: public static void addJavaBreakpointListener(
224: IJavaBreakpointListener listener) {
225: JDIDebugPlugin.getDefault().addJavaBreakpointListener(listener);
226: }
227:
228: /**
229: * Unregisters the given listener for breakpoint notifications. Has no
230: * effect if an identical listener is not already registered.
231: *
232: * @param listener breakpoint listener
233: * @see IJavaBreakpointListener
234: * @since 2.0
235: */
236: public static void removeJavaBreakpointListener(
237: IJavaBreakpointListener listener) {
238: JDIDebugPlugin.getDefault().removeJavaBreakpointListener(
239: listener);
240: }
241:
242: /**
243: * Creates and returns a line breakpoint in the type with the
244: * given name, at the given line number. The marker associated with the
245: * breakpoint will be created on the specified resource. If a character
246: * range within the line is known, it may be specified by charStart/charEnd.
247: * If hitCount is > 0, the breakpoint will suspend execution when it is
248: * "hit" the specified number of times.
249: *
250: * @param resource the resource on which to create the associated breakpoint
251: * marker
252: * @param typeName the fully qualified name of the type the breakpoint is
253: * to be installed in. If the breakpoint is to be installed in an inner type,
254: * it is sufficient to provide the name of the top level enclosing type.
255: * If an inner class name is specified, it should be formatted as the
256: * associated class file name (i.e. with <code>$</code>). For example,
257: * <code>example.SomeClass$InnerType</code>, could be specified, but
258: * <code>example.SomeClass</code> is sufficient.
259: * @param lineNumber the lineNumber on which the breakpoint is set - line
260: * numbers are 1 based, associated with the source file in which
261: * the breakpoint is set
262: * @param charStart the first character index associated with the breakpoint,
263: * or -1 if unspecified, in the source file in which the breakpoint is set
264: * @param charEnd the last character index associated with the breakpoint,
265: * or -1 if unspecified, in the source file in which the breakpoint is set
266: * @param hitCount the number of times the breakpoint will be hit before
267: * suspending execution - 0 if it should always suspend
268: * @param register whether to add this breakpoint to the breakpoint manager
269: * @param attributes a map of client defined attributes that should be assigned
270: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
271: * @return a line breakpoint
272: * @exception CoreException If this method fails. Reasons include:<ul>
273: *<li>Failure creating underlying marker. The exception's status contains
274: * the underlying exception responsible for the failure.</li></ul>
275: * @since 2.0
276: */
277: public static IJavaLineBreakpoint createLineBreakpoint(
278: IResource resource, String typeName, int lineNumber,
279: int charStart, int charEnd, int hitCount, boolean register,
280: Map attributes) throws CoreException {
281: if (attributes == null) {
282: attributes = new HashMap(10);
283: }
284: return new JavaLineBreakpoint(resource, typeName, lineNumber,
285: charStart, charEnd, hitCount, register, attributes);
286: }
287:
288: /**
289: * Creates and returns a pattern breakpoint for the given resource at the
290: * given line number, which is installed in all classes whose fully
291: * qualified name matches the given pattern.
292: * If hitCount > 0, the breakpoint will suspend execution when it is
293: * "hit" the specified number of times.
294: *
295: * @param resource the resource on which to create the associated breakpoint
296: * marker
297: * @param sourceName the name of the source file in which the breakpoint is
298: * set, or <code>null</code>. When specified, the pattern breakpoint will
299: * install itself in classes that have a source file name debug attribute
300: * that matches this value, and satisfies the class name pattern.
301: * @param pattern the class name pattern in which the pattern breakpoint should
302: * be installed. The pattern breakpoint will install itself in every class which
303: * matches the pattern.
304: * @param lineNumber the lineNumber on which the breakpoint is set - line
305: * numbers are 1 based, associated with the source file in which
306: * the breakpoint is set
307: * @param charStart the first character index associated with the breakpoint,
308: * or -1 if unspecified, in the source file in which the breakpoint is set
309: * @param charEnd the last character index associated with the breakpoint,
310: * or -1 if unspecified, in the source file in which the breakpoint is set
311: * @param hitCount the number of times the breakpoint will be hit before
312: * suspending execution - 0 if it should always suspend
313: * @param register whether to add this breakpoint to the breakpoint manager
314: * @param attributes a map of client defined attributes that should be assigned
315: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
316: * @return a pattern breakpoint
317: * @exception CoreException If this method fails. Reasons include:<ul>
318: *<li>Failure creating underlying marker. The exception's status contains
319: * the underlying exception responsible for the failure.</li></ul>
320: * @deprecated use <code>createStratumBreakpoint</code> instead
321: */
322: public static IJavaPatternBreakpoint createPatternBreakpoint(
323: IResource resource, String sourceName, String pattern,
324: int lineNumber, int charStart, int charEnd, int hitCount,
325: boolean register, Map attributes) throws CoreException {
326: if (attributes == null) {
327: attributes = new HashMap(10);
328: }
329: return new JavaPatternBreakpoint(resource, sourceName, pattern,
330: lineNumber, charStart, charEnd, hitCount, register,
331: attributes);
332: }
333:
334: /**
335: * Creates and returns a line breakpoint identified by its source file
336: * name and/or path, and stratum that it is relative to.
337: *
338: * @param resource the resource on which to create the associated breakpoint
339: * marker
340: * @param stratum the stratum in which the source name, source path and line number
341: * are relative, or <code>null</code>. If <code>null</code> or if the specified stratum
342: * is not defined for a type, the source name, source path and line number are
343: * relative to the type's default stratum.
344: * @param sourceName the simple name of the source file in which the breakpoint is
345: * set, or <code>null</code>. The breakpoint will install itself in classes that have a source
346: * file name debug attribute that matches this value in the specified stratum,
347: * and satisfies the class name pattern and source path attribute. When <code>null</code>,
348: * the source file name debug attribute is not considered.
349: * @param sourcePath the qualified source file name in which the breakpoint is
350: * set, or <code>null</code>. The breakpoint will install itself in classes that
351: * have a source file path in the specified stratum that matches this value, and
352: * satisfies the class name pattern and source name attribute. When <code>null</code>,
353: * the source path attribute is not considered.
354: * @param classNamePattern the class name pattern to which the breakpoint should
355: * be restricted, or <code>null</code>. The breakpoint will install itself in each type that
356: * matches this class name pattern, with a satisfying source name and source path.
357: * Patterns may begin or end with '*', which matches 0 or more characters. A pattern that
358: * does not contain a '*' is equivalent to a pattern ending in '*'. Specifying <code>null</code>,
359: * or an empty string is the equivalent to "*". Multiple patterns can be specified
360: * by delimiting the patterns with a comma - e.g. "x.y.z,a.b.c". When multiple patterns
361: * are specified, The breakpoint will install itself in each of the types that
362: * match any of the specified class pattern, with a satisfying source name and source path.
363: * @param lineNumber the lineNumber on which the breakpoint is set - line
364: * numbers are 1 based, associated with the source file (stratum) in which
365: * the breakpoint is set
366: * @param charStart the first character index associated with the breakpoint,
367: * or -1 if unspecified, in the source file in which the breakpoint is set
368: * @param charEnd the last character index associated with the breakpoint,
369: * or -1 if unspecified, in the source file in which the breakpoint is set
370: * @param hitCount the number of times the breakpoint will be hit before
371: * suspending execution - 0 if it should always suspend
372: * @param register whether to add this breakpoint to the breakpoint manager
373: * @param attributes a map of client defined attributes that should be assigned
374: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
375: * @return a stratum breakpoint
376: * @exception CoreException If this method fails. Reasons include:<ul>
377: *<li>Failure creating underlying marker. The exception's status contains
378: * the underlying exception responsible for the failure.</li></ul>
379: * @since 3.0
380: */
381: public static IJavaStratumLineBreakpoint createStratumBreakpoint(
382: IResource resource, String stratum, String sourceName,
383: String sourcePath, String classNamePattern, int lineNumber,
384: int charStart, int charEnd, int hitCount, boolean register,
385: Map attributes) throws CoreException {
386: if (attributes == null) {
387: attributes = new HashMap(10);
388: }
389: return new JavaStratumLineBreakpoint(resource, stratum,
390: sourceName, sourcePath, classNamePattern, lineNumber,
391: charStart, charEnd, hitCount, register, attributes);
392: }
393:
394: /**
395: * Creates and returns a target pattern breakpoint for the given resource at the
396: * given line number. Clients must set the class name pattern per target for
397: * this type of breakpoint.
398: * If hitCount > 0, the breakpoint will suspend execution when it is
399: * "hit" the specified number of times.
400: *
401: * @param resource the resource on which to create the associated breakpoint
402: * marker
403: * @param sourceName the name of the source file in which the breakpoint is
404: * set, or <code>null</code>. When specified, the pattern breakpoint will
405: * install itself in classes that have a source file name debug attribute
406: * that matches this value, and satisfies the class name pattern.
407: * @param lineNumber the lineNumber on which the breakpoint is set - line
408: * numbers are 1 based, associated with the source file in which
409: * the breakpoint is set
410: * @param charStart the first character index associated with the breakpoint,
411: * or -1 if unspecified, in the source file in which the breakpoint is set
412: * @param charEnd the last character index associated with the breakpoint,
413: * or -1 if unspecified, in the source file in which the breakpoint is set
414: * @param hitCount the number of times the breakpoint will be hit before
415: * suspending execution - 0 if it should always suspend
416: * @param register whether to add this breakpoint to the breakpoint manager
417: * @param attributes a map of client defined attributes that should be assigned
418: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
419: * @return a target pattern breakpoint
420: * @exception CoreException If this method fails. Reasons include:<ul>
421: *<li>Failure creating underlying marker. The exception's status contains
422: * the underlying exception responsible for the failure.</li></ul>
423: */
424: public static IJavaTargetPatternBreakpoint createTargetPatternBreakpoint(
425: IResource resource, String sourceName, int lineNumber,
426: int charStart, int charEnd, int hitCount, boolean register,
427: Map attributes) throws CoreException {
428: if (attributes == null) {
429: attributes = new HashMap(10);
430: }
431: return new JavaTargetPatternBreakpoint(resource, sourceName,
432: lineNumber, charStart, charEnd, hitCount, register,
433: attributes);
434: }
435:
436: /**
437: * Creates and returns an exception breakpoint for an exception with the given name.
438: * The marker associated with the breakpoint will be created on the specified resource.
439: * Caught and uncaught specify where the exception
440: * should cause thread suspensions - that is, in caught and/or uncaught locations.
441: * Checked indicates if the given exception is a checked exception.
442: *
443: * @param resource the resource on which to create the associated
444: * breakpoint marker
445: * @param exceptionName the fully qualified name of the exception for
446: * which to create the breakpoint
447: * @param caught whether to suspend in caught locations
448: * @param uncaught whether to suspend in uncaught locations
449: * @param checked whether the exception is a checked exception (i.e. compiler
450: * detected)
451: * @param register whether to add this breakpoint to the breakpoint manager
452: * @param attributes a map of client defined attributes that should be assigned
453: * to the underlying breakpoint marker on creation or <code>null</code> if none.
454: * @return an exception breakpoint
455: * @exception CoreException If this method fails. Reasons include:<ul>
456: *<li>Failure creating underlying marker. The exception's status contains
457: * the underlying exception responsible for the failure.</li></ul>
458: * @since 2.0
459: */
460: public static IJavaExceptionBreakpoint createExceptionBreakpoint(
461: IResource resource, String exceptionName, boolean caught,
462: boolean uncaught, boolean checked, boolean register,
463: Map attributes) throws CoreException {
464: if (attributes == null) {
465: attributes = new HashMap(10);
466: }
467: return new JavaExceptionBreakpoint(resource, exceptionName,
468: caught, uncaught, checked, register, attributes);
469: }
470:
471: /**
472: * Creates and returns a watchpoint on a field with the given name
473: * in a type with the given name.
474: * The marker associated with the breakpoint will be created on the specified resource.
475: * If hitCount > 0, the breakpoint will suspend execution when it is
476: * "hit" the specified number of times.
477: *
478: * @param resource the resource on which to create the associated breakpoint
479: * marker
480: * @param typeName the fully qualified name of the type the breakpoint is
481: * to be installed in. If the breakpoint is to be installed in an inner type,
482: * it is sufficient to provide the name of the top level enclosing type.
483: * If an inner class name is specified, it should be formatted as the
484: * associated class file name (i.e. with <code>$</code>). For example,
485: * <code>example.SomeClass$InnerType</code>, could be specified, but
486: * <code>example.SomeClass</code> is sufficient.
487: * @param fieldName the name of the field on which to suspend (on access or modification)
488: * @param lineNumber the lineNumber on which the breakpoint is set - line
489: * numbers are 1 based, associated with the source file in which
490: * the breakpoint is set
491: * @param charStart the first character index associated with the breakpoint,
492: * or -1 if unspecified, in the source file in which the breakpoint is set
493: * @param charEnd the last character index associated with the breakpoint,
494: * or -1 if unspecified, in the source file in which the breakpoint is set
495: * @param hitCount the number of times the breakpoint will be hit before
496: * suspending execution - 0 if it should always suspend
497: * @param register whether to add this breakpoint to the breakpoint manager
498: * @param attributes a map of client defined attributes that should be assigned
499: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
500: * @return a watchpoint
501: * @exception CoreException If this method fails. Reasons include:<ul>
502: *<li>Failure creating underlying marker. The CoreException's status contains
503: * the underlying exception responsible for the failure.</li></ul>
504: * @since 2.0
505: */
506: public static IJavaWatchpoint createWatchpoint(IResource resource,
507: String typeName, String fieldName, int lineNumber,
508: int charStart, int charEnd, int hitCount, boolean register,
509: Map attributes) throws CoreException {
510: if (attributes == null) {
511: attributes = new HashMap(10);
512: }
513: return new JavaWatchpoint(resource, typeName, fieldName,
514: lineNumber, charStart, charEnd, hitCount, register,
515: attributes);
516: }
517:
518: /**
519: * Creates and returns a method breakpoint with the specified
520: * criteria.
521: *
522: * @param resource the resource on which to create the associated
523: * breakpoint marker
524: * @param typePattern the pattern specifying the fully qualified name of type(s)
525: * this breakpoint suspends execution in. Patterns are limited to exact
526: * matches and patterns that begin or end with '*'.
527: * @param methodName the name of the method(s) this breakpoint suspends
528: * execution in, or <code>null</code> if this breakpoint does
529: * not suspend execution based on method name
530: * @param methodSignature the signature of the method(s) this breakpoint suspends
531: * execution in, or <code>null</code> if this breakpoint does not
532: * suspend execution based on method signature
533: * @param entry whether this breakpoint causes execution to suspend
534: * on entry of methods
535: * @param exit whether this breakpoint causes execution to suspend
536: * on exit of methods
537: * @param nativeOnly whether this breakpoint causes execution to suspend
538: * on entry/exit of native methods only
539: * @param lineNumber the lineNumber on which the breakpoint is set - line
540: * numbers are 1 based, associated with the source file in which
541: * the breakpoint is set
542: * @param charStart the first character index associated with the breakpoint,
543: * or -1 if unspecified, in the source file in which the breakpoint is set
544: * @param charEnd the last character index associated with the breakpoint,
545: * or -1 if unspecified, in the source file in which the breakpoint is set
546: * @param hitCount the number of times the breakpoint will be hit before
547: * suspending execution - 0 if it should always suspend
548: * @param register whether to add this breakpoint to the breakpoint manager
549: * @param attributes a map of client defined attributes that should be assigned
550: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
551: * @return a method breakpoint
552: * @exception CoreException If this method fails. Reasons include:<ul>
553: *<li>Failure creating underlying marker. The exception's status contains
554: * the underlying exception responsible for the failure.</li></ul>
555: * @since 2.0
556: */
557: public static IJavaMethodBreakpoint createMethodBreakpoint(
558: IResource resource, String typePattern, String methodName,
559: String methodSignature, boolean entry, boolean exit,
560: boolean nativeOnly, int lineNumber, int charStart,
561: int charEnd, int hitCount, boolean register, Map attributes)
562: throws CoreException {
563: if (attributes == null) {
564: attributes = new HashMap(10);
565: }
566: return new JavaMethodBreakpoint(resource, typePattern,
567: methodName, methodSignature, entry, exit, nativeOnly,
568: lineNumber, charStart, charEnd, hitCount, register,
569: attributes);
570: }
571:
572: /**
573: * Creates and returns a method entry breakpoint with the specified
574: * criteria. A method entry breakpoint will only be installed for methods
575: * that have executable code (i.e. will not work for native methods).
576: *
577: * @param resource the resource on which to create the associated
578: * breakpoint marker
579: * @param typeName the fully qualified name of type
580: * this breakpoint suspends execution in.
581: * @param methodName the name of the method this breakpoint suspends
582: * execution in
583: * @param methodSignature the signature of the method this breakpoint suspends
584: * execution in
585: * @param lineNumber the lineNumber on which the breakpoint is set - line
586: * numbers are 1 based, associated with the source file in which
587: * the breakpoint is set
588: * @param charStart the first character index associated with the breakpoint,
589: * or -1 if unspecified, in the source file in which the breakpoint is set
590: * @param charEnd the last character index associated with the breakpoint,
591: * or -1 if unspecified, in the source file in which the breakpoint is set
592: * @param hitCount the number of times the breakpoint will be hit before
593: * suspending execution - 0 if it should always suspend
594: * @param register whether to add this breakpoint to the breakpoint manager
595: * @param attributes a map of client defined attributes that should be assigned
596: * to the underlying breakpoint marker on creation, or <code>null</code> if none.
597: * @return a method entry breakpoint
598: * @exception CoreException If this method fails. Reasons include:<ul>
599: *<li>Failure creating underlying marker. The exception's status contains
600: * the underlying exception responsible for the failure.</li></ul>
601: * @since 2.0
602: */
603: public static IJavaMethodEntryBreakpoint createMethodEntryBreakpoint(
604: IResource resource, String typeName, String methodName,
605: String methodSignature, int lineNumber, int charStart,
606: int charEnd, int hitCount, boolean register, Map attributes)
607: throws CoreException {
608: if (attributes == null) {
609: attributes = new HashMap(10);
610: }
611: return new JavaMethodEntryBreakpoint(resource, typeName,
612: methodName, methodSignature, lineNumber, charStart,
613: charEnd, hitCount, register, attributes);
614: }
615:
616: /**
617: * Returns a Java line breakpoint that is already registered with the breakpoint
618: * manager for a type with the given name at the given line number.
619: *
620: * @param typeName fully qualified type name
621: * @param lineNumber line number
622: * @return a Java line breakpoint that is already registered with the breakpoint
623: * manager for a type with the given name at the given line number or <code>null</code>
624: * if no such breakpoint is registered
625: * @exception CoreException if unable to retrieve the associated marker
626: * attributes (line number).
627: */
628: public static IJavaLineBreakpoint lineBreakpointExists(
629: String typeName, int lineNumber) throws CoreException {
630: String modelId = getPluginIdentifier();
631: String markerType = JavaLineBreakpoint.getMarkerType();
632: IBreakpointManager manager = DebugPlugin.getDefault()
633: .getBreakpointManager();
634: IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
635: for (int i = 0; i < breakpoints.length; i++) {
636: if (!(breakpoints[i] instanceof IJavaLineBreakpoint)) {
637: continue;
638: }
639: IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) breakpoints[i];
640: IMarker marker = breakpoint.getMarker();
641: if (marker != null && marker.exists()
642: && marker.getType().equals(markerType)) {
643: String breakpointTypeName = breakpoint.getTypeName();
644: if (breakpointTypeName.equals(typeName)
645: || breakpointTypeName
646: .startsWith(typeName + '$')) {
647: if (breakpoint.getLineNumber() == lineNumber) {
648: return breakpoint;
649: }
650: }
651: }
652: }
653: return null;
654: }
655:
656: /**
657: * Returns a Java line breakpoint that is already registered with the breakpoint
658: * manager for a type with the given name at the given line number in the given resource.
659: *
660: * @param resource the resource
661: * @param typeName fully qualified type name
662: * @param lineNumber line number
663: * @return a Java line breakpoint that is already registered with the breakpoint
664: * manager for a type with the given name at the given line number or <code>null</code>
665: * if no such breakpoint is registered
666: * @exception CoreException if unable to retrieve the associated marker
667: * attributes (line number).
668: * @since 3.1
669: */
670: public static IJavaLineBreakpoint lineBreakpointExists(
671: IResource resource, String typeName, int lineNumber)
672: throws CoreException {
673: String modelId = getPluginIdentifier();
674: String markerType = JavaLineBreakpoint.getMarkerType();
675: IBreakpointManager manager = DebugPlugin.getDefault()
676: .getBreakpointManager();
677: IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
678: for (int i = 0; i < breakpoints.length; i++) {
679: if (!(breakpoints[i] instanceof IJavaLineBreakpoint)) {
680: continue;
681: }
682: IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) breakpoints[i];
683: IMarker marker = breakpoint.getMarker();
684: if (marker != null && marker.exists()
685: && marker.getType().equals(markerType)) {
686: String breakpointTypeName = breakpoint.getTypeName();
687: if ((breakpointTypeName.equals(typeName) || breakpointTypeName
688: .startsWith(typeName + '$'))
689: && breakpoint.getLineNumber() == lineNumber
690: && resource.equals(marker.getResource())) {
691: return breakpoint;
692: }
693: }
694: }
695: return null;
696: }
697:
698: /**
699: * Returns the preference store for this plug-in or <code>null</code>
700: * if the store is not available.
701: *
702: * @return the preference store for this plug-in
703: * @since 2.0
704: */
705: public static Preferences getPreferences() {
706: JDIDebugPlugin deflt = JDIDebugPlugin.getDefault();
707: if (deflt != null) {
708: return deflt.getPluginPreferences();
709: }
710: return null;
711: }
712:
713: /**
714: * Saves the preference store for this plug-in.
715: *
716: * @since 2.0
717: */
718: public static void savePreferences() {
719: JDIDebugPlugin.getDefault().savePluginPreferences();
720: }
721:
722: /**
723: * Creates and returns a class prepare breakpoint for a type with the given name.
724: * The marker associated with the breakpoint will be created on the specified resource.
725: *
726: * @param resource the resource on which to create the associated
727: * breakpoint marker
728: * @param typeName the fully qualified name of the type for
729: * which to create the breakpoint
730: * @param memberType one of <code>TYPE_CLASS</code> or <code>TYPE_INTERFACE</code>
731: * @param charStart the first character index associated with the breakpoint,
732: * or -1 if unspecified, in the source file in which the breakpoint is set
733: * @param charEnd the last character index associated with the breakpoint,
734: * or -1 if unspecified, in the source file in which the breakpoint is set
735: * @param register whether to add this breakpoint to the breakpoint manager
736: * @param attributes a map of client defined attributes that should be assigned
737: * to the underlying breakpoint marker on creation or <code>null</code> if none.
738: * @return a class prepare breakpoint
739: * @exception CoreException If this method fails. Reasons include:<ul>
740: *<li>Failure creating underlying marker. The exception's status contains
741: * the underlying exception responsible for the failure.</li></ul>
742: * @since 3.0
743: */
744: public static IJavaClassPrepareBreakpoint createClassPrepareBreakpoint(
745: IResource resource, String typeName, int memberType,
746: int charStart, int charEnd, boolean register, Map attributes)
747: throws CoreException {
748: if (attributes == null) {
749: attributes = new HashMap(10);
750: }
751: return new JavaClassPrepareBreakpoint(resource, typeName,
752: memberType, charStart, charEnd, register, attributes);
753: }
754: }
|