1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpdt.debug.core;
14 import java.util.HashMap;
17 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
18 import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
20 import org.eclipse.core.resources.IMarker;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.runtime.CoreException;
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.model.IBreakpoint;
29 * Provides utility methods for creating debug targets and breakpoints specific
30 * to the PHP debug model.
32 * Clients are not intended to instantiate or subclass this class; this class
33 * provides static utility methods only.
36 public class PHPDebugModel {
39 * Not to be instantiated.
41 private PHPDebugModel() {
46 * Returns the identifier for the PHP debug model plug-in
48 * @return plugin identifier
50 // public static String getPluginIdentifier() {
51 // return PHPDebugCorePlugin.getUniqueIdentifier();
54 * Creates and returns a line breakpoint in the type with at the given line
55 * number. The marker associated with the breakpoint will be created on the
56 * specified resource. If a character range within the line is known, it may
57 * be specified by charStart/charEnd. If hitCount is > 0, the breakpoint
58 * will suspend execution when it is "hit" the specified number of times.
61 * the resource on which to create the associated breakpoint
64 * the lineNumber on which the breakpoint is set - line numbers
65 * are 1 based, associated with the source file in which the
68 * the first character index associated with the breakpoint, or
69 * -1 if unspecified, in the source file in which the breakpoint
72 * the last character index associated with the breakpoint, or -1
73 * if unspecified, in the source file in which the breakpoint is
76 * the number of times the breakpoint will be hit before
77 * suspending execution - 0 if it should always suspend
79 * whether to add this breakpoint to the breakpoint manager
81 * a map of client defined attributes that should be assigned to
82 * the underlying breakpoint marker on creation, or
83 * <code>null</code> if none.
84 * @return a line breakpoint
85 * @exception CoreException
86 * If this method fails. Reasons include:
88 * <li>Failure creating underlying marker. The exception's
89 * status contains the underlying exception responsible for
94 public static void createLineBreakpoint(IResource resource, int lineNumber,
95 int charStart, int charEnd, int hitCount, boolean register,
96 Map attributes) throws CoreException {
97 if (attributes == null) {
98 attributes = new HashMap(10);
100 new PHPLineBreakpoint(resource, lineNumber, charStart, charEnd,
101 hitCount, true, attributes);
104 public static PHPLineBreakpoint createLineBreakpoint(IResource resource,
105 int lineNumber, int hitCount, boolean register, Map attributes)
106 throws CoreException {
107 if (attributes == null) {
108 attributes = new HashMap(10);
110 return new PHPLineBreakpoint(resource, lineNumber, hitCount, true,
115 * Returns true if line breakpoint is already registered with the breakpoint
116 * manager for the given line number.
119 * fully qualified type name
122 * @return true if line breakpoint is already registered with the breakpoint
123 * manager for the given line number or <code>false</code> if no
124 * such breakpoint is registered
125 * @exception CoreException
126 * If this method fails.
128 public static PHPLineBreakpoint lineBreakpointExists(IResource resource, int lineNumber)
129 throws CoreException {
130 String modelId = PHPDebugCorePlugin.PLUGIN_ID; // getPluginIdentifier();
131 String markerType = PHPLineBreakpoint.getMarkerType();
132 IBreakpointManager manager = DebugPlugin.getDefault()
133 .getBreakpointManager();
134 IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
135 for (int i = 0; i < breakpoints.length; i++) {
136 if (!(breakpoints[i] instanceof PHPLineBreakpoint)) {
139 PHPLineBreakpoint breakpoint = (PHPLineBreakpoint) breakpoints[i];
140 if (breakpoint.getLineNumber() == lineNumber) {
141 if (breakpoint.getMarker().getResource().equals(resource)) {
150 * Returns the preference store for this plug-in or <code>null</code> if
151 * the store is not available.
153 * @return the preference store for this plug-in
155 public static Preferences getPreferences() {
156 PHPDebugCorePlugin deflt = PHPDebugCorePlugin.getDefault();
158 return deflt.getPluginPreferences();
164 * Saves the preference store for this plug-in.
166 * @return the preference store for this plug-in
168 public static void savePreferences() {
169 PHPDebugCorePlugin.getDefault().savePluginPreferences();
173 * Creates and returns a debug target for the given VM, with the specified
174 * name, and associates the debug target with the given process for console
175 * I/O. The allow terminate flag specifies whether the debug target will
176 * support termination (<code>ITerminate</code>). The allow disconnect
177 * flag specifies whether the debug target will support disconnection (<code>IDisconnect</code>).
178 * The resume flag specifies if the target VM should be resumed on startup
179 * (has no effect if the VM was already running when the connection to the
180 * VM was esatbished). Launching the actual VM is a client responsibility.
181 * The debug target is added to the given launch.
184 * the launch the new debug target will be contained in
186 * the VM to create a debug target for
188 * the name to associate with the VM, which will be returned from
189 * <code>IDebugTarget.getName</code>. If <code>null</code>
190 * the name will be retrieved from the underlying VM.
192 * the process to associate with the debug target, which will be
193 * returned from <code>IDebugTarget.getProcess</code>
194 * @param allowTerminate
195 * whether the target will support termianation
196 * @param allowDisconnect
197 * whether the target will support disconnection
199 * whether the target is to be resumed on startup. Has no effect
200 * if the target was already running when the connection to the
201 * VM was established.
202 * @return a debug target
203 * @see org.eclipse.debug.core.model.ITerminate
204 * @see org.eclipse.debug.core.model.IDisconnect
208 * public static IDebugTarget newDebugTarget(final ILaunch launch, final
209 * String name, final IProcess process) { final IDebugTarget[] target = new
210 * IDebugTarget[1]; IWorkspaceRunnable r = new IWorkspaceRunnable() { public
211 * void run(IProgressMonitor m) { target[0]= new PHPDebugTarget(launch,
212 * process); } }; try { ResourcesPlugin.getWorkspace().run(r, null); } catch
213 * (CoreException e) { //PHPDebugPlugin.log(e); } return target[0]; }