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 / 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,
28                 ILineBreakpoint {
29
30         private static final String PHP_LINE_BREAKPOINT = "net.sourceforge.phpeclipse.debug.core.phpLineBreakpointMarker"; //$NON-NLS-1$
31
32         public PHPLineBreakpoint() {
33         }
34
35         public PHPLineBreakpoint(IResource resource, int lineNumber, int charStart,
36                         int charEnd, int hitCount, boolean add, Map attributes)
37                         throws DebugException {
38                 this(resource, lineNumber, charStart, charEnd, hitCount, add,
39                                 attributes, PHP_LINE_BREAKPOINT);
40         }
41
42         public PHPLineBreakpoint(IResource resource, int lineNumber, int hitCount,
43                         boolean add, Map attributes) throws DebugException {
44                 this(resource, lineNumber, -1, -1, hitCount, add, attributes,
45                                 PHP_LINE_BREAKPOINT);
46         }
47
48         protected PHPLineBreakpoint(final IResource resource, final int lineNumber,
49                         final int charStart, final int charEnd, final int hitCount,
50                         final boolean add, final Map attributes, final String markerType)
51                         throws DebugException {
52                 IWorkspaceRunnable wr = new IWorkspaceRunnable() {
53                         public void run(IProgressMonitor monitor) throws CoreException {
54
55                                 // create the marker
56                                 setMarker(resource.createMarker(markerType));
57
58                                 // add attributes
59                                 addLineBreakpointAttributes(attributes, getModelIdentifier(),
60                                                 true, lineNumber, charStart, charEnd, hitCount);
61
62                                 // set attributes
63                                 ensureMarker().setAttributes(attributes);
64
65                                 // add to breakpoint manager if requested
66                                 register(add);
67                         }
68                 };
69                 run(wr);
70         }
71
72         public void addLineBreakpointAttributes(Map attributes,
73                         String modelIdentifier, boolean enabled, int lineNumber,
74                         int charStart, int charEnd, int hitCount) {
75                 attributes.put(IBreakpoint.ID, modelIdentifier);
76                 attributes.put(IBreakpoint.ENABLED, new Boolean(enabled));
77                 attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
78                 if (charStart != -1) {
79                         attributes.put(IMarker.CHAR_START, new Integer(charStart));
80                         attributes.put(IMarker.CHAR_END, new Integer(charEnd));
81                 }
82                 attributes.put(TYPE_NAME, "typeName");
83                 attributes.put(PHPBreakpoint.HIT_COUNT, new Integer(hitCount));
84                 attributes.put(PHPBreakpoint.CONDITION, new String(""));
85                 attributes.put(PHPBreakpoint.CONDITION_ENABLED, new Boolean(false));
86                 attributes.put(PHPBreakpoint.CHANGE_ID, new Integer(0));
87         }
88
89         /**
90          * @see ILineBreakpoint#getLineNumber()
91          */
92         public int getLineNumber() throws CoreException {
93                 return ensureMarker().getAttribute(IMarker.LINE_NUMBER, -1);
94         }
95
96         /**
97          * @see ILineBreakpoint#getCharStart()
98          */
99         public int getCharStart() throws CoreException {
100                 return ensureMarker().getAttribute(IMarker.CHAR_START, -1);
101         }
102
103         /**
104          * @see ILineBreakpoint#getCharEnd()
105          */
106         public int getCharEnd() throws CoreException {
107                 return ensureMarker().getAttribute(IMarker.CHAR_END, -1);
108         }
109
110         /**
111          * Returns the type of marker associated with Java line breakpoints
112          */
113         public static String getMarkerType() {
114                 return PHP_LINE_BREAKPOINT;
115         }
116
117         public int getHitCount() throws CoreException {
118                 return ensureMarker().getAttribute(PHPBreakpoint.HIT_COUNT, 1);
119         }
120
121         public int getChangeID() throws CoreException {
122                 return ensureMarker().getAttribute(CHANGE_ID, 1);
123         }
124
125         public void setChangeID(int changeID) throws CoreException {
126                 ensureMarker().setAttribute(CHANGE_ID, changeID);
127         }
128
129         public String getCondition() throws CoreException {
130                 return ensureMarker().getAttribute(CONDITION, "");
131         }
132
133         public void setCondition(String condition) throws CoreException {
134                 ensureMarker().setAttribute(CONDITION, condition);
135         }
136
137         public void setConditionEnabled(boolean enabled) throws CoreException {
138                 ensureMarker().setAttribute(CONDITION_ENABLED, enabled);
139         }
140
141         public boolean isConditionEnabled() throws CoreException {
142                 return ensureMarker().getAttribute(CONDITION_ENABLED, false);
143         }
144 }