Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugLineBreakpoint.java
1
2 /*
3  * Created on 25.11.2004
4  *
5  * TODO To change the template for this generated file go to
6  * Window - Preferences - Java - Code Style - Code Templates
7  */
8 package net.sourceforge.phpeclipse.xdebug.php.model;
9
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
15
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.CoreException;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.debug.core.DebugPlugin;
22 import org.eclipse.debug.core.model.IBreakpoint;
23 import org.eclipse.debug.core.model.LineBreakpoint;
24
25
26 /**
27  * @author Axel
28  *
29  * TODO To change the template for this generated type comment go to
30  * Window - Preferences - Java - Code Style - Code Templates
31  */
32 public class XDebugLineBreakpoint  extends LineBreakpoint {
33         
34         /**
35          * Default constructor is required for the breakpoint manager
36          * to re-create persisted breakpoints. After instantiating a breakpoint,
37          * the <code>setMarker(...)</code> method is called to restore
38          * this breakpoint's attributes.
39          */
40         private static final String XDEBUG_LINE_BREAKPOINT = "net.sourceforge.phpeclipse.xdebug.core.XDebugLineBreakpoint"; //$NON-NLS-1$
41
42         /**
43          * Breakpoint attribute storing the fully qualified name of the type
44          * this breakpoint is located in.
45          * (value <code>"net.sourceforge.phpeclipse.debug.typeName"</code>). This attribute is a <code>String</code>.
46          */
47         protected static final String TYPE_NAME = "net.sourceforge.phpeclipse.debug.typeName"; //$NON-NLS-1$            
48
49 //      public PHPLineBreakpoint() {
50 //      }
51 //
52 //      public PHPLineBreakpoint(IResource resource, int lineNumber, int charStart, int charEnd, int hitCount, boolean add, Map attributes) throws DebugException {
53 //              this(resource, lineNumber, charStart, charEnd, hitCount, add, attributes, PHP_LINE_BREAKPOINT);
54 //      }
55 //      
56 //      public PHPLineBreakpoint(IResource resource, int lineNumber, int hitCount, boolean add, Map attributes) throws DebugException {
57 //              this(resource, lineNumber, -1, -1, hitCount, add, attributes, PHP_LINE_BREAKPOINT);
58 //      }
59
60         
61         public static final String BREAKPOINT_ID ="XDebugLineBreakpointID";
62         
63         public XDebugLineBreakpoint() {
64         }
65         
66         /**
67          * Constructs a line breakpoint on the given resource at the given
68          * line number. The line number is 1-based (i.e. the first line of a
69          * file is line number 1).
70          * 
71          * @param resource file on which to set the breakpoint
72          * @param lineNumber 1-based line number of the breakpoint
73          * @throws CoreException if unable to create the breakpoint
74          */
75         public XDebugLineBreakpoint(final IResource resource, final int lineNumber) throws CoreException {
76 //              IMarker marker = resource.createMarker("net.sourceforge.phpeclipse.xdebug.core.XDebugLineBreakpoint");
77 //              setMarker(marker);
78 //              setEnabled(true);
79 //              XDebugCorePlugin.log(IStatus.INFO,"Markertype: "+ marker.getType());
80 //              ensureMarker().setAttribute(IMarker.LINE_NUMBER, lineNumber);
81 //              ensureMarker().setAttribute(IBreakpoint.ID, IXDebugConstants.ID_PHP_DEBUG_MODEL);
82 //              ensureMarker().setAttribute(BREAKPOINT_ID,-1);
83                 IWorkspaceRunnable wr= new IWorkspaceRunnable() {
84                         public void run(IProgressMonitor monitor) throws CoreException {
85         
86                                 // create the marker
87                                 setMarker(resource.createMarker(XDEBUG_LINE_BREAKPOINT));
88
89                                 // add attributes
90                                 Map attributes = new HashMap(10);
91                                 addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, -1, -1);
92
93                                 // set attributes
94                                 ensureMarker().setAttributes(attributes);
95                                 
96                                 // add to breakpoint manager if requested
97                                 register(true);         
98                         }
99                 };
100                 run(getMarkerRule(resource), wr);
101
102         }
103         
104         protected void register(boolean register) throws CoreException {
105                 if (register) {
106                         DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
107                 } else {
108                         setRegistered(false);
109                 }
110         }
111         
112         public void addLineBreakpointAttributes(Map attributes, String modelIdentifier, boolean enabled, int lineNumber, int charStart, int charEnd) {
113                 attributes.put(IBreakpoint.ID, modelIdentifier);
114                 attributes.put(IBreakpoint.ENABLED, new Boolean(enabled));
115                 attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
116                 if (charStart!=-1)
117                 {
118                         attributes.put(IMarker.CHAR_START, new Integer(charStart));
119                         attributes.put(IMarker.CHAR_END, new Integer(charEnd));
120                 }
121                 attributes.put(TYPE_NAME, "typeName");
122                 attributes.put(BREAKPOINT_ID,new Integer(-1));
123         }               
124
125         
126         /* (non-Javadoc)
127          * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier()
128          */
129         public String getModelIdentifier() {
130                 return IXDebugConstants.ID_PHP_DEBUG_MODEL;
131         }
132         
133         public void setID(int id) throws CoreException
134         {
135                 ensureMarker().setAttribute(BREAKPOINT_ID,id);
136         }
137         public int getID() throws CoreException
138         {
139                 return ensureMarker().getAttribute(BREAKPOINT_ID,-1);
140         }
141 }