*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / core / 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.core;
8
9 import org.eclipse.core.runtime.Path;
10 import org.eclipse.debug.core.DebugException;
11 import org.eclipse.debug.core.model.IRegisterGroup;
12 import org.eclipse.debug.core.model.IStackFrame;
13 import org.eclipse.debug.core.model.IThread;
14 import org.eclipse.debug.core.model.IVariable;
15
16 /**
17  * @author Axel
18  *
19  * TODO To change the template for this generated type comment go to
20  * Window - Preferences - Java - Code Style - Code Templates
21  */
22 public class XDebugStackFrame  extends XDebugElement implements IStackFrame {
23         
24         private XDebugThread fThread;
25         private String fName;
26         private int fPC;
27         private String fFileName;
28         private int fId;
29         private IVariable[] fVariables;
30         
31         /**
32          * Constructs a stack frame in the given thread with the given
33          * frame data.
34          * 
35          * @param thread
36          * @param data frame data
37          * @param id stack frame id (0 is the bottom of the stack)
38          */
39         public XDebugStackFrame(XDebugThread thread, String data, int id) {
40                 super((XDebugTarget) thread.getDebugTarget());
41                 fId = id;
42                 fThread = thread;
43                 init(data);
44         }
45         
46         /**
47          * Initializes this frame based on its data
48          * 
49          * @param data
50          */
51         private void init(String data) {
52                 String[] strings = data.split("\\|");
53                 String fileName = strings[0];
54                 fFileName = (new Path(fileName)).lastSegment();
55                 String pc = strings[1];
56                 fPC = Integer.parseInt(pc) + 1;
57                 fName = strings[2];
58                 int numVars = strings.length - 3;
59                 fVariables = new IVariable[numVars];
60                 for (int i = 0; i < numVars; i++) {
61                         fVariables[i] = new XDebugVariable(this, strings[i + 3]);
62                 }
63         }
64         
65         /* (non-Javadoc)
66          * @see org.eclipse.debug.core.model.IStackFrame#getThread()
67          */
68         public IThread getThread() {
69                 return fThread;
70         }
71         /* (non-Javadoc)
72          * @see org.eclipse.debug.core.model.IStackFrame#getVariables()
73          */
74         public IVariable[] getVariables() throws DebugException {
75                 return fVariables;
76         }
77         /* (non-Javadoc)
78          * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
79          */
80         public boolean hasVariables() throws DebugException {
81                 return fVariables.length > 0;
82         }
83         /* (non-Javadoc)
84          * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
85          */
86         public int getLineNumber() throws DebugException {
87                 return fPC;
88         }
89         /* (non-Javadoc)
90          * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
91          */
92         public int getCharStart() throws DebugException {
93                 return -1;
94         }
95         /* (non-Javadoc)
96          * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
97          */
98         public int getCharEnd() throws DebugException {
99                 return -1;
100         }
101         /* (non-Javadoc)
102          * @see org.eclipse.debug.core.model.IStackFrame#getName()
103          */
104         public String getName() throws DebugException {
105                 return fName;
106         }
107         /* (non-Javadoc)
108          * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
109          */
110         public IRegisterGroup[] getRegisterGroups() throws DebugException {
111                 return null;
112         }
113         /* (non-Javadoc)
114          * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
115          */
116         public boolean hasRegisterGroups() throws DebugException {
117                 return false;
118         }
119         /* (non-Javadoc)
120          * @see org.eclipse.debug.core.model.IStep#canStepInto()
121          */
122         public boolean canStepInto() {
123                 return getThread().canStepInto();
124         }
125         /* (non-Javadoc)
126          * @see org.eclipse.debug.core.model.IStep#canStepOver()
127          */
128         public boolean canStepOver() {
129                 return getThread().canStepOver();
130         }
131         /* (non-Javadoc)
132          * @see org.eclipse.debug.core.model.IStep#canStepReturn()
133          */
134         public boolean canStepReturn() {
135                 return getThread().canStepReturn();
136         }
137         /* (non-Javadoc)
138          * @see org.eclipse.debug.core.model.IStep#isStepping()
139          */
140         public boolean isStepping() {
141                 return getThread().isStepping();
142         }
143         /* (non-Javadoc)
144          * @see org.eclipse.debug.core.model.IStep#stepInto()
145          */
146         public void stepInto() throws DebugException {
147                 getThread().stepInto();
148         }
149         /* (non-Javadoc)
150          * @see org.eclipse.debug.core.model.IStep#stepOver()
151          */
152         public void stepOver() throws DebugException {
153                 getThread().stepOver();
154         }
155         /* (non-Javadoc)
156          * @see org.eclipse.debug.core.model.IStep#stepReturn()
157          */
158         public void stepReturn() throws DebugException {
159                 getThread().stepReturn();
160         }
161         /* (non-Javadoc)
162          * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
163          */
164         public boolean canResume() {
165                 return getThread().canResume();
166         }
167         /* (non-Javadoc)
168          * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
169          */
170         public boolean canSuspend() {
171                 return getThread().canSuspend();
172         }
173         /* (non-Javadoc)
174          * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
175          */
176         public boolean isSuspended() {
177                 return getThread().isSuspended();
178         }
179         /* (non-Javadoc)
180          * @see org.eclipse.debug.core.model.ISuspendResume#resume()
181          */
182         public void resume() throws DebugException {
183                 getThread().resume();
184         }
185         /* (non-Javadoc)
186          * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
187          */
188         public void suspend() throws DebugException {
189                 getThread().suspend();
190         }
191         /* (non-Javadoc)
192          * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
193          */
194         public boolean canTerminate() {
195                 return getThread().canTerminate();
196         }
197         /* (non-Javadoc)
198          * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
199          */
200         public boolean isTerminated() {
201                 return getThread().isTerminated();
202         }
203         /* (non-Javadoc)
204          * @see org.eclipse.debug.core.model.ITerminate#terminate()
205          */
206         public void terminate() throws DebugException {
207                 getThread().terminate();
208         }
209         
210         /**
211          * Returns the name of the source file this stack frame is associated
212          * with.
213          * 
214          * @return the name of the source file this stack frame is associated
215          * with
216          */
217         public String getSourceName() {
218                 return fFileName;
219         }
220         /* (non-Javadoc)
221          * @see java.lang.Object#equals(java.lang.Object)
222          */
223         public boolean equals(Object obj) {
224                 if (obj instanceof XDebugStackFrame) {
225                         XDebugStackFrame sf = (XDebugStackFrame)obj;
226                         try {
227                                 return sf.getSourceName().equals(getSourceName()) &&
228                                         sf.getLineNumber() == getLineNumber() &&
229                                         sf.fId == fId;
230                         } catch (DebugException e) {
231                         }
232                 }
233                 return false;
234         }
235         /* (non-Javadoc)
236          * @see java.lang.Object#hashCode()
237          */
238         public int hashCode() {
239                 return getSourceName().hashCode() + fId;
240         }
241         
242         /**
243          * Returns this stack frame's unique identifier within its thread
244          * 
245          * @return this stack frame's unique identifier within its thread
246          */
247         protected int getIdentifier() {
248                 return fId;
249         }
250 }