2 * Created on 23.11.2004
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
7 package net.sourceforge.phpeclipse.xdebug.php.model;
9 import java.net.MalformedURLException;
12 import org.eclipse.core.runtime.IPath;
13 import org.eclipse.core.runtime.Path;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IRegisterGroup;
16 import org.eclipse.debug.core.model.IStackFrame;
17 import org.eclipse.debug.core.model.IThread;
18 import org.eclipse.debug.core.model.IVariable;
19 import org.w3c.dom.Node;
20 import org.w3c.dom.NodeList;
23 * @author PHPeclipse team
27 public class XDebugStackFrame extends XDebugElement implements IStackFrame {
28 private XDebugThread fThread;
31 private int fLineNumber;
34 private String fWhere;
36 private IVariable[] fVariables;
38 private int fStepCount = 0;
41 * Constructs a stack frame in the given thread with the given
45 * @param data frame data
46 * @param id stack frame id (0 is the bottom of the stack)
48 public XDebugStackFrame(XDebugThread thread, int level, String type, int lineNumber, String where, /*URL*/String filename) {
49 super(thread == null ? null : (XDebugTarget) thread.getDebugTarget());
54 fLineNumber = lineNumber;
57 fName = new URL(filename);
58 } catch (MalformedURLException e) {
63 public void incrementStepCounter() {
68 * @see org.eclipse.debug.core.model.IStackFrame#getThread()
70 public IThread getThread() {
74 public IVariable[] getVariables() throws DebugException {
75 if (fVariables == null) {
76 Node dfl = ((XDebugTarget) getDebugTarget()).getLocalVariables(fLevel);
77 Node dfg = ((XDebugTarget) getDebugTarget()).getGlobalVariables(fLevel);
78 parseVariable(dfl, dfg);
84 private void parseVariable(Node localVariables, Node globalVariables) {
85 NodeList property = localVariables.getChildNodes();
87 NodeList propertyGlobal = globalVariables.getChildNodes();
89 fVariables = new IVariable[property.getLength() + propertyGlobal.getLength()];
91 int length = property.getLength();
92 for (int i = 0; i < length; i++) {
93 XDebugVariable var = new XDebugVariable(this, property.item(i));
97 int globalLength = propertyGlobal.getLength();
98 for (int k = 0; k < globalLength; k++) {
99 XDebugVariable var = new XDebugVariable(this, propertyGlobal.item(k));
100 fVariables[k + length] = var;
104 /*public void evaluateChange(IStackFrame OldStackFrame) throws DebugException {
105 IVariable[] OldVariable = ((XDebugStackFrame) OldStackFrame).getVariables();
106 for (int i = 0; i < fVariables.length; i++) {
107 ((XDebugVariable) fVariables[i]).setChange(OldVariable[i]);
112 * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
114 public boolean hasVariables() throws DebugException {
115 /*return fVariables.length > 0;*/
120 * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
122 public int getLineNumber() throws DebugException {
127 * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
129 public int getCharStart() throws DebugException {
134 * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
136 public int getCharEnd() throws DebugException {
140 /* (non-Javadoc)fName
141 * @see org.eclipse.debug.core.model.IStackFrame#getName()
143 public String getName() throws DebugException {
144 return fName.toString()+"::"+fWhere+ " line: "+ fLineNumber;
148 * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
150 public IRegisterGroup[] getRegisterGroups() throws DebugException {
155 * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
157 public boolean hasRegisterGroups() throws DebugException {
162 * @see org.eclipse.debug.core.model.IStep#canStepInto()
164 public boolean canStepInto() {
165 return fThread.canStepInto();
169 * @see org.eclipse.debug.core.model.IStep#canStepOver()
171 public boolean canStepOver() {
172 return fThread.canStepOver();
176 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
178 public boolean canStepReturn() {
179 return fThread.canStepReturn();
183 * @see org.eclipse.debug.core.model.IStep#isStepping()
185 public boolean isStepping() {
186 return fThread.isStepping();
190 * @see org.eclipse.debug.core.model.IStep#stepInto()
192 public void stepInto() throws DebugException {
197 * @see org.eclipse.debug.core.model.IStep#stepOver()
199 public void stepOver() throws DebugException {
204 * @see org.eclipse.debug.core.model.IStep#stepReturn()
206 public void stepReturn() throws DebugException {
207 fThread.stepReturn();
211 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
213 public boolean canResume() {
214 return fThread.canResume();
218 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
220 public boolean canSuspend() {
221 return fThread.canSuspend();
225 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
227 public boolean isSuspended() {
228 return fThread.isSuspended();
232 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
234 public void resume() throws DebugException {
239 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
241 public void suspend() throws DebugException {
246 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
248 public boolean canTerminate() {
249 return fThread.canTerminate();
253 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
255 public boolean isTerminated() {
256 return fThread.isTerminated();
260 * @see org.eclipse.debug.core.model.ITerminate#terminate()
262 public void terminate() throws DebugException {
267 * Returns the name of the source file this stack frame is associated
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.
273 public String getSourceName() {
277 IPath a = new Path(fName.getFile());
278 return a.lastSegment();
281 public boolean isSameStackFrame(Object obj) {
282 boolean isSameStackFrame = false;
284 if (obj instanceof XDebugStackFrame) {
285 XDebugStackFrame sf = (XDebugStackFrame)obj;
286 isSameStackFrame = sf.getSourceName().equals(getSourceName()) &&
287 sf.getType().equals(getType()) &&
288 sf.getWhere().equals(getWhere()); //&&
291 return isSameStackFrame;
295 * @see java.lang.Object#equals(java.lang.Object)
297 public boolean equals(Object obj) {
298 if (obj instanceof XDebugStackFrame) {
299 XDebugStackFrame sf = (XDebugStackFrame)obj;
301 return sf.getSourceName().equals(fName) &&
302 sf.getLineNumber() == fLineNumber &&
303 sf.getLevel() == fLevel &&
304 sf.getType().equals(fType) &&
305 sf.getWhere().equals(fWhere);
306 } catch (DebugException e) {
314 * @see java.lang.Object#hashCode()
316 public int hashCode() {
317 return getSourceName().hashCode() + fLevel;
320 public URL getFullName() {
324 public int getLevel() {
328 public String getType() {
332 public String getWhere() {
336 public boolean setVariableValue(XDebugVariable variable, String expression) throws DebugException {
337 return ((XDebugTarget) getDebugTarget()).setVarValue("$" + variable.getName(), expression);