5fbece5f8093cca45fce8fee52d488935f166b8c
[phpeclipse.git] /
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 java.net.URL;
10
11 //import net.sourceforge.phpeclipse.xdebug.core.Base64;
12 //import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
13 //import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
14 //import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.XDebugResponse;
15
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.debug.core.DebugException;
19 import org.eclipse.debug.core.model.IRegisterGroup;
20 import org.eclipse.debug.core.model.IStackFrame;
21 import org.eclipse.debug.core.model.IThread;
22 import org.eclipse.debug.core.model.IVariable;
23 import org.w3c.dom.Node;
24 import org.w3c.dom.NodeList;
25
26 /**
27  * @author PHPeclipse team
28  * @author Axel
29  *
30  */
31 public class XDebugStackFrame  extends XDebugElement implements IStackFrame {
32         private XDebugThread fThread;
33
34         private int fId;
35         
36         private URL fName;
37         
38         private int fLineNumber;
39         private int fLevel;
40         private String fType;
41         private String fWhere;
42
43         private IVariable[] fVariables;
44
45         private int fStepCount = 0;
46         
47         /**
48          * Constructs a stack frame in the given thread with the given
49          * frame data.
50          * 
51          * @param thread
52          * @param data frame data
53          * @param id stack frame id (0 is the bottom of the stack)
54          */
55         public XDebugStackFrame(XDebugThread thread, int id) {
56                 super(thread == null ? null : (XDebugTarget) thread.getDebugTarget());
57                 fId = id;
58                 fThread = thread;
59         }
60         
61         public void incrementStepCounter() {
62                 fStepCount++;
63         }
64         
65         /* (non-Javadoc)
66          * @see org.eclipse.debug.core.model.IStackFrame#getThread()
67          */
68         public IThread getThread() {
69                 return fThread;
70         }
71         
72         public IVariable[] getVariables() throws DebugException {
73                 if (fVariables == null) {
74                         Node dfl = fTarget.getLocalVariables(fLevel);
75                         Node dfg = fTarget.getGlobalVariables(fLevel);
76                         parseVariable(dfl, dfg);
77                 }
78
79                 return fVariables;
80         }
81         
82         private void parseVariable(Node localVariables, Node globalVariables) {
83                 NodeList property = localVariables.getChildNodes();
84                 
85                 NodeList propertyGlobal = globalVariables.getChildNodes();
86                 
87                 fVariables = new IVariable[property.getLength() + propertyGlobal.getLength()];
88                 
89                 int length = property.getLength();
90                 for (int i = 0; i < length; i++) {
91                         XDebugVariable var = new XDebugVariable(this, property.item(i));
92                         fVariables[i] = var;
93                 }
94
95                 int globalLength = propertyGlobal.getLength();
96                 for (int k = 0; k < globalLength; k++) {
97                         XDebugVariable var = new XDebugVariable(this, propertyGlobal.item(k));
98                         fVariables[k + length] = var;
99                 }
100         }
101         
102         /*public void evaluateChange(IStackFrame OldStackFrame) throws DebugException {
103                 IVariable[] OldVariable = ((XDebugStackFrame) OldStackFrame).getVariables();
104                 for (int i = 0; i < fVariables.length; i++) {
105                         ((XDebugVariable) fVariables[i]).setChange(OldVariable[i]);
106                 }
107         }*/
108         
109         /* (non-Javadoc)
110          * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
111          */
112         public boolean hasVariables() throws DebugException {
113                 /*return fVariables.length > 0;*/
114                 return true;
115         }
116         
117         /* (non-Javadoc)
118          * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
119          */
120         public int getLineNumber() throws DebugException {
121                 return fLineNumber;
122         }
123         
124         /* (non-Javadoc)
125          * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
126          */
127         public int getCharStart() throws DebugException {
128                 return -1;
129         }
130         
131         /* (non-Javadoc)
132          * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
133          */
134         public int getCharEnd() throws DebugException {
135                 return -1;
136         }
137         
138         /* (non-Javadoc)fName
139          * @see org.eclipse.debug.core.model.IStackFrame#getName()
140          */
141         public String getName() throws DebugException {
142                 //String a = fName.getFile();
143                 //return fName.lastSegment().toString()+"::"+fWhere+ " line: "+ fLineNumber;
144                 return fName.toString()+"::"+fWhere+ " line: "+ fLineNumber;
145         }
146         
147         /* (non-Javadoc)
148          * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
149          */
150         public IRegisterGroup[] getRegisterGroups() throws DebugException {
151                 return null;
152         }
153         
154         /* (non-Javadoc)
155          * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
156          */
157         public boolean hasRegisterGroups() throws DebugException {
158                 return false;
159         }
160         
161         /* (non-Javadoc)
162          * @see org.eclipse.debug.core.model.IStep#canStepInto()
163          */
164         public boolean canStepInto() {
165                 return fThread.canStepInto();
166         }
167         
168         /* (non-Javadoc)
169          * @see org.eclipse.debug.core.model.IStep#canStepOver()
170          */
171         public boolean canStepOver() {
172                 return fThread.canStepOver();
173         }
174         
175         /* (non-Javadoc)
176          * @see org.eclipse.debug.core.model.IStep#canStepReturn()
177          */
178         public boolean canStepReturn() {
179                 return fThread.canStepReturn();
180         }
181         
182         /* (non-Javadoc)
183          * @see org.eclipse.debug.core.model.IStep#isStepping()
184          */
185         public boolean isStepping() {
186                 return fThread.isStepping();
187         }
188         
189         /* (non-Javadoc)
190          * @see org.eclipse.debug.core.model.IStep#stepInto()
191          */
192         public void stepInto() throws DebugException {
193                 fThread.stepInto();
194         }
195         
196         /* (non-Javadoc)
197          * @see org.eclipse.debug.core.model.IStep#stepOver()
198          */
199         public void stepOver() throws DebugException {
200                 fThread.stepOver();
201         }
202         
203         /* (non-Javadoc)
204          * @see org.eclipse.debug.core.model.IStep#stepReturn()
205          */
206         public void stepReturn() throws DebugException {
207                 fThread.stepReturn();
208         }
209         
210         /* (non-Javadoc)
211          * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
212          */
213         public boolean canResume() {
214                 return fThread.canResume();
215         }
216         
217         /* (non-Javadoc)
218          * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
219          */
220         public boolean canSuspend() {
221                 return fThread.canSuspend();
222         }
223         
224         /* (non-Javadoc)
225          * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
226          */
227         public boolean isSuspended() {
228                 return fThread.isSuspended();
229         }
230         
231         /* (non-Javadoc)
232          * @see org.eclipse.debug.core.model.ISuspendResume#resume()
233          */
234         public void resume() throws DebugException {
235                 fThread.resume();
236         }
237         
238         /* (non-Javadoc)
239          * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
240          */
241         public void suspend() throws DebugException {
242                 fThread.suspend();
243         }
244         
245         /* (non-Javadoc)
246          * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
247          */
248         public boolean canTerminate() {
249                 return fThread.canTerminate();
250         }
251         
252         /* (non-Javadoc)
253          * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
254          */
255         public boolean isTerminated() {
256                 return fThread.isTerminated();
257         }
258         
259         /* (non-Javadoc)
260          * @see org.eclipse.debug.core.model.ITerminate#terminate()
261          */
262         public void terminate() throws DebugException {
263                 fThread.terminate();
264         }
265         
266         /**
267          * Returns the name of the source file this stack frame is associated
268          * with.
269          * 
270          * @return the name of the source file this stack frame is associated
271          * with. If the file associated with this frame does not exists, it returns null.
272          */
273         public String getSourceName() {
274                 if (fName == null) {
275                         return null;
276                 }
277                 IPath a = new Path(fName.getFile());
278                 return a.lastSegment();
279         }
280
281         public boolean isSameStackFrame(Object obj) {
282                 boolean isSameStackFrame = false;
283                 
284                 if (obj instanceof XDebugStackFrame) {
285                         XDebugStackFrame sf = (XDebugStackFrame)obj;
286                         //try {
287                                 isSameStackFrame = sf.getSourceName().equals(getSourceName()) &&
288                                         /*sf.getLineNumber() == getLineNumber() &&*/
289                                         /*sf.getLevel() == getLevel() &&*/
290                                         sf.getType().equals(getType()) &&
291                                         sf.getWhere().equals(getWhere()); //&&
292                                         /*sf.fId == fId;*/
293                         /*} catch (DebugException e) {
294                         }*/
295                 }
296
297                 return isSameStackFrame;
298         }
299         
300         /* (non-Javadoc)
301          * @see java.lang.Object#equals(java.lang.Object)
302          */
303         public boolean equals(Object obj) {
304                 if (obj instanceof XDebugStackFrame) {
305                         XDebugStackFrame sf = (XDebugStackFrame)obj;
306                         try {
307                                 return sf.getSourceName().equals(getSourceName()) &&
308                                         sf.getLineNumber() == getLineNumber() &&
309                                         sf.getLevel() == getLevel() &&
310                                         sf.getType().equals(getType()) &&
311                                         sf.getWhere().equals(getWhere());
312 /*                                      sf.getType() == getType() &&
313                                         sf.getWhere() == getWhere() &&*/
314                                         /*sf.fId == fId;*/
315                         } catch (DebugException e) {
316                         }
317                 }
318
319                 return false;
320         }
321         
322         /* (non-Javadoc)
323          * @see java.lang.Object#equals(java.lang.Object)
324          */
325         public boolean equalsOld(Object obj) {
326                 if (obj instanceof XDebugStackFrame) {
327                         XDebugStackFrame sf = (XDebugStackFrame)obj;
328                         try {
329                                 return sf.getSourceName().equals(getSourceName()) &&
330                                         sf.getLineNumber() == getLineNumber() &&
331                                         sf.fId == fId;
332                         } catch (DebugException e) {
333                         }
334                 }
335                 return false;
336         }
337         
338         /* (non-Javadoc)
339          * @see java.lang.Object#hashCode()
340          */
341         public int hashCode() {
342 //              return getSourceName().hashCode() + fId;
343                 return getSourceName().hashCode() + fLevel;
344         }
345         
346         /**
347          * 
348          * @return this stack frame's unique identifier within its thread
349          */
350         protected int getIdentifier() {
351                 return fId;
352         }
353
354
355         public void setFullName(URL name) {
356                 fName = name;
357         }
358
359
360         public URL getFullName() {
361                 return fName;
362         }
363         
364
365         public int getLevel() {
366                 return fLevel;
367         }
368
369         public void setLevel(int level) {
370                 fLevel = level;
371                 fId = level;
372         }
373
374         public String getType() {
375                 return fType;
376         }
377
378         public void setType(String type) {
379                 fType = type;
380         }
381
382         public String getWhere() {
383                 return fWhere;
384         }
385
386         public void setWhere(String where) {
387                 fWhere = where;
388         }
389
390         public void setLineNumber(int newlineNumber) {
391                 fLineNumber = newlineNumber;
392         }
393 }