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;
30 private int fLineNumber;
33 private String fWhere;
34 private IVariable[] fVariables;
35 private int fStepCount = 0;
38 * Constructs a stack frame in the given thread with the given
42 * @param data frame data
43 * @param id stack frame id (0 is the bottom of the stack)
45 public XDebugStackFrame(XDebugThread thread, int id, String type, int lineNumber, String where, /*URL*/String filename) {
46 super(/*thread == null ? null : */(XDebugTarget) thread.getDebugTarget());
51 fLineNumber = lineNumber;
55 fName = new URL(filename);
56 } catch (MalformedURLException e) {
61 public void incrementStepCounter() {
66 * @see org.eclipse.debug.core.model.IStackFrame#getThread()
68 public IThread getThread() {
72 public IVariable[] getVariables() throws DebugException {
73 if (fVariables == null) {
74 Node dfl = ((XDebugTarget) getDebugTarget()).getLocalVariables(fLevel);
75 Node dfg = ((XDebugTarget) getDebugTarget()).getGlobalVariables(fLevel);
76 parseVariable(dfl, dfg);
82 private void parseVariable(Node localVariables, Node globalVariables) throws DebugException {
83 NodeList property = localVariables.getChildNodes();
85 NodeList propertyGlobal = globalVariables.getChildNodes();
87 fVariables = new IVariable[property.getLength() + propertyGlobal.getLength()];
89 int length = property.getLength();
90 for (int i = 0; i < length; i++) {
91 XDebugVariable var = new XDebugVariable(this, property.item(i));
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;
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]);
110 * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
112 public boolean hasVariables() throws DebugException {
113 /*return fVariables.length > 0;*/
118 * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
120 public int getLineNumber() throws DebugException {
125 * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
127 public int getCharStart() throws DebugException {
132 * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
134 public int getCharEnd() throws DebugException {
138 /* (non-Javadoc)fName
139 * @see org.eclipse.debug.core.model.IStackFrame#getName()
141 public String getName() throws DebugException {
142 return fName.toString()+"::"+fWhere+ " line: "+ fLineNumber;
146 * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
148 public IRegisterGroup[] getRegisterGroups() throws DebugException {
153 * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
155 public boolean hasRegisterGroups() throws DebugException {
160 * @see org.eclipse.debug.core.model.IStep#canStepInto()
162 public boolean canStepInto() {
163 return fThread.canStepInto();
167 * @see org.eclipse.debug.core.model.IStep#canStepOver()
169 public boolean canStepOver() {
170 return fThread.canStepOver();
174 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
176 public boolean canStepReturn() {
177 return fThread.canStepReturn();
181 * @see org.eclipse.debug.core.model.IStep#isStepping()
183 public boolean isStepping() {
184 return fThread.isStepping();
188 * @see org.eclipse.debug.core.model.IStep#stepInto()
190 public void stepInto() throws DebugException {
195 * @see org.eclipse.debug.core.model.IStep#stepOver()
197 public void stepOver() throws DebugException {
202 * @see org.eclipse.debug.core.model.IStep#stepReturn()
204 public void stepReturn() throws DebugException {
205 fThread.stepReturn();
209 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
211 public boolean canResume() {
212 return fThread.canResume();
216 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
218 public boolean canSuspend() {
219 return fThread.canSuspend();
223 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
225 public boolean isSuspended() {
226 return fThread.isSuspended();
230 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
232 public void resume() throws DebugException {
237 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
239 public void suspend() throws DebugException {
244 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
246 public boolean canTerminate() {
247 return fThread.canTerminate();
251 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
253 public boolean isTerminated() {
254 return fThread.isTerminated();
258 * @see org.eclipse.debug.core.model.ITerminate#terminate()
260 public void terminate() throws DebugException {
265 * Returns the name of the source file this stack frame is associated
268 * @return the name of the source file this stack frame is associated
269 * with. If the file associated with this frame does not exists, it returns null.
271 public String getSourceName() {
275 IPath a = new Path(fName.getFile());
276 return a.lastSegment();
279 public boolean isSameStackFrame(Object obj) {
280 boolean isSameStackFrame = false;
282 if (obj instanceof XDebugStackFrame) {
283 XDebugStackFrame sf = (XDebugStackFrame)obj;
284 isSameStackFrame = sf.getSourceName().equals(getSourceName()) &&
285 sf.getType().equals(getType()) &&
286 sf.getWhere().equals(getWhere()); //&&
289 return isSameStackFrame;
293 * @see java.lang.Object#equals(java.lang.Object)
295 public boolean equals(Object obj) {
296 if (obj instanceof XDebugStackFrame) {
297 XDebugStackFrame sf = (XDebugStackFrame)obj;
299 return sf.getSourceName().equals(new Path(fName.getFile()).lastSegment()) &&
300 sf.getLineNumber() == fLineNumber &&
301 sf.getLevel() == fLevel &&
302 sf.getType().equals(fType) &&
303 sf.getWhere().equals(fWhere);
304 } catch (DebugException e) {
312 * @see java.lang.Object#hashCode()
314 public int hashCode() {
315 return getSourceName().hashCode() + fLevel;
318 public URL getFullName() {
322 public int getLevel() {
326 public String getType() {
330 public String getWhere() {
334 public boolean setVariableValue(XDebugVariable variable, String expression) throws DebugException {
335 return ((XDebugTarget) getDebugTarget()).setVarValue("$" + variable.getName(), expression);
338 public Node eval(String expression) throws DebugException {
339 return ((XDebugTarget) getDebugTarget()).eval(expression);