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