1) Added methods for conditional breakpoints and skip/hit count.
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / breakpoints / PHPLineBreakpoint.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     Vicente Fernando - Initial implementation - www.alfersoft.com.ar
10 **********************************************************************/
11 package net.sourceforge.phpdt.internal.debug.core.breakpoints;
12
13 import java.util.Map;
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.debug.core.DebugException;
21 import org.eclipse.debug.core.model.IBreakpoint;
22 import org.eclipse.debug.core.model.ILineBreakpoint;
23
24 /**
25  * A breakpoint that can be located at a specific line of source code.
26  */
27 public class PHPLineBreakpoint extends PHPBreakpoint implements IBreakpoint, ILineBreakpoint {
28
29         private static final String PHP_LINE_BREAKPOINT = "net.sourceforge.phpeclipse.debug.core.phpLineBreakpointMarker"; //$NON-NLS-1$
30
31         public PHPLineBreakpoint() {
32         }
33
34         public PHPLineBreakpoint(IResource resource, int lineNumber, int charStart, int charEnd, int hitCount, boolean add, Map attributes) throws DebugException {
35                 this(resource, lineNumber, charStart, charEnd, hitCount, add, attributes, PHP_LINE_BREAKPOINT);
36         }
37         
38         public PHPLineBreakpoint(IResource resource, int lineNumber, int hitCount, boolean add, Map attributes) throws DebugException {
39                 this(resource, lineNumber, -1, -1, hitCount, add, attributes, PHP_LINE_BREAKPOINT);
40         }
41         
42
43         protected PHPLineBreakpoint (final IResource resource, 
44                                              final int lineNumber, 
45                                              final int charStart, 
46                                              final int charEnd, 
47                                              final int hitCount, 
48                                              final boolean add, 
49                                              final Map attributes, 
50                                              final String markerType) throws DebugException {
51                 IWorkspaceRunnable wr= new IWorkspaceRunnable() {
52                         public void run(IProgressMonitor monitor) throws CoreException {
53         
54                                 // create the marker
55                                 setMarker(resource.createMarker(markerType));
56
57                                 // add attributes
58                                 addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd, hitCount);
59
60                                 // set attributes
61                                 ensureMarker().setAttributes(attributes);
62                                 
63                                 // add to breakpoint manager if requested
64                                 register(add);          
65                         }
66                 };
67                 run(wr);
68         }
69         
70
71         public void addLineBreakpointAttributes(Map attributes, String modelIdentifier, boolean enabled, int lineNumber, int charStart, int charEnd, int hitCount) {
72                 attributes.put(IBreakpoint.ID, modelIdentifier);
73                 attributes.put(IBreakpoint.ENABLED, new Boolean(enabled));
74                 attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
75                 if (charStart!=-1)
76                 {
77                         attributes.put(IMarker.CHAR_START, new Integer(charStart));
78                         attributes.put(IMarker.CHAR_END, new Integer(charEnd));
79                 }
80                 attributes.put(TYPE_NAME, "typeName"); 
81                 attributes.put(PHPBreakpoint.HIT_COUNT, new Integer(hitCount));
82                 attributes.put(PHPBreakpoint.CONDITION, new String(""));
83                 attributes.put(PHPBreakpoint.CONDITION_ENABLED, new Boolean(false));
84                 attributes.put(PHPBreakpoint.CHANGE_ID, new Integer(0));
85         }               
86
87         /**
88          * @see ILineBreakpoint#getLineNumber()
89          */
90         public int getLineNumber() throws CoreException {
91                 return ensureMarker().getAttribute(IMarker.LINE_NUMBER, -1);
92         }
93
94         /**
95          * @see ILineBreakpoint#getCharStart()
96          */
97         public int getCharStart() throws CoreException {
98                 return ensureMarker().getAttribute(IMarker.CHAR_START, -1);
99         }
100
101         /**
102          * @see ILineBreakpoint#getCharEnd()
103          */
104         public int getCharEnd() throws CoreException {
105                 return ensureMarker().getAttribute(IMarker.CHAR_END, -1);
106         }
107         
108         /**
109          * Returns the type of marker associated with Java line breakpoints
110          */
111         public static String getMarkerType() {
112                 return PHP_LINE_BREAKPOINT;
113         }
114         
115         public int getHitCount() throws CoreException {
116                 return ensureMarker().getAttribute(PHPBreakpoint.HIT_COUNT, 1);
117         }
118         
119         public int getChangeID() throws CoreException {
120                 return ensureMarker().getAttribute(CHANGE_ID, 1);
121         }
122         
123         public void setChangeID(int changeID) throws CoreException {
124                 ensureMarker().setAttribute(CHANGE_ID, changeID);
125         }
126
127         public String getCondition () throws CoreException {
128                 return ensureMarker ().getAttribute (CONDITION, "");
129         }
130         
131         public void setCondition (String condition) throws CoreException {
132                 ensureMarker ().setAttribute (CONDITION, condition);
133         }
134
135         public void setConditionEnabled (boolean enabled) throws CoreException {
136                 ensureMarker ().setAttribute (CONDITION_ENABLED, enabled);
137         }
138
139         public boolean isConditionEnabled () throws CoreException {
140                 return ensureMarker ().getAttribute (CONDITION_ENABLED, false);
141         }
142 }