A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / breakpoints / PHPBreakpoint.java
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
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  Vicente Fernando - www.alfersoft.com.ar
11  **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core.breakpoints;
13
14 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
15
16 import org.eclipse.core.resources.IMarker;
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.debug.core.DebugException;
21 import org.eclipse.debug.core.DebugPlugin;
22 import org.eclipse.debug.core.model.Breakpoint;
23 import org.eclipse.debug.core.model.IBreakpoint;
24
25 /**
26  * A breakpoint is capable of suspending the execution of a program at a
27  * specific location when a program is running in debug mode. Each breakpoint
28  * has an associated marker which stores and persists all attributes associated
29  * with a breakpoint.
30  * <p>
31  * A breakpoint is defined in two parts:
32  * <ol>
33  * <li>By an extension of kind
34  * <code>"org.eclipse.debug.core.breakpoints"</code></li>
35  * <li>By a marker definition that corresponds to the above breakpoint
36  * extension</li>
37  * </ol>
38  * <p>
39  * For example, following is a definition of corresponding breakpoint and
40  * breakpoint marker definitions. Note that the <code>markerType</code>
41  * attribute defined by the breakpoint extension corresponds to the type of the
42  * marker definition.
43  * 
44  * <pre>
45  *  &lt;extension point=&quot;org.eclipse.debug.core.breakpoints&quot;&gt;
46  *    &lt;breakpoint 
47  *       id=&quot;com.example.Breakpoint&quot;
48  *       class=&quot;com.example.Breakpoint&quot;
49  *       markerType=&quot;com.example.BreakpointMarker&quot;&gt;
50  *    &lt;/breakpoint&gt;
51  *  &lt;/extension&gt;
52  *  &lt;extension point=&quot;org.eclipse.core.resources.markers&quot;&gt;
53  *    &lt;marker 
54  *       id=&quot;com.example.BreakpointMarker&quot;
55  *       super type=&quot;org.eclipse.debug.core.breakpointMarker&quot;
56  *       attribute name =&quot;exampleAttribute&quot;&gt;
57  *    &lt;/marker&gt;
58  *  &lt;/extension&gt;
59  * </pre>
60  * 
61  * <p>
62  * The breakpoint manager instantiates persisted breakpoints by traversing all
63  * markers that are a subtype of
64  * <code>"org.eclipse.debug.core.breakpointMarker"</code>, and instantiating
65  * the class defined by the <code>class</code> attribute on the associated
66  * breakpoint extension. The method <code>setMarker</code> is then called to
67  * associate a marker with the breakpoint.
68  * </p>
69  * <p>
70  * Breakpoints may or may not be registered with the breakpoint manager, and are
71  * persisted and restored as such. Since marker definitions only allow all or
72  * none of a specific marker type to be persisted, breakpoints define a
73  * <code>PERSISTED</code> attribute for selective persistence of breakpoints
74  * of the same type.
75  * </p>
76  * 
77  * @since 2.0
78  */
79
80 public abstract class PHPBreakpoint extends Breakpoint implements IBreakpoint {
81
82         /**
83          * Breakpoint attribute storing a breakpoint's hit count value (value
84          * <code>"net.sourceforge.phpeclipse.debug.hitCount"</code>). This
85          * attribute is stored as an <code>int</code>.
86          * 
87          * For DBG the hit count is really a skip count. Explanation: A hit count of
88          * e.g. 4 would break on the fourth occurence of the breakpoint. A skip
89          * count means skip the first four occurences of the breakpoint, and break
90          * on the fifth occurence.
91          */
92         protected static final String HIT_COUNT = "net.sourceforge.phpeclipse.debug.hitCount"; //$NON-NLS-1$
93
94         /**
95          * Breakpoint attribute storing a breakpoint's changeID. This is used for
96          * checking whether the breakpoint properties menu was finished with a
97          * OK-button. Which means a possible change of breakpoint condition or skip
98          * count. This is necessary because in method breakpointChanged in class
99          * PHPDebugTarget we need to know, whether the breakpoint has changed or not
100          * (breakpointChanged is called also when a PHP source file is modified and
101          * saved).
102          */
103         protected static final String CHANGE_ID = "net.sourceforge.phpeclipse.debug.changeID"; //$NON-NLS-1$
104
105         /**
106          * Breakpoint attribute storing a breakpoint's condition (value
107          * <code>"net.sourceforge.phpeclipse.debug.condition"</code>). This
108          * attribute is stored as an <code>string</code>.
109          */
110         protected static final String CONDITION = "net.sourceforge.phpeclipse.debug.condition"; //$NON-NLS-1$
111
112         /**
113          * Breakpoint attribute storing whether a breakpoint's condition is enabled
114          * or not (value
115          * <code>"net.sourceforge.phpeclipse.debug.conditionEnabled"</code>).
116          * This attribute is stored as an <code>boolean</code>.
117          */
118         protected static final String CONDITION_ENABLED = "net.sourceforge.phpeclipse.debug.conditionEnabled"; //$NON-NLS-1$
119
120         /**
121          * Breakpoint attribute storing the fully qualified name of the type this
122          * breakpoint is located in. (value
123          * <code>"net.sourceforge.phpeclipse.debug.typeName"</code>). This
124          * attribute is a <code>String</code>.
125          */
126         protected static final String TYPE_NAME = "net.sourceforge.phpeclipse.debug.typeName"; //$NON-NLS-1$            
127
128         /**
129          * Root breakpoint marker type (value
130          * <code>"org.eclipse.debug.core.breakpoint"</code>).
131          */
132         public static final String BREAKPOINT_MARKER = DebugPlugin
133                         .getUniqueIdentifier()
134                         + ".breakpointMarker"; //$NON-NLS-1$
135
136         /**
137          * Line breakpoint marker type (value
138          * <code>"org.eclipse.debug.core.lineBreakpoint"</code>).
139          */
140         public static final String LINE_BREAKPOINT_MARKER = DebugPlugin
141                         .getUniqueIdentifier()
142                         + ".lineBreakpointMarker"; //$NON-NLS-1$
143
144         /**
145          * Enabled breakpoint marker attribute (value
146          * <code>"org.eclipse.debug.core.enabled"</code>). The attribute is a
147          * <code>boolean</code> corresponding to the enabled state of a
148          * breakpoint.
149          * 
150          * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean)
151          */
152         public static final String ENABLED = "org.eclipse.debug.core.enabled"; //$NON-NLS-1$
153
154         /**
155          * Debug model identifier breakpoint marker attribute (value
156          * <code>"org.eclipse.debug.core.id"</code>). The attribute is a
157          * <code>String</code> corresponding to the identifier of the debug model
158          * a breakpoint is associated with.
159          */
160         public static final String ID = "org.eclipse.debug.core.id"; //$NON-NLS-1$
161
162         /**
163          * Registered breakpoint marker attribute (value
164          * <code>"org.eclipse.debug.core.registered"</code>). The attribute is a
165          * <code>boolean</code> corresponding to whether a breakpoint has been
166          * registered with the breakpoint manager.
167          * 
168          * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean)
169          */
170         public static final String REGISTERED = "org.eclipse.debug.core.registered"; //$NON-NLS-1$      
171
172         /**
173          * Persisted breakpoint marker attribute (value
174          * <code>"org.eclipse.debug.core.persisted"</code>). The attribute is a
175          * <code>boolean</code> corresponding to whether a breakpoint is to be
176          * persisted accross workspace invocations.
177          * 
178          * @see org.eclipse.core.resources.IMarker#getAttribute(String, boolean)
179          */
180         public static final String PERSISTED = "org.eclipse.debug.core.persisted"; //$NON-NLS-1$                
181
182         private int DBGBpNo = 0;
183
184         public PHPBreakpoint() {
185         }
186
187         /**
188          * @see IBreakpoint#setMarker(IMarker)
189          */
190         public void setMarker(IMarker marker) throws CoreException {
191                 super.setMarker(marker);
192         }
193
194         /**
195          * Add this breakpoint to the breakpoint manager, or sets it as
196          * unregistered.
197          */
198         protected void register(boolean register) throws CoreException {
199                 if (register) {
200                         DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
201                 } else {
202                         setRegistered(false);
203                 }
204         }
205
206         /**
207          * Execute the given workspace runnable
208          */
209         protected void run(IWorkspaceRunnable wr) throws DebugException {
210                 try {
211                         ResourcesPlugin.getWorkspace().run(wr, null);
212                 } catch (CoreException e) {
213                         throw new DebugException(e.getStatus());
214                 }
215         }
216
217         /**
218          * @see IBreakpoint#getModelIdentifier()
219          */
220         public String getModelIdentifier() {
221                 return PHPDebugCorePlugin.getUniqueIdentifier();
222         }
223
224         public void setDBGBpNo(int bpNo) {
225                 this.DBGBpNo = bpNo;
226         }
227
228         public int getDBGBpNo() {
229                 return this.DBGBpNo;
230         }
231
232         public int getHitCount() throws CoreException {
233                 return getMarker().getAttribute(HIT_COUNT, -1);
234         }
235
236         public void setHitCount(int hitCount) throws CoreException {
237                 if (hitCount > 0) {
238                         if (!isEnabled()) {
239                                 getMarker().setAttribute(ENABLED, true);
240                         }
241                 }
242
243                 getMarker().setAttribute(HIT_COUNT, hitCount);
244         }
245 }