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.IResource;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.Preferences;
23 import org.eclipse.debug.core.DebugPlugin;
24 import org.eclipse.debug.core.IBreakpointManager;
25 import org.eclipse.debug.core.model.IBreakpoint;
28 * Provides utility methods for creating debug targets and breakpoints specific
29 * to the PHP debug model.
31 * Clients are not intended to instantiate or subclass this class; this class
32 * provides static utility methods only.
35 public class PHPDebugModel {
38 * Not to be instantiated.
40 private PHPDebugModel() {
45 * Returns the identifier for the PHP debug model plug-in
47 * @return plugin identifier
49 // public static String getPluginIdentifier() {
50 // return PHPDebugCorePlugin.getUniqueIdentifier();
53 * Creates and returns a line breakpoint in the type with at the given line
54 * number. The marker associated with the breakpoint will be created on the
55 * specified resource. If a character range within the line is known, it may
56 * be specified by charStart/charEnd. If hitCount is > 0, the breakpoint
57 * will suspend execution when it is "hit" the specified number of times.
60 * the resource on which to create the associated breakpoint
63 * the lineNumber on which the breakpoint is set - line numbers
64 * are 1 based, associated with the source file in which the
67 * the first character index associated with the breakpoint, or
68 * -1 if unspecified, in the source file in which the breakpoint
71 * the last character index associated with the breakpoint, or -1
72 * if unspecified, in the source file in which the breakpoint is
75 * the number of times the breakpoint will be hit before
76 * suspending execution - 0 if it should always suspend
78 * whether to add this breakpoint to the breakpoint manager
80 * a map of client defined attributes that should be assigned to
81 * the underlying breakpoint marker on creation, or
82 * <code>null</code> if none.
83 * @return a line breakpoint
84 * @exception CoreException
85 * If this method fails. Reasons include:
87 * <li>Failure creating underlying marker. The exception's
88 * status contains the underlying exception responsible for
93 public static void createLineBreakpoint(IResource resource, int lineNumber,
94 int charStart, int charEnd, int hitCount, boolean register,
95 Map attributes) throws CoreException {
96 if (attributes == null) {
97 attributes = new HashMap(10);
99 new PHPLineBreakpoint(resource, lineNumber, charStart, charEnd,
100 hitCount, true, attributes);
103 public static PHPLineBreakpoint createLineBreakpoint(IResource resource,
104 int lineNumber, int hitCount, boolean register, Map attributes)
105 throws CoreException {
106 if (attributes == null) {
107 attributes = new HashMap(10);
109 return new PHPLineBreakpoint(resource, lineNumber, hitCount, true,
114 * Returns true if line breakpoint is already registered with the breakpoint
115 * manager for the given line number.
118 * fully qualified type name
121 * @return true if line breakpoint is already registered with the breakpoint
122 * manager for the given line number or <code>false</code> if no
123 * such breakpoint is registered
124 * @exception CoreException
125 * If this method fails.
127 public static PHPLineBreakpoint lineBreakpointExists(int lineNumber)
128 throws CoreException {
129 String modelId = PHPDebugCorePlugin.PLUGIN_ID; // getPluginIdentifier();
130 String markerType = PHPLineBreakpoint.getMarkerType();
131 IBreakpointManager manager = DebugPlugin.getDefault()
132 .getBreakpointManager();
133 IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
134 for (int i = 0; i < breakpoints.length; i++) {
135 if (!(breakpoints[i] instanceof PHPLineBreakpoint)) {
138 PHPLineBreakpoint breakpoint = (PHPLineBreakpoint) breakpoints[i];
139 if (breakpoint.getMarker().getType().equals(markerType)) {
140 if (breakpoint.getLineNumber() == lineNumber) {
149 * Returns the preference store for this plug-in or <code>null</code> if
150 * the store is not available.
152 * @return the preference store for this plug-in
154 public static Preferences getPreferences() {
155 PHPDebugCorePlugin deflt = PHPDebugCorePlugin.getDefault();
157 return deflt.getPluginPreferences();
163 * Saves the preference store for this plug-in.
165 * @return the preference store for this plug-in
167 public static void savePreferences() {
168 PHPDebugCorePlugin.getDefault().savePluginPreferences();
172 * Creates and returns a debug target for the given VM, with the specified
173 * name, and associates the debug target with the given process for console
174 * I/O. The allow terminate flag specifies whether the debug target will
175 * support termination (<code>ITerminate</code>). The allow disconnect
176 * flag specifies whether the debug target will support disconnection (<code>IDisconnect</code>).
177 * The resume flag specifies if the target VM should be resumed on startup
178 * (has no effect if the VM was already running when the connection to the
179 * VM was esatbished). Launching the actual VM is a client responsibility.
180 * The debug target is added to the given launch.
183 * the launch the new debug target will be contained in
185 * the VM to create a debug target for
187 * the name to associate with the VM, which will be returned from
188 * <code>IDebugTarget.getName</code>. If <code>null</code>
189 * the name will be retrieved from the underlying VM.
191 * the process to associate with the debug target, which will be
192 * returned from <code>IDebugTarget.getProcess</code>
193 * @param allowTerminate
194 * whether the target will support termianation
195 * @param allowDisconnect
196 * whether the target will support disconnection
198 * whether the target is to be resumed on startup. Has no effect
199 * if the target was already running when the connection to the
200 * VM was established.
201 * @return a debug target
202 * @see org.eclipse.debug.core.model.ITerminate
203 * @see org.eclipse.debug.core.model.IDisconnect
207 * public static IDebugTarget newDebugTarget(final ILaunch launch, final
208 * String name, final IProcess process) { final IDebugTarget[] target = new
209 * IDebugTarget[1]; IWorkspaceRunnable r = new IWorkspaceRunnable() { public
210 * void run(IProgressMonitor m) { target[0]= new PHPDebugTarget(launch,
211 * process); } }; try { ResourcesPlugin.getWorkspace().run(r, null); } catch
212 * (CoreException e) { //PHPDebugPlugin.log(e); } return target[0]; }