1) Added a vector for storing the variables.
authorrobekras <robekras>
Sun, 16 Oct 2005 18:11:44 +0000 (18:11 +0000)
committerrobekras <robekras>
Sun, 16 Oct 2005 18:11:44 +0000 (18:11 +0000)
2) getVariables now read the variables as a vector list.
3) Added a findVariable method which can be called recursiv (which looks for a variable through the entire variable tree).
4) Changed the 'old' findVariable method the call the new method (means hover works now).
5) Added setIndex method for stackframe replication.
6) Added compareTo method for stackframe list sorting.

net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java

index 4130898..a819140 100644 (file)
@@ -11,6 +11,8 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpdt.internal.debug.core.model;
 
+import java.util.Vector;
+
 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
 
 import org.eclipse.debug.core.DebugEvent;
@@ -23,14 +25,20 @@ import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.model.IThread;
 import org.eclipse.debug.core.model.IVariable;
 
-public class PHPStackFrame extends PHPDebugElement implements IStackFrame {
+/**
+ *
+ * TODO Remove the variables array and use only the varList vector
+ *      Have also to change hasVariables
+ */
+public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Comparable{
 
        private PHPThread               thread;                         // The thread to which this stackframe belongs
        private String                  file;               // The file name???
        private int                     lineNumber;         //
        private int                     index;              //
        private int                     modno;              //
-       private PHPVariable[]   variables;          // The array of variables
+       private PHPVariable[]   variables;          // The array of variables TODO: better introduce a vector?
+       private Vector          varList  = new Vector ();
        private String                  description;        //
 
        /**
@@ -96,39 +104,60 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame {
         * @return The array of PHPVariables for this stackframe.
         */
        public IVariable[] getVariables() throws DebugException {
-               PHPVariable[] variablesNew;                                 // The intermediate storage of the variable array we get from DBG proxy
+               //PHPVariable[] variablesNew;                                 // The intermediate storage of the variable array we get from DBG proxy
+
+               //variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy
+               //variables    = variablesNew;                                // Store the array the stackframes member variable
+               varList   = this.getPHPDBGProxy ().readVariables (this);
 
-               variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy
-               variables    = variablesNew;                                // Store the array the stackframes member variable
+               variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
 
                return variables;                                           // Give the array back to user interface
        }
 
        /**
-        * TODO Is this really used (who calls this)
-        * I think this method could be removed
         *
-        * @param s The variables name we are looking for.
-        * @return
         */
-       public IVariable findVariable (String s) throws DebugException {
-               String name;
-               int    i;
-
-               if (this.hasVariables ()) {                                                                     // Does this stackframe have variables?
-                       name = "$" + s;                                         // Prefix the variable name with $
-
-                       for (i = 0; i < variables.length; i++) {                // For all variables
-                               if ((variables[i].getName ()).equals (name)) {
-                                       return variables[i];
+       private PHPVariable findVariable (Vector varList, String varname) {
+               PHPVariable     variable;
+               PHPValue        value;
+               int                     i;
+
+               for (i = 0; i < varList.size (); i++) {                                         // For all variables
+                       variable = (PHPVariable) varList.get (i);                               // Get the variable
+                       value    = (PHPValue) variable.getValue ();                             // Get the value of the variable
+
+                       try {
+                               if (value.hasVariables ()) {                                            // Does the variable/value have children
+                                       variable = findVariable (value.getChildVariables (), varname);
+
+                                       if (variable != null) {
+                                               return variable;
+                                       }
+                               }
+                               else if ((variable.getName ()).equals (varname)) {      //
+                                       return variable;                                                                //
                                }
                        }
+                       catch (DebugException e) {                                                              // That's, because of the hasVariables method
+                       }
                }
 
                return null;
        }
 
        /**
+        * This method is called from the UI (e.g. from PHPDebugHover
+        * to find the variable the mouse is pointing to)
+        *
+        * @param s The variable name we are looking for.
+        * @return
+        */
+       public IVariable findVariable (String s) throws DebugException {
+               return (findVariable (varList, s));                                                     // Prefix the variable name with $
+       }
+
+       /**
         *
         */
        public boolean hasVariables () throws DebugException {
@@ -287,6 +316,10 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame {
                return index;
        }
 
+       public void setIndex (int index) {
+               this.index = index;
+       }
+
        public PHPDBGProxy getPHPDBGProxy() {
                PHPDebugTarget DebugTarget;
 
@@ -302,4 +335,27 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame {
        public int getModNo() {
                return modno;
        }
+
+       /**
+        * This function is needed when sorting the stackframes by their index numbers.
+        *
+        * @param obj The stackframe which this one is compared to.
+        * @return
+        * <ul>
+        * <li> -1 if the index of this stackframe is less.
+        * <li> 0 if the index of both stackfream is equal (should no happen).
+        * <li> 1 if the index of this stackfram is greater.
+        * </ul>
+        */
+       public int compareTo (Object obj)
+       {
+               if (index < ((PHPStackFrame) obj).getIndex ()) {
+                       return -1;
+               }
+               else if (index > ((PHPStackFrame) obj).getIndex ()) {
+                       return 1;
+               }
+
+               return 0;
+       }
 }