First submit for debug plugin
[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.runtime.CoreException;
16 import org.eclipse.core.resources.IMarker;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.IWorkspaceRunnable;
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         protected PHPLineBreakpoint(final IResource resource, final int lineNumber, final int charStart, final int charEnd, final int hitCount, final boolean add, final Map attributes, final String markerType) throws DebugException {
39                 IWorkspaceRunnable wr= new IWorkspaceRunnable() {
40                         public void run(IProgressMonitor monitor) throws CoreException {
41         
42                                 // create the marker
43                                 setMarker(resource.createMarker(markerType));
44
45                                 // add attributes
46                                 addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd);
47
48                                 // set attributes
49                                 ensureMarker().setAttributes(attributes);
50                                 
51                                 // add to breakpoint manager if requested
52                                 register(add);          
53                         }
54                 };
55                 run(wr);
56         }
57
58         public void addLineBreakpointAttributes(Map attributes, String modelIdentifier, boolean enabled, int lineNumber, int charStart, int charEnd) {
59                 attributes.put(IBreakpoint.ID, modelIdentifier);
60                 attributes.put(IBreakpoint.ENABLED, new Boolean(enabled));
61                 attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
62                 attributes.put(IMarker.CHAR_START, new Integer(charStart));
63                 attributes.put(IMarker.CHAR_END, new Integer(charEnd));
64                 attributes.put(TYPE_NAME, "typeName"); 
65         }               
66
67         /**
68          * @see ILineBreakpoint#getLineNumber()
69          */
70         public int getLineNumber() throws CoreException {
71                 return ensureMarker().getAttribute(IMarker.LINE_NUMBER, -1);
72         }
73
74         /**
75          * @see ILineBreakpoint#getCharStart()
76          */
77         public int getCharStart() throws CoreException {
78                 return ensureMarker().getAttribute(IMarker.CHAR_START, -1);
79         }
80
81         /**
82          * @see ILineBreakpoint#getCharEnd()
83          */
84         public int getCharEnd() throws CoreException {
85                 return ensureMarker().getAttribute(IMarker.CHAR_END, -1);
86         }
87         
88         /**
89          * Returns the type of marker associated with Java line breakpoints
90          */
91         public static String getMarkerType() {
92                 return PHP_LINE_BREAKPOINT;
93         }       
94 }