/********************************************************************** Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.breakpoints; import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.Breakpoint; import org.eclipse.debug.core.model.IBreakpoint; /** * A breakpoint is capable of suspending the execution of a program at a * specific location when a program is running in debug mode. Each breakpoint * has an associated marker which stores and persists all attributes associated * with a breakpoint. *

* A breakpoint is defined in two parts: *

    *
  1. By an extension of kind * "org.eclipse.debug.core.breakpoints"
  2. *
  3. By a marker definition that corresponds to the above breakpoint * extension
  4. *
*

* For example, following is a definition of corresponding breakpoint and * breakpoint marker definitions. Note that the markerType * attribute defined by the breakpoint extension corresponds to the type of the * marker definition. * *

 *  <extension point="org.eclipse.debug.core.breakpoints">
 *    <breakpoint 
 *       id="com.example.Breakpoint"
 *       class="com.example.Breakpoint"
 *       markerType="com.example.BreakpointMarker">
 *    </breakpoint>
 *  </extension>
 *  <extension point="org.eclipse.core.resources.markers">
 *    <marker 
 *       id="com.example.BreakpointMarker"
 *       super type="org.eclipse.debug.core.breakpointMarker"
 *       attribute name ="exampleAttribute">
 *    </marker>
 *  </extension>
 * 
* *

* The breakpoint manager instantiates persisted breakpoints by traversing all * markers that are a subtype of * "org.eclipse.debug.core.breakpointMarker", and instantiating * the class defined by the class attribute on the associated * breakpoint extension. The method setMarker is then called to * associate a marker with the breakpoint. *

*

* Breakpoints may or may not be registered with the breakpoint manager, and are * persisted and restored as such. Since marker definitions only allow all or * none of a specific marker type to be persisted, breakpoints define a * PERSISTED attribute for selective persistence of breakpoints * of the same type. *

* * @since 2.0 */ public abstract class PHPBreakpoint extends Breakpoint implements IBreakpoint { /** * Breakpoint attribute storing a breakpoint's hit count value (value * "net.sourceforge.phpeclipse.debug.hitCount"). This * attribute is stored as an int. * * For DBG the hit count is really a skip count. Explanation: A hit count of * e.g. 4 would break on the fourth occurence of the breakpoint. A skip * count means skip the first four occurences of the breakpoint, and break * on the fifth occurence. */ protected static final String HIT_COUNT = "net.sourceforge.phpeclipse.debug.hitCount"; //$NON-NLS-1$ /** * Breakpoint attribute storing a breakpoint's changeID. This is used for * checking whether the breakpoint properties menu was finished with a * OK-button. Which means a possible change of breakpoint condition or skip * count. This is necessary because in method breakpointChanged in class * PHPDebugTarget we need to know, whether the breakpoint has changed or not * (breakpointChanged is called also when a PHP source file is modified and * saved). */ protected static final String CHANGE_ID = "net.sourceforge.phpeclipse.debug.changeID"; //$NON-NLS-1$ /** * Breakpoint attribute storing a breakpoint's condition (value * "net.sourceforge.phpeclipse.debug.condition"). This * attribute is stored as an string. */ protected static final String CONDITION = "net.sourceforge.phpeclipse.debug.condition"; //$NON-NLS-1$ /** * Breakpoint attribute storing whether a breakpoint's condition is enabled * or not (value * "net.sourceforge.phpeclipse.debug.conditionEnabled"). * This attribute is stored as an boolean. */ protected static final String CONDITION_ENABLED = "net.sourceforge.phpeclipse.debug.conditionEnabled"; //$NON-NLS-1$ /** * Breakpoint attribute storing the fully qualified name of the type this * breakpoint is located in. (value * "net.sourceforge.phpeclipse.debug.typeName"). This * attribute is a String. */ protected static final String TYPE_NAME = "net.sourceforge.phpeclipse.debug.typeName"; //$NON-NLS-1$ /** * Root breakpoint marker type (value * "org.eclipse.debug.core.breakpoint"). */ public static final String BREAKPOINT_MARKER = DebugPlugin .getUniqueIdentifier() + ".breakpointMarker"; //$NON-NLS-1$ /** * Line breakpoint marker type (value * "org.eclipse.debug.core.lineBreakpoint"). */ public static final String LINE_BREAKPOINT_MARKER = DebugPlugin .getUniqueIdentifier() + ".lineBreakpointMarker"; //$NON-NLS-1$ /** * Enabled breakpoint marker attribute (value * "org.eclipse.debug.core.enabled"). The attribute is a * boolean corresponding to the enabled state of a * breakpoint. * * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean) */ public static final String ENABLED = "org.eclipse.debug.core.enabled"; //$NON-NLS-1$ /** * Debug model identifier breakpoint marker attribute (value * "org.eclipse.debug.core.id"). The attribute is a * String corresponding to the identifier of the debug model * a breakpoint is associated with. */ public static final String ID = "org.eclipse.debug.core.id"; //$NON-NLS-1$ /** * Registered breakpoint marker attribute (value * "org.eclipse.debug.core.registered"). The attribute is a * boolean corresponding to whether a breakpoint has been * registered with the breakpoint manager. * * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean) */ public static final String REGISTERED = "org.eclipse.debug.core.registered"; //$NON-NLS-1$ /** * Persisted breakpoint marker attribute (value * "org.eclipse.debug.core.persisted"). The attribute is a * boolean corresponding to whether a breakpoint is to be * persisted accross workspace invocations. * * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean) */ public static final String PERSISTED = "org.eclipse.debug.core.persisted"; //$NON-NLS-1$ private int DBGBpNo = 0; public PHPBreakpoint() { } /** * @see IBreakpoint#setMarker(IMarker) */ public void setMarker(IMarker marker) throws CoreException { super.setMarker(marker); } /** * Add this breakpoint to the breakpoint manager, or sets it as * unregistered. */ protected void register(boolean register) throws CoreException { if (register) { DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this); } else { setRegistered(false); } } /** * Execute the given workspace runnable */ protected void run(IWorkspaceRunnable wr) throws DebugException { try { ResourcesPlugin.getWorkspace().run(wr, null); } catch (CoreException e) { throw new DebugException(e.getStatus()); } } /** * @see IBreakpoint#getModelIdentifier() */ public String getModelIdentifier() { return PHPDebugCorePlugin.getUniqueIdentifier(); } public void setDBGBpNo(int bpNo) { this.DBGBpNo = bpNo; } public int getDBGBpNo() { return this.DBGBpNo; } public int getHitCount() throws CoreException { return getMarker().getAttribute(HIT_COUNT, -1); } public void setHitCount(int hitCount) throws CoreException { if (hitCount > 0) { if (!isEnabled()) { getMarker().setAttribute(ENABLED, true); } } getMarker().setAttribute(HIT_COUNT, hitCount); } }