KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > debug > core > JDIDebugModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.debug.core;
12
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
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 /**
45  * Provides utility methods for creating debug targets and breakpoints specific
46  * to the JDI debug model.
47  * <p>
48  * To provide access to behavior and information specific to the JDI
49  * debug model, a set of interfaces are defined which extend the base
50  * set of debug element interfaces. For example, <code>IJavaStackFrame</code>
51  * is declared to extend <code>IStackFrame</code>, and provides methods
52  * specific to this debug model. The specialized interfaces are also
53  * available as adapters from the debug elements generated from this
54  * model.
55  * </p>
56  * <p>
57  * Clients are not intended to instantiate or subclass this class;
58  * this class provides static utility methods only.
59  * </p>
60  */

61 public class JDIDebugModel {
62     
63     /**
64      * Preference key for default JDI request timeout value.
65      */

66     public static final String JavaDoc PREF_REQUEST_TIMEOUT = getPluginIdentifier() + ".PREF_REQUEST_TIMEOUT"; //$NON-NLS-1$
67

68     /**
69      * Preference key for specifying if hot code replace should be performed
70      * when a replacement class file contains compilation errors.
71      */

72     public static final String JavaDoc PREF_HCR_WITH_COMPILATION_ERRORS= getPluginIdentifier() + ".PREF_HCR_WITH_COMPILATION_ERRORS"; //$NON-NLS-1$
73

74     /**
75      * The default JDI request timeout when no preference is set.
76      */

77     public static final int DEF_REQUEST_TIMEOUT = 3000;
78     
79     /**
80      * Boolean preference controlling whether breakpoints are
81      * hit during an evaluation operation.
82      * If true, breakpoints will be hit as usual during evaluations.
83      * If false, the breakpoint manager will be automatically disabled
84      * during evaluations.
85      *
86      * @since 3.0
87      */

88     public static final String JavaDoc PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION = getPluginIdentifier() + ".suspend_for_breakpoints_during_evaluation"; //$NON-NLS-1$
89

90     /**
91      * Not to be instantiated.
92      */

93     private JDIDebugModel() {
94         super();
95     }
96     
97     /**
98      * Creates and returns a debug target for the given VM, with
99      * the specified name, and associates the debug target with the
100      * given process for console I/O. The allow terminate flag specifies whether
101      * the debug target will support termination (<code>ITerminate</code>).
102      * The allow disconnect flag specifies whether the debug target will
103      * support disconnection (<code>IDisconnect</code>). Launching the actual
104      * VM is a client responsibility. By default, the target VM will be
105      * resumed on startup.
106      * The debug target is added to the given launch.
107      *
108      * @param launch the launch the new debug target will be contained in
109      * @param vm the VM to create a debug target for
110      * @param name the name to associate with the VM, which will be
111      * returned from <code>IDebugTarget.getName</code>. If <code>null</code>
112      * the name will be retrieved from the underlying VM.
113      * @param process the process to associate with the debug target,
114      * which will be returned from <code>IDebugTarget.getProcess</code>
115      * @param allowTerminate whether the target will support termination
116      * @param allowDisconnect whether the target will support disconnection
117      * @return a debug target
118      * @see org.eclipse.debug.core.model.ITerminate
119      * @see org.eclipse.debug.core.model.IDisconnect
120      * @since 2.0
121      */

122     public static IDebugTarget newDebugTarget(ILaunch launch, VirtualMachine vm, String JavaDoc name, IProcess process, boolean allowTerminate, boolean allowDisconnect) {
123         return newDebugTarget(launch, vm, name, process, allowTerminate, allowDisconnect, true);
124     }
125
126     /**
127      * Creates and returns a debug target for the given VM, with
128      * the specified name, and associates the debug target with the
129      * given process for console I/O. The allow terminate flag specifies whether
130      * the debug target will support termination (<code>ITerminate</code>).
131      * The allow disconnect flag specifies whether the debug target will
132      * support disconnection (<code>IDisconnect</code>). The resume
133      * flag specifies if the target VM should be resumed on startup (has
134      * no effect if the VM was already running when the connection to the
135      * VM was established). Launching the actual VM is a client responsibility.
136      * The debug target is added to the given launch.
137      *
138      * @param launch the launch the new debug target will be contained in
139      * @param vm the VM to create a debug target for
140      * @param name the name to associate with the VM, which will be
141      * returned from <code>IDebugTarget.getName</code>. If <code>null</code>
142      * the name will be retrieved from the underlying VM.
143      * @param process the process to associate with the debug target,
144      * which will be returned from <code>IDebugTarget.getProcess</code>
145      * @param allowTerminate whether the target will support termination
146      * @param allowDisconnect whether the target will support disconnection
147      * @param resume whether the target is to be resumed on startup. Has
148      * no effect if the target was already running when the connection
149      * to the VM was established.
150      * @return a debug target
151      * @see org.eclipse.debug.core.model.ITerminate
152      * @see org.eclipse.debug.core.model.IDisconnect
153      * @since 2.0
154      */

155     public static IDebugTarget newDebugTarget(final ILaunch launch, final VirtualMachine vm, final String JavaDoc 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     /**
171      * Returns the identifier for the JDI debug model plug-in
172      *
173      * @return plug-in identifier
174      */

175     public static String JavaDoc getPluginIdentifier() {
176         return JDIDebugPlugin.getUniqueIdentifier();
177     }
178     
179     /**
180      * Registers the given listener for hot code replace notifications. Has no
181      * effect if an identical listener is already registered.
182      *
183      * @param listener hot code replace listener
184      * @see IJavaHotCodeReplaceListener
185      * @since 2.0
186      */

187     public static void addHotCodeReplaceListener(IJavaHotCodeReplaceListener listener) {
188         JDIDebugPlugin.getDefault().addHotCodeReplaceListener(listener);
189     }
190         
191     /**
192      * Unregisters the given listener for hot code replace notifications. Has no
193      * effect if an identical listener is not already registered.
194      *
195      * @param listener hot code replace listener
196      * @see IJavaHotCodeReplaceListener
197      * @since 2.0
198      */

199     public static void removeHotCodeReplaceListener(IJavaHotCodeReplaceListener listener) {
200         JDIDebugPlugin.getDefault().removeHotCodeReplaceListener(listener);
201     }
202     
203     /**
204      * Registers the given listener for breakpoint notifications. Has no
205      * effect if an identical listener is already registered.
206      *
207      * @param listener breakpoint listener
208      * @see IJavaBreakpointListener
209      * @since 2.0
210      */

211     public static void addJavaBreakpointListener(IJavaBreakpointListener listener) {
212         JDIDebugPlugin.getDefault().addJavaBreakpointListener(listener);
213     }
214
215     /**
216      * Unregisters the given listener for breakpoint notifications. Has no
217      * effect if an identical listener is not already registered.
218      *
219      * @param listener breakpoint listener
220      * @see IJavaBreakpointListener
221      * @since 2.0
222      */

223     public static void removeJavaBreakpointListener(IJavaBreakpointListener listener) {
224         JDIDebugPlugin.getDefault().removeJavaBreakpointListener(listener);
225     }
226     
227     
228     /**
229      * Creates and returns a line breakpoint in the type with the
230      * given name, at the given line number. The marker associated with the
231      * breakpoint will be created on the specified resource. If a character
232      * range within the line is known, it may be specified by charStart/charEnd.
233      * If hitCount is > 0, the breakpoint will suspend execution when it is
234      * "hit" the specified number of times.
235      *
236      * @param resource the resource on which to create the associated breakpoint
237      * marker
238      * @param typeName the fully qualified name of the type the breakpoint is
239      * to be installed in. If the breakpoint is to be installed in an inner type,
240      * it is sufficient to provide the name of the top level enclosing type.
241      * If an inner class name is specified, it should be formatted as the
242      * associated class file name (i.e. with <code>$</code>). For example,
243      * <code>example.SomeClass$InnerType</code>, could be specified, but
244      * <code>example.SomeClass</code> is sufficient.
245      * @param lineNumber the lineNumber on which the breakpoint is set - line
246      * numbers are 1 based, associated with the source file in which
247      * the breakpoint is set
248      * @param charStart the first character index associated with the breakpoint,
249      * or -1 if unspecified, in the source file in which the breakpoint is set
250      * @param charEnd the last character index associated with the breakpoint,
251      * or -1 if unspecified, in the source file in which the breakpoint is set
252      * @param hitCount the number of times the breakpoint will be hit before
253      * suspending execution - 0 if it should always suspend
254      * @param register whether to add this breakpoint to the breakpoint manager
255      * @param attributes a map of client defined attributes that should be assigned
256      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
257      * @return a line breakpoint
258      * @exception CoreException If this method fails. Reasons include:<ul>
259      *<li>Failure creating underlying marker. The exception's status contains
260      * the underlying exception responsible for the failure.</li></ul>
261      * @since 2.0
262      */

263     public static IJavaLineBreakpoint createLineBreakpoint(IResource resource, String JavaDoc typeName, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
264         if (attributes == null) {
265             attributes = new HashMap JavaDoc(10);
266         }
267         return new JavaLineBreakpoint(resource, typeName, lineNumber, charStart, charEnd, hitCount, register, attributes);
268     }
269     
270     /**
271      * Creates and returns a pattern breakpoint for the given resource at the
272      * given line number, which is installed in all classes whose fully
273      * qualified name matches the given pattern.
274      * If hitCount > 0, the breakpoint will suspend execution when it is
275      * "hit" the specified number of times.
276      *
277      * @param resource the resource on which to create the associated breakpoint
278      * marker
279      * @param sourceName the name of the source file in which the breakpoint is
280      * set, or <code>null</code>. When specified, the pattern breakpoint will
281      * install itself in classes that have a source file name debug attribute
282      * that matches this value, and satisfies the class name pattern.
283      * @param pattern the class name pattern in which the pattern breakpoint should
284      * be installed. The pattern breakpoint will install itself in every class which
285      * matches the pattern.
286      * @param lineNumber the lineNumber on which the breakpoint is set - line
287      * numbers are 1 based, associated with the source file in which
288      * the breakpoint is set
289      * @param charStart the first character index associated with the breakpoint,
290      * or -1 if unspecified, in the source file in which the breakpoint is set
291      * @param charEnd the last character index associated with the breakpoint,
292      * or -1 if unspecified, in the source file in which the breakpoint is set
293      * @param hitCount the number of times the breakpoint will be hit before
294      * suspending execution - 0 if it should always suspend
295      * @param register whether to add this breakpoint to the breakpoint manager
296      * @param attributes a map of client defined attributes that should be assigned
297      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
298      * @return a pattern breakpoint
299      * @exception CoreException If this method fails. Reasons include:<ul>
300      *<li>Failure creating underlying marker. The exception's status contains
301      * the underlying exception responsible for the failure.</li></ul>
302      * @deprecated use <code>createStratumBreakpoint</code> instead
303      */

304     public static IJavaPatternBreakpoint createPatternBreakpoint(IResource resource, String JavaDoc sourceName, String JavaDoc pattern, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
305         if (attributes == null) {
306             attributes = new HashMap JavaDoc(10);
307         }
308         return new JavaPatternBreakpoint(resource, sourceName, pattern, lineNumber, charStart, charEnd, hitCount, register, attributes);
309     }
310     
311     /**
312      * Creates and returns a line breakpoint identified by its source file
313      * name and/or path, and stratum that it is relative to.
314      *
315      * @param resource the resource on which to create the associated breakpoint
316      * marker
317      * @param stratum the stratum in which the source name, source path and line number
318      * are relative, or <code>null</code>. If <code>null</code> or if the specified stratum
319      * is not defined for a type, the source name, source path and line number are
320      * relative to the type's default stratum.
321      * @param sourceName the simple name of the source file in which the breakpoint is
322      * set, or <code>null</code>. The breakpoint will install itself in classes that have a source
323      * file name debug attribute that matches this value in the specified stratum,
324      * and satisfies the class name pattern and source path attribute. When <code>null</code>,
325      * the source file name debug attribute is not considered.
326      * @param sourcePath the qualified source file name in which the breakpoint is
327      * set, or <code>null</code>. The breakpoint will install itself in classes that
328      * have a source file path in the specified stratum that matches this value, and
329      * satisfies the class name pattern and source name attribute. When <code>null</code>,
330      * the source path attribute is not considered.
331      * @param classNamePattern the class name pattern to which the breakpoint should
332      * be restricted, or <code>null</code>. The breakpoint will install itself in each type that
333      * matches this class name pattern, with a satisfying source name and source path.
334      * Patterns may begin or end with '*', which matches 0 or more characters. A pattern that
335      * does not contain a '*' is equivalent to a pattern ending in '*'. Specifying <code>null</code>,
336      * or an empty string is the equivalent to "*". Multiple patterns can be specified
337      * by delimiting the patterns with a comma - e.g. "x.y.z,a.b.c". When multiple patterns
338      * are specified, The breakpoint will install itself in each of the types that
339      * match any of the specified class pattern, with a satisfying source name and source path.
340      * @param lineNumber the lineNumber on which the breakpoint is set - line
341      * numbers are 1 based, associated with the source file (stratum) in which
342      * the breakpoint is set
343      * @param charStart the first character index associated with the breakpoint,
344      * or -1 if unspecified, in the source file in which the breakpoint is set
345      * @param charEnd the last character index associated with the breakpoint,
346      * or -1 if unspecified, in the source file in which the breakpoint is set
347      * @param hitCount the number of times the breakpoint will be hit before
348      * suspending execution - 0 if it should always suspend
349      * @param register whether to add this breakpoint to the breakpoint manager
350      * @param attributes a map of client defined attributes that should be assigned
351      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
352      * @return a stratum breakpoint
353      * @exception CoreException If this method fails. Reasons include:<ul>
354      *<li>Failure creating underlying marker. The exception's status contains
355      * the underlying exception responsible for the failure.</li></ul>
356      * @since 3.0
357      */

358     public static IJavaStratumLineBreakpoint createStratumBreakpoint(IResource resource, String JavaDoc stratum, String JavaDoc sourceName, String JavaDoc sourcePath, String JavaDoc classNamePattern, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
359         if (attributes == null) {
360             attributes = new HashMap JavaDoc(10);
361         }
362         return new JavaStratumLineBreakpoint(resource, stratum, sourceName, sourcePath, classNamePattern, lineNumber, charStart, charEnd, hitCount, register, attributes);
363     }
364     
365     /**
366      * Creates and returns a target pattern breakpoint for the given resource at the
367      * given line number. Clients must set the class name pattern per target for
368      * this type of breakpoint.
369      * If hitCount > 0, the breakpoint will suspend execution when it is
370      * "hit" the specified number of times.
371      *
372      * @param resource the resource on which to create the associated breakpoint
373      * marker
374      * @param sourceName the name of the source file in which the breakpoint is
375      * set, or <code>null</code>. When specified, the pattern breakpoint will
376      * install itself in classes that have a source file name debug attribute
377      * that matches this value, and satisfies the class name pattern.
378      * @param lineNumber the lineNumber on which the breakpoint is set - line
379      * numbers are 1 based, associated with the source file in which
380      * the breakpoint is set
381      * @param charStart the first character index associated with the breakpoint,
382      * or -1 if unspecified, in the source file in which the breakpoint is set
383      * @param charEnd the last character index associated with the breakpoint,
384      * or -1 if unspecified, in the source file in which the breakpoint is set
385      * @param hitCount the number of times the breakpoint will be hit before
386      * suspending execution - 0 if it should always suspend
387      * @param register whether to add this breakpoint to the breakpoint manager
388      * @param attributes a map of client defined attributes that should be assigned
389      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
390      * @return a target pattern breakpoint
391      * @exception CoreException If this method fails. Reasons include:<ul>
392      *<li>Failure creating underlying marker. The exception's status contains
393      * the underlying exception responsible for the failure.</li></ul>
394      */

395     public static IJavaTargetPatternBreakpoint createTargetPatternBreakpoint(IResource resource, String JavaDoc sourceName, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
396         if (attributes == null) {
397             attributes = new HashMap JavaDoc(10);
398         }
399         return new JavaTargetPatternBreakpoint(resource, sourceName, lineNumber, charStart, charEnd, hitCount, register, attributes);
400     }
401         
402     /**
403      * Creates and returns an exception breakpoint for an exception with the given name.
404      * The marker associated with the breakpoint will be created on the specified resource.
405      * Caught and uncaught specify where the exception
406      * should cause thread suspensions - that is, in caught and/or uncaught locations.
407      * Checked indicates if the given exception is a checked exception.
408      *
409      * @param resource the resource on which to create the associated
410      * breakpoint marker
411      * @param exceptionName the fully qualified name of the exception for
412      * which to create the breakpoint
413      * @param caught whether to suspend in caught locations
414      * @param uncaught whether to suspend in uncaught locations
415      * @param checked whether the exception is a checked exception (i.e. compiler
416      * detected)
417      * @param register whether to add this breakpoint to the breakpoint manager
418      * @param attributes a map of client defined attributes that should be assigned
419      * to the underlying breakpoint marker on creation or <code>null</code> if none.
420      * @return an exception breakpoint
421      * @exception CoreException If this method fails. Reasons include:<ul>
422      *<li>Failure creating underlying marker. The exception's status contains
423      * the underlying exception responsible for the failure.</li></ul>
424      * @since 2.0
425      */

426     public static IJavaExceptionBreakpoint createExceptionBreakpoint(IResource resource, String JavaDoc exceptionName, boolean caught, boolean uncaught, boolean checked, boolean register, Map JavaDoc attributes) throws CoreException {
427         if (attributes == null) {
428             attributes = new HashMap JavaDoc(10);
429         }
430         return new JavaExceptionBreakpoint(resource, exceptionName, caught, uncaught, checked, register, attributes);
431     }
432
433     /**
434      * Creates and returns a watchpoint on a field with the given name
435      * in a type with the given name.
436      * The marker associated with the breakpoint will be created on the specified resource.
437      * If hitCount > 0, the breakpoint will suspend execution when it is
438      * "hit" the specified number of times.
439      *
440      * @param resource the resource on which to create the associated breakpoint
441      * marker
442      * @param typeName the fully qualified name of the type the breakpoint is
443      * to be installed in. If the breakpoint is to be installed in an inner type,
444      * it is sufficient to provide the name of the top level enclosing type.
445      * If an inner class name is specified, it should be formatted as the
446      * associated class file name (i.e. with <code>$</code>). For example,
447      * <code>example.SomeClass$InnerType</code>, could be specified, but
448      * <code>example.SomeClass</code> is sufficient.
449      * @param fieldName the name of the field on which to suspend (on access or modification)
450      * @param lineNumber the lineNumber on which the breakpoint is set - line
451      * numbers are 1 based, associated with the source file in which
452      * the breakpoint is set
453      * @param charStart the first character index associated with the breakpoint,
454      * or -1 if unspecified, in the source file in which the breakpoint is set
455      * @param charEnd the last character index associated with the breakpoint,
456      * or -1 if unspecified, in the source file in which the breakpoint is set
457      * @param hitCount the number of times the breakpoint will be hit before
458      * suspending execution - 0 if it should always suspend
459      * @param register whether to add this breakpoint to the breakpoint manager
460      * @param attributes a map of client defined attributes that should be assigned
461      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
462      * @return a watchpoint
463      * @exception CoreException If this method fails. Reasons include:<ul>
464      *<li>Failure creating underlying marker. The CoreException's status contains
465      * the underlying exception responsible for the failure.</li></ul>
466      * @since 2.0
467      */

468     public static IJavaWatchpoint createWatchpoint(IResource resource, String JavaDoc typeName, String JavaDoc fieldName, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
469         if (attributes == null) {
470             attributes = new HashMap JavaDoc(10);
471         }
472         return new JavaWatchpoint(resource, typeName, fieldName, lineNumber, charStart, charEnd, hitCount, register, attributes);
473     }
474     
475     /**
476      * Creates and returns a method breakpoint with the specified
477      * criteria.
478      *
479      * @param resource the resource on which to create the associated
480      * breakpoint marker
481      * @param typePattern the pattern specifying the fully qualified name of type(s)
482      * this breakpoint suspends execution in. Patterns are limited to exact
483      * matches and patterns that begin or end with '*'.
484      * @param methodName the name of the method(s) this breakpoint suspends
485      * execution in, or <code>null</code> if this breakpoint does
486      * not suspend execution based on method name
487      * @param methodSignature the signature of the method(s) this breakpoint suspends
488      * execution in, or <code>null</code> if this breakpoint does not
489      * suspend execution based on method signature
490      * @param entry whether this breakpoint causes execution to suspend
491      * on entry of methods
492      * @param exit whether this breakpoint causes execution to suspend
493      * on exit of methods
494      * @param nativeOnly whether this breakpoint causes execution to suspend
495      * on entry/exit of native methods only
496      * @param lineNumber the lineNumber on which the breakpoint is set - line
497      * numbers are 1 based, associated with the source file in which
498      * the breakpoint is set
499      * @param charStart the first character index associated with the breakpoint,
500      * or -1 if unspecified, in the source file in which the breakpoint is set
501      * @param charEnd the last character index associated with the breakpoint,
502      * or -1 if unspecified, in the source file in which the breakpoint is set
503      * @param hitCount the number of times the breakpoint will be hit before
504      * suspending execution - 0 if it should always suspend
505      * @param register whether to add this breakpoint to the breakpoint manager
506      * @param attributes a map of client defined attributes that should be assigned
507      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
508      * @return a method breakpoint
509      * @exception CoreException If this method fails. Reasons include:<ul>
510      *<li>Failure creating underlying marker. The exception's status contains
511      * the underlying exception responsible for the failure.</li></ul>
512      * @since 2.0
513      */

514     public static IJavaMethodBreakpoint createMethodBreakpoint(IResource resource, String JavaDoc typePattern, String JavaDoc methodName, String JavaDoc methodSignature, boolean entry, boolean exit, boolean nativeOnly, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
515         if (attributes == null) {
516             attributes = new HashMap JavaDoc(10);
517         }
518         return new JavaMethodBreakpoint(resource, typePattern, methodName, methodSignature, entry, exit, nativeOnly, lineNumber, charStart, charEnd, hitCount, register, attributes);
519     }
520     
521     /**
522      * Creates and returns a method entry breakpoint with the specified
523      * criteria. A method entry breakpoint will only be installed for methods
524      * that have executable code (i.e. will not work for native methods).
525      *
526      * @param resource the resource on which to create the associated
527      * breakpoint marker
528      * @param typeName the fully qualified name of type
529      * this breakpoint suspends execution in.
530      * @param methodName the name of the method this breakpoint suspends
531      * execution in
532      * @param methodSignature the signature of the method this breakpoint suspends
533      * execution in
534      * @param lineNumber the lineNumber on which the breakpoint is set - line
535      * numbers are 1 based, associated with the source file in which
536      * the breakpoint is set
537      * @param charStart the first character index associated with the breakpoint,
538      * or -1 if unspecified, in the source file in which the breakpoint is set
539      * @param charEnd the last character index associated with the breakpoint,
540      * or -1 if unspecified, in the source file in which the breakpoint is set
541      * @param hitCount the number of times the breakpoint will be hit before
542      * suspending execution - 0 if it should always suspend
543      * @param register whether to add this breakpoint to the breakpoint manager
544      * @param attributes a map of client defined attributes that should be assigned
545      * to the underlying breakpoint marker on creation, or <code>null</code> if none.
546      * @return a method entry breakpoint
547      * @exception CoreException If this method fails. Reasons include:<ul>
548      *<li>Failure creating underlying marker. The exception's status contains
549      * the underlying exception responsible for the failure.</li></ul>
550      * @since 2.0
551      */

552     public static IJavaMethodEntryBreakpoint createMethodEntryBreakpoint(IResource resource, String JavaDoc typeName, String JavaDoc methodName, String JavaDoc methodSignature, int lineNumber, int charStart, int charEnd, int hitCount, boolean register, Map JavaDoc attributes) throws CoreException {
553         if (attributes == null) {
554             attributes = new HashMap JavaDoc(10);
555         }
556         return new JavaMethodEntryBreakpoint(resource, typeName, methodName, methodSignature, lineNumber, charStart, charEnd, hitCount, register, attributes);
557     }
558         
559     /**
560      * Returns a Java line breakpoint that is already registered with the breakpoint
561      * manager for a type with the given name at the given line number.
562      *
563      * @param typeName fully qualified type name
564      * @param lineNumber line number
565      * @return a Java line breakpoint that is already registered with the breakpoint
566      * manager for a type with the given name at the given line number or <code>null</code>
567      * if no such breakpoint is registered
568      * @exception CoreException if unable to retrieve the associated marker
569      * attributes (line number).
570      */

571     public static IJavaLineBreakpoint lineBreakpointExists(String JavaDoc typeName, int lineNumber) throws CoreException {
572         String JavaDoc modelId= getPluginIdentifier();
573         String JavaDoc 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 JavaDoc 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     /**
595      * Returns a Java line breakpoint that is already registered with the breakpoint
596      * manager for a type with the given name at the given line number in the given resource.
597      *
598      * @param resource the resource
599      * @param typeName fully qualified type name
600      * @param lineNumber line number
601      * @return a Java line breakpoint that is already registered with the breakpoint
602      * manager for a type with the given name at the given line number or <code>null</code>
603      * if no such breakpoint is registered
604      * @exception CoreException if unable to retrieve the associated marker
605      * attributes (line number).
606      * @since 3.1
607      */

608     public static IJavaLineBreakpoint lineBreakpointExists(IResource resource, String JavaDoc typeName, int lineNumber) throws CoreException {
609         String JavaDoc modelId= getPluginIdentifier();
610         String JavaDoc 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 JavaDoc 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     /**
632      * Returns the preference store for this plug-in or <code>null</code>
633      * if the store is not available.
634      *
635      * @return the preference store for this plug-in
636      * @since 2.0
637      */

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     /**
647      * Saves the preference store for this plug-in.
648      *
649      * @since 2.0
650      */

651     public static void savePreferences() {
652         JDIDebugPlugin.getDefault().savePluginPreferences();
653     }
654     
655     /**
656      * Creates and returns a class prepare breakpoint for a type with the given name.
657      * The marker associated with the breakpoint will be created on the specified resource.
658      *
659      * @param resource the resource on which to create the associated
660      * breakpoint marker
661      * @param typeName the fully qualified name of the type for
662      * which to create the breakpoint
663      * @param memberType one of <code>TYPE_CLASS</code> or <code>TYPE_INTERFACE</code>
664      * @param charStart the first character index associated with the breakpoint,
665      * or -1 if unspecified, in the source file in which the breakpoint is set
666      * @param charEnd the last character index associated with the breakpoint,
667      * or -1 if unspecified, in the source file in which the breakpoint is set
668      * @param register whether to add this breakpoint to the breakpoint manager
669      * @param attributes a map of client defined attributes that should be assigned
670      * to the underlying breakpoint marker on creation or <code>null</code> if none.
671      * @return a class prepare breakpoint
672      * @exception CoreException If this method fails. Reasons include:<ul>
673      *<li>Failure creating underlying marker. The exception's status contains
674      * the underlying exception responsible for the failure.</li></ul>
675      * @since 3.0
676      */

677     public static IJavaClassPrepareBreakpoint createClassPrepareBreakpoint(IResource resource, String JavaDoc typeName, int memberType, int charStart, int charEnd, boolean register, Map JavaDoc attributes) throws CoreException {
678         if (attributes == null) {
679             attributes = new HashMap JavaDoc(10);
680         }
681         return new JavaClassPrepareBreakpoint(resource, typeName, memberType, charStart, charEnd, register, attributes);
682     }
683 }
684
Popular Tags