A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugStackFrame.java
1 /*
2  * Created on 23.11.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpeclipse.xdebug.php.model;
8
9 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
10 import net.sourceforge.phpeclipse.xdebug.core.DebugConnection.DebugResponse;
11
12 import org.eclipse.core.runtime.Path;
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.model.IRegisterGroup;
15 import org.eclipse.debug.core.model.IStackFrame;
16 import org.eclipse.debug.core.model.IThread;
17 import org.eclipse.debug.core.model.IVariable;
18 import org.w3c.dom.Node;
19 import org.w3c.dom.NodeList;
20
21 /**
22  * @author Axel
23  * 
24  * TODO To change the template for this generated type comment go to Window -
25  * Preferences - Java - Code Style - Code Templates
26  */
27 public class XDebugStackFrame extends XDebugElement implements IStackFrame {
28
29         private XDebugThread fThread;
30
31         // private String fName;
32         private int fLineNo;
33
34         private String fFileName;
35
36         private int fId;
37
38         private IVariable[] fVariables;
39
40         private String fLevel;
41
42         private String fType;
43
44         private String fWhere;
45
46         /**
47          * Constructs a stack frame in the given thread with the given frame data.
48          * 
49          * @param thread
50          * @param data
51          *            frame data
52          * @param id
53          *            stack frame id (0 is the bottom of the stack)
54          */
55         public XDebugStackFrame(XDebugThread thread, Node stackNode, int id) {
56                 super((XDebugTarget) thread.getDebugTarget());
57                 fId = id;
58                 fThread = thread;
59                 init(stackNode);
60         }
61
62         /**
63          * Initializes this frame based on its data
64          * 
65          * @param data
66          */
67         private void init(Node stackNode) {
68
69                 fLevel = PHPDebugUtils.getAttributeValue(stackNode, "level");
70                 fType = PHPDebugUtils.getAttributeValue(stackNode, "type");
71                 String fileName = PHPDebugUtils.unescapeString(PHPDebugUtils
72                                 .getAttributeValue(stackNode, "filename"));
73                 String lineNo = PHPDebugUtils.getAttributeValue(stackNode, "lineno");
74
75                 if (lineNo != "")
76                         fLineNo = Integer.parseInt(lineNo);
77
78                 fWhere = PHPDebugUtils.getAttributeValue(stackNode, "where");
79
80                 fFileName = (new Path(fileName)).lastSegment();
81                 int id = -1;
82                 try {
83                         id = ((XDebugTarget) getDebugTarget()).sendRequest("context_get",
84                                         "-d " + fLevel);
85                 } catch (DebugException e) {
86                         // TODO Auto-generated catch block
87                         e.printStackTrace();
88                 }
89                 DebugResponse response = ((XDebugTarget) getDebugTarget())
90                                 .getResponse(id);
91                 Node responseNode = response.getParentNode();
92                 NodeList property = responseNode.getChildNodes();
93                 fVariables = new IVariable[property.getLength()];
94                 for (int i = 0; i < property.getLength(); i++) {
95                         Node propertyNode = property.item(i);
96                         fVariables[i] = new XDebugVariable(this, propertyNode);
97                 }
98
99                 // int numVars = strings.length - 3;
100                 // fVariables = new IVariable[numVars];
101                 // for (int i = 0; i < numVars; i++) {
102                 // fVariables[i] = new XDebugVariable(this, strings[i + 3]);
103                 // }
104         }
105
106         /*
107          * (non-Javadoc)
108          * 
109          * @see org.eclipse.debug.core.model.IStackFrame#getThread()
110          */
111         public IThread getThread() {
112                 return fThread;
113         }
114
115         /*
116          * (non-Javadoc)
117          * 
118          * @see org.eclipse.debug.core.model.IStackFrame#getVariables()
119          */
120         public IVariable[] getVariables() throws DebugException {
121                 return fVariables;
122         }
123
124         /*
125          * (non-Javadoc)
126          * 
127          * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
128          */
129         public boolean hasVariables() throws DebugException {
130                 return fVariables.length > 0;
131         }
132
133         /*
134          * (non-Javadoc)
135          * 
136          * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
137          */
138         public int getLineNumber() throws DebugException {
139                 return fLineNo;
140         }
141
142         /*
143          * (non-Javadoc)
144          * 
145          * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
146          */
147         public int getCharStart() throws DebugException {
148                 return -1;
149         }
150
151         /*
152          * (non-Javadoc)
153          * 
154          * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
155          */
156         public int getCharEnd() throws DebugException {
157                 return -1;
158         }
159
160         /*
161          * (non-Javadoc)
162          * 
163          * @see org.eclipse.debug.core.model.IStackFrame#getName()
164          */
165         public String getName() throws DebugException {
166                 return fFileName + "::" + fWhere + " : lineno " + fLineNo;
167         }
168
169         /*
170          * (non-Javadoc)
171          * 
172          * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
173          */
174         public IRegisterGroup[] getRegisterGroups() throws DebugException {
175                 return null;
176         }
177
178         /*
179          * (non-Javadoc)
180          * 
181          * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
182          */
183         public boolean hasRegisterGroups() throws DebugException {
184                 return false;
185         }
186
187         /*
188          * (non-Javadoc)
189          * 
190          * @see org.eclipse.debug.core.model.IStep#canStepInto()
191          */
192         public boolean canStepInto() {
193                 return getThread().canStepInto();
194         }
195
196         /*
197          * (non-Javadoc)
198          * 
199          * @see org.eclipse.debug.core.model.IStep#canStepOver()
200          */
201         public boolean canStepOver() {
202                 return getThread().canStepOver();
203         }
204
205         /*
206          * (non-Javadoc)
207          * 
208          * @see org.eclipse.debug.core.model.IStep#canStepReturn()
209          */
210         public boolean canStepReturn() {
211                 return getThread().canStepReturn();
212         }
213
214         /*
215          * (non-Javadoc)
216          * 
217          * @see org.eclipse.debug.core.model.IStep#isStepping()
218          */
219         public boolean isStepping() {
220                 return getThread().isStepping();
221         }
222
223         /*
224          * (non-Javadoc)
225          * 
226          * @see org.eclipse.debug.core.model.IStep#stepInto()
227          */
228         public void stepInto() throws DebugException {
229                 getThread().stepInto();
230         }
231
232         /*
233          * (non-Javadoc)
234          * 
235          * @see org.eclipse.debug.core.model.IStep#stepOver()
236          */
237         public void stepOver() throws DebugException {
238                 getThread().stepOver();
239         }
240
241         /*
242          * (non-Javadoc)
243          * 
244          * @see org.eclipse.debug.core.model.IStep#stepReturn()
245          */
246         public void stepReturn() throws DebugException {
247                 getThread().stepReturn();
248         }
249
250         /*
251          * (non-Javadoc)
252          * 
253          * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
254          */
255         public boolean canResume() {
256                 return getThread().canResume();
257         }
258
259         /*
260          * (non-Javadoc)
261          * 
262          * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
263          */
264         public boolean canSuspend() {
265                 return getThread().canSuspend();
266         }
267
268         /*
269          * (non-Javadoc)
270          * 
271          * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
272          */
273         public boolean isSuspended() {
274                 return getThread().isSuspended();
275         }
276
277         /*
278          * (non-Javadoc)
279          * 
280          * @see org.eclipse.debug.core.model.ISuspendResume#resume()
281          */
282         public void resume() throws DebugException {
283                 getThread().resume();
284         }
285
286         /*
287          * (non-Javadoc)
288          * 
289          * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
290          */
291         public void suspend() throws DebugException {
292                 getThread().suspend();
293         }
294
295         /*
296          * (non-Javadoc)
297          * 
298          * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
299          */
300         public boolean canTerminate() {
301                 return getThread().canTerminate();
302         }
303
304         /*
305          * (non-Javadoc)
306          * 
307          * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
308          */
309         public boolean isTerminated() {
310                 return getThread().isTerminated();
311         }
312
313         /*
314          * (non-Javadoc)
315          * 
316          * @see org.eclipse.debug.core.model.ITerminate#terminate()
317          */
318         public void terminate() throws DebugException {
319                 getThread().terminate();
320         }
321
322         /**
323          * Returns the name of the source file this stack frame is associated with.
324          * 
325          * @return the name of the source file this stack frame is associated with
326          */
327         public String getSourceName() {
328                 return fFileName;
329         }
330
331         /*
332          * (non-Javadoc)
333          * 
334          * @see java.lang.Object#equals(java.lang.Object)
335          */
336         public boolean equals(Object obj) {
337                 if (obj instanceof XDebugStackFrame) {
338                         XDebugStackFrame sf = (XDebugStackFrame) obj;
339                         try {
340                                 return sf.getSourceName().equals(getSourceName())
341                                                 && sf.getLineNumber() == getLineNumber()
342                                                 && sf.fId == fId;
343                         } catch (DebugException e) {
344                         }
345                 }
346                 return false;
347         }
348
349         /*
350          * (non-Javadoc)
351          * 
352          * @see java.lang.Object#hashCode()
353          */
354         public int hashCode() {
355                 return getSourceName().hashCode() + fId;
356         }
357
358         /**
359          * Returns this stack frame's unique identifier within its thread
360          * 
361          * @return this stack frame's unique identifier within its thread
362          */
363         protected int getIdentifier() {
364                 return fId;
365         }
366 }