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;
 
  11 //import net.sourceforge.phpeclipse.xdebug.core.Base64;
 
  12 //import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
 
  13 //import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
 
  14 //import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.XDebugResponse;
 
  16 import org.eclipse.core.runtime.IPath;
 
  17 import org.eclipse.core.runtime.Path;
 
  18 import org.eclipse.debug.core.DebugException;
 
  19 import org.eclipse.debug.core.model.IRegisterGroup;
 
  20 import org.eclipse.debug.core.model.IStackFrame;
 
  21 import org.eclipse.debug.core.model.IThread;
 
  22 import org.eclipse.debug.core.model.IVariable;
 
  23 import org.w3c.dom.Node;
 
  24 import org.w3c.dom.NodeList;
 
  27  * @author PHPeclipse team
 
  31 public class XDebugStackFrame  extends XDebugElement implements IStackFrame {
 
  32         private XDebugThread fThread;
 
  38         private int fLineNumber;
 
  41         private String fWhere;
 
  43         private IVariable[] fVariables;
 
  45         private int fStepCount = 0;
 
  48          * Constructs a stack frame in the given thread with the given
 
  52          * @param data frame data
 
  53          * @param id stack frame id (0 is the bottom of the stack)
 
  55         public XDebugStackFrame(XDebugThread thread, int id) {
 
  56                 super(thread == null ? null : (XDebugTarget) thread.getDebugTarget());
 
  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) {
 
  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                 //String a = fName.getFile();
 
 143                 //return fName.lastSegment().toString()+"::"+fWhere+ " line: "+ fLineNumber;
 
 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;
 
 287                                 isSameStackFrame = sf.getSourceName().equals(getSourceName()) &&
 
 288                                         /*sf.getLineNumber() == getLineNumber() &&*/
 
 289                                         /*sf.getLevel() == getLevel() &&*/
 
 290                                         sf.getType().equals(getType()) &&
 
 291                                         sf.getWhere().equals(getWhere()); //&&
 
 293                         /*} catch (DebugException e) {
 
 297                 return isSameStackFrame;
 
 301          * @see java.lang.Object#equals(java.lang.Object)
 
 303         public boolean equals(Object obj) {
 
 304                 if (obj instanceof XDebugStackFrame) {
 
 305                         XDebugStackFrame sf = (XDebugStackFrame)obj;
 
 307                                 return sf.getSourceName().equals(getSourceName()) &&
 
 308                                         sf.getLineNumber() == getLineNumber() &&
 
 309                                         sf.getLevel() == getLevel() &&
 
 310                                         sf.getType().equals(getType()) &&
 
 311                                         sf.getWhere().equals(getWhere());
 
 312 /*                                      sf.getType() == getType() &&
 
 313                                         sf.getWhere() == getWhere() &&*/
 
 315                         } catch (DebugException e) {
 
 323          * @see java.lang.Object#equals(java.lang.Object)
 
 325         public boolean equalsOld(Object obj) {
 
 326                 if (obj instanceof XDebugStackFrame) {
 
 327                         XDebugStackFrame sf = (XDebugStackFrame)obj;
 
 329                                 return sf.getSourceName().equals(getSourceName()) &&
 
 330                                         sf.getLineNumber() == getLineNumber() &&
 
 332                         } catch (DebugException e) {
 
 339          * @see java.lang.Object#hashCode()
 
 341         public int hashCode() {
 
 342 //              return getSourceName().hashCode() + fId;
 
 343                 return getSourceName().hashCode() + fLevel;
 
 348          * @return this stack frame's unique identifier within its thread
 
 350         protected int getIdentifier() {
 
 355         public void setFullName(URL name) {
 
 360         public URL getFullName() {
 
 365         public int getLevel() {
 
 369         public void setLevel(int level) {
 
 374         public String getType() {
 
 378         public void setType(String type) {
 
 382         public String getWhere() {
 
 386         public void setWhere(String where) {
 
 390         public void setLineNumber(int newlineNumber) {
 
 391                 fLineNumber = newlineNumber;