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;
 
  34         private int fLineNumber;
 
  37         private String fWhere;
 
  39         private IVariable[] fVariables;
 
  41         private int fStepCount = 0;
 
  44          * Constructs a stack frame in the given thread with the given
 
  48          * @param data frame data
 
  49          * @param id stack frame id (0 is the bottom of the stack)
 
  51         public XDebugStackFrame(XDebugThread thread, int id, String type, int lineNumber, String where, /*URL*/String filename) {
 
  52                 super(thread == null ? null : (XDebugTarget) thread.getDebugTarget());
 
  58                 fLineNumber = lineNumber;
 
  62                 fName = new URL(filename);
 
  63                 } catch (MalformedURLException e) {
 
  68         public void incrementStepCounter() {
 
  73          * @see org.eclipse.debug.core.model.IStackFrame#getThread()
 
  75         public IThread getThread() {
 
  79         public IVariable[] getVariables() throws DebugException {
 
  80                 if (fVariables == null) {
 
  81                         Node dfl = ((XDebugTarget) getDebugTarget()).getLocalVariables(fLevel);
 
  82                         Node dfg = ((XDebugTarget) getDebugTarget()).getGlobalVariables(fLevel);
 
  83                         parseVariable(dfl, dfg);
 
  89         private void parseVariable(Node localVariables, Node globalVariables) {
 
  90                 NodeList property = localVariables.getChildNodes();
 
  92                 NodeList propertyGlobal = globalVariables.getChildNodes();
 
  94                 fVariables = new IVariable[property.getLength() + propertyGlobal.getLength()];
 
  96                 int length = property.getLength();
 
  97                 for (int i = 0; i < length; i++) {
 
  98                         XDebugVariable var = new XDebugVariable(this, property.item(i));
 
 102                 int globalLength = propertyGlobal.getLength();
 
 103                 for (int k = 0; k < globalLength; k++) {
 
 104                         XDebugVariable var = new XDebugVariable(this, propertyGlobal.item(k));
 
 105                         fVariables[k + length] = var;
 
 109         /*public void evaluateChange(IStackFrame OldStackFrame) throws DebugException {
 
 110                 IVariable[] OldVariable = ((XDebugStackFrame) OldStackFrame).getVariables();
 
 111                 for (int i = 0; i < fVariables.length; i++) {
 
 112                         ((XDebugVariable) fVariables[i]).setChange(OldVariable[i]);
 
 117          * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
 
 119         public boolean hasVariables() throws DebugException {
 
 120                 /*return fVariables.length > 0;*/
 
 125          * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
 
 127         public int getLineNumber() throws DebugException {
 
 132          * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
 
 134         public int getCharStart() throws DebugException {
 
 139          * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
 
 141         public int getCharEnd() throws DebugException {
 
 145         /* (non-Javadoc)fName
 
 146          * @see org.eclipse.debug.core.model.IStackFrame#getName()
 
 148         public String getName() throws DebugException {
 
 149                 return fName.toString()+"::"+fWhere+ " line: "+ fLineNumber;
 
 153          * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
 
 155         public IRegisterGroup[] getRegisterGroups() throws DebugException {
 
 160          * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
 
 162         public boolean hasRegisterGroups() throws DebugException {
 
 167          * @see org.eclipse.debug.core.model.IStep#canStepInto()
 
 169         public boolean canStepInto() {
 
 170                 return fThread.canStepInto();
 
 174          * @see org.eclipse.debug.core.model.IStep#canStepOver()
 
 176         public boolean canStepOver() {
 
 177                 return fThread.canStepOver();
 
 181          * @see org.eclipse.debug.core.model.IStep#canStepReturn()
 
 183         public boolean canStepReturn() {
 
 184                 return fThread.canStepReturn();
 
 188          * @see org.eclipse.debug.core.model.IStep#isStepping()
 
 190         public boolean isStepping() {
 
 191                 return fThread.isStepping();
 
 195          * @see org.eclipse.debug.core.model.IStep#stepInto()
 
 197         public void stepInto() throws DebugException {
 
 202          * @see org.eclipse.debug.core.model.IStep#stepOver()
 
 204         public void stepOver() throws DebugException {
 
 209          * @see org.eclipse.debug.core.model.IStep#stepReturn()
 
 211         public void stepReturn() throws DebugException {
 
 212                 fThread.stepReturn();
 
 216          * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
 
 218         public boolean canResume() {
 
 219                 return fThread.canResume();
 
 223          * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
 
 225         public boolean canSuspend() {
 
 226                 return fThread.canSuspend();
 
 230          * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
 
 232         public boolean isSuspended() {
 
 233                 return fThread.isSuspended();
 
 237          * @see org.eclipse.debug.core.model.ISuspendResume#resume()
 
 239         public void resume() throws DebugException {
 
 244          * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
 
 246         public void suspend() throws DebugException {
 
 251          * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
 
 253         public boolean canTerminate() {
 
 254                 return fThread.canTerminate();
 
 258          * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
 
 260         public boolean isTerminated() {
 
 261                 return fThread.isTerminated();
 
 265          * @see org.eclipse.debug.core.model.ITerminate#terminate()
 
 267         public void terminate() throws DebugException {
 
 272          * Returns the name of the source file this stack frame is associated
 
 275          * @return the name of the source file this stack frame is associated
 
 276          * with. If the file associated with this frame does not exists, it returns null.
 
 278         public String getSourceName() {
 
 282                 IPath a = new Path(fName.getFile());
 
 283                 return a.lastSegment();
 
 286         public boolean isSameStackFrame(Object obj) {
 
 287                 boolean isSameStackFrame = false;
 
 289                 if (obj instanceof XDebugStackFrame) {
 
 290                         XDebugStackFrame sf = (XDebugStackFrame)obj;
 
 292                                 isSameStackFrame = sf.getSourceName().equals(getSourceName()) &&
 
 293                                         /*sf.getLineNumber() == getLineNumber() &&*/
 
 294                                         /*sf.getLevel() == getLevel() &&*/
 
 295                                         sf.getType().equals(getType()) &&
 
 296                                         sf.getWhere().equals(getWhere()); //&&
 
 298                         /*} catch (DebugException e) {
 
 302                 return isSameStackFrame;
 
 306          * @see java.lang.Object#equals(java.lang.Object)
 
 308         public boolean equals(Object obj) {
 
 309                 if (obj instanceof XDebugStackFrame) {
 
 310                         XDebugStackFrame sf = (XDebugStackFrame)obj;
 
 312                                 return sf.getSourceName().equals(getSourceName()) &&
 
 313                                         sf.getLineNumber() == getLineNumber() &&
 
 314                                         sf.getLevel() == getLevel() &&
 
 315                                         sf.getType().equals(getType()) &&
 
 316                                         sf.getWhere().equals(getWhere());
 
 317 /*                                      sf.getType() == getType() &&
 
 318                                         sf.getWhere() == getWhere() &&*/
 
 320                         } catch (DebugException e) {
 
 328          * @see java.lang.Object#equals(java.lang.Object)
 
 330         public boolean equalsOld(Object obj) {
 
 331                 if (obj instanceof XDebugStackFrame) {
 
 332                         XDebugStackFrame sf = (XDebugStackFrame)obj;
 
 334                                 return sf.getSourceName().equals(getSourceName()) &&
 
 335                                         sf.getLineNumber() == getLineNumber() &&
 
 337                         } catch (DebugException e) {
 
 344          * @see java.lang.Object#hashCode()
 
 346         public int hashCode() {
 
 347                 return getSourceName().hashCode() + fLevel;
 
 352          * @return this stack frame's unique identifier within its thread
 
 354         /*protected int getIdentifier() {
 
 358         public URL getFullName() {
 
 363         public int getLevel() {
 
 367         public String getType() {
 
 371         public String getWhere() {
 
 375         public boolean setVariableValue(XDebugVariable variable, String expression)  throws DebugException {
 
 376                 return ((XDebugTarget) getDebugTarget()).setVarValue("$" + variable.getName(), expression);