1) Although dbg will be dropped from being supported or bundled with PHPeclipse,...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPStackFrame.java
index 245dc76..7bede78 100644 (file)
@@ -11,6 +11,7 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpdt.internal.debug.core.model;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Vector;
 
@@ -33,17 +34,19 @@ import org.eclipse.debug.core.model.IVariable;
 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 String              file;                                       // The file name???
        private int                     lineNumber;
        private int                     index;
        private int                     modno;
+       private PHPVariable[]   variables;              //
        private int                     scope_id;                               // scope id
-       private Vector          varList;                                // Variables list
-       private String          description;                    // The source file name with the full path on target/remote system
+       private Vector                  varList;                                // Variables list
+       private String          description;                    // The source file name with the full path on target/remote system
        private boolean                 fUpToDate;                              // Indicates whether the variable list within this stackframe is
                                                                                                        // up-to-date
        private boolean                 fAvailable;                     // Needed when updating the stackframe list, shows whether the stackframe
                                                                                                        // is within the list which was received from dbg
+       private boolean         fDebug      = true;
 
        /**
         *
@@ -55,19 +58,19 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         * @param modno
         * @param scope_id
         */
-       public PHPStackFrame(PHPThread thread, String file, int line, int index,
-                       String desc, int modno, int scope_id) {
-               super(null);
-
-               this.lineNumber = line;
-               this.index = index;
-               this.file = file;
-               this.thread = thread;
+       public PHPStackFrame (PHPThread thread, String file, int line, int index,
+                                     String desc, int modno, int scope_id) {
+               super (null);
+
+               this.lineNumber  = line;
+               this.index       = index;
+               this.file        = file;
+               this.thread      = thread;
                this.description = desc;
-               this.modno = modno;
-               this.scope_id = scope_id;
-               this.varList = new Vector();
-               this.fUpToDate = false;
+               this.modno       = modno;
+               this.scope_id    = scope_id;
+               this.varList     = new Vector();
+               this.fUpToDate   = false;
        }
 
 //     /**
@@ -88,7 +91,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 //     }
 
        /**
-        * 
+        *
         * @return scope id
         */
        public int getScopeID() {
@@ -96,7 +99,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
        }
 
        /**
-        * 
+        *
         */
        public void setScopeID(int scope_id) {
                this.scope_id = scope_id;
@@ -187,7 +190,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         *
         * TODO Check where this recursion can come from.
         * Whether this back reference is legal or a bug.
-        * 
+        *
         * Typically $GLOBALS contains $GLOBALS
         *
         * @param var
@@ -197,17 +200,17 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         * <li> true if the PHPValue is
         * </ul>
         */
-       private boolean hasRecursion(PHPVariable var) {
+       private boolean hasRecursion (PHPVariable var) {
                PHPVariable parentVar;
                PHPValue        val;
 
-               val = (PHPValue) var.getValue();                                                        // Get the PHPValue from the current PHPVariable
+               val = (PHPValue) var.getValue ();                                                       // Get the PHPValue from the current PHPVariable
 
                while (var != null) {                                                                           // As long as we have PHPVariable
-                       parentVar = var.getParent();                                                    // Get the parent PHPVariable
+                       parentVar = var.getParent ();                                                   // Get the parent PHPVariable
 
                        if (parentVar != null) {                                                                // Is there a parent?
-                               if (parentVar.getValue().equals(val)) {                         // Get the PHPValue for the parent PHPVariable and check
+                               if (parentVar.getValue ().equals (val)) {                       // Get the PHPValue for the parent PHPVariable and check
                                                                                                                                        // whether it is the same
                                        return true;                                                                    // Return, if we have recursion
                                }
@@ -238,7 +241,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         * @param varListOld The 'static' list of variables which are to be updated.
         * @param varListNew The new list of (current) variables from DBG.
         */
-       private void updateVariableList(Vector varListOld, Vector varListNew) {
+       private void updateVariableList (Vector varListOld, Vector varListNew) {
                PHPVariable varOld;                                                                             // The variable from the 'static' list
                PHPVariable varNew;                                                                             // The variable from the DBG list
                PHPValue        valOld;                                                                                 // The value of the current variable from 'static' list
@@ -257,21 +260,24 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
                                varOld = (PHPVariable) varListOld.get(o);                       // Get the static variable
 
                                if (varNew.getName().equals(varOld.getName())) {        // Did we found the variable within the 'static' list?
-                                       valOld = (PHPValue) varOld.getValue();                  // Get the value from 'static'
-                                       valNew = (PHPValue) varNew.getValue();                  // Get the value from DBG
+                                       valOld = (PHPValue) varOld.getValue ();         // Get the value from 'static'
+                                       valNew = (PHPValue) varNew.getValue ();                 // Get the value from DBG
 
                                        try {
                                                if (valOld.hasVariables() ||                            // If the 'static' value has child variables
-                                                               valNew.hasVariables()) {                        //  or if the DBG value has child variables
-                                                       if (!hasRecursion(varOld) && !hasRecursion(varNew)) { // Both branches should not have a recursion
-                                                               updateVariableList(valOld.getChildVariables(), // Update the variable list for the child variables
-                                                                               valNew.getChildVariables());
+                                                       valNew.hasVariables()) {                                //  or if the DBG value has child variables
+                                                       if (!hasRecursion(varOld) &&
+                                                           !hasRecursion(varNew)) {            // Both branches should not have a recursion
+                                                               updateVariableList (
+                                                                      valOld.getChildVariables (), // Update the variable list for the child variables
+                                                                          valNew.getChildVariables ());
                                                        }
                                                }
-                                               if (!valOld.getValueString().equals(
-                                                               valNew.getValueString())) {             // Has the value changed?
-                                                       valOld.setValueString(valNew.getValueString()); // Yes, set the 'static' value (variable) to the new value
-                                                       varOld.setValueChanged(true);                   // and set the 'has changed' flag, so that the variable view
+
+                                               if (!valOld.getValueString ().equals (
+                                                                 valNew.getValueString ())) {          // Has the value changed?
+                                                       valOld.setValueString (valNew.getValueString ()); // Yes, set the 'static' value (variable) to the new value
+                                                       varOld.setValueChanged (true);                  // and set the 'has changed' flag, so that the variable view
                                                                                                                                        // could show the user the changed status with a different
                                                                                                                                        // color
                                                }
@@ -318,13 +324,20 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         */
        public IVariable[] getVariables() throws DebugException {
                if (!fUpToDate) {
-                       resetHasChangedInfo(varList);
-                       updateVariableList(varList, this.getPHPDBGProxy().readVariables(this));
+                       resetHasChangedInfo (varList);
+                       updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this));
                        fUpToDate = true;
-                       Collections.sort(varList, new PHPVariableComparator());
+
+                       variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
+                       Arrays.sort (variables, new PHPVariableComparator ());
+/*
+                       Collections.sort (varList, new PHPVariableComparator ());
+ */
                }
 
-               return (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]);
+//             return (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
+
+               return variables;                                           // Give the array back to user interface
        }
 
        /**
@@ -336,19 +349,21 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
                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
+                       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
-                                       if (!hasRecursion(variable)) {                                  // Don't follow recursive variable/values
-                                               PHPVariable var = findVariable(value.getChildVariables(), varname);
+                               if (value.hasVariables ()) {                                            // Does the variable/value have children
+                                       if (!hasRecursion (variable)) {                                 // Don't follow recursive variable/values
+                                               PHPVariable var = findVariable (value.getChildVariables(), varname);
+
                                                if (var != null) {
                                                        return var;
                                                }
                                        }
                                }
-                               if (variable.getName().equals(varname)) {
+
+                               if (variable.getName().equals (varname)) {
                                        return variable;
                                }
                        } catch (DebugException e) {                                                    // That's, because of the hasVariables method
@@ -406,14 +421,18 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
                StringBuffer name = new StringBuffer();
 
                if (!this.getDescription().equals("")) {
-                       name.append(this.getDescription());
+                       name.append (this.getDescription());
                } else {
-                       name.append(this.getFileName());
+                       name.append (this.getFileName());
                }
 
-               name.append(" [line ");
-               name.append(this.getLineNumber());
-               name.append("]");
+               name.append (" [line ");
+               name.append (this.getLineNumber());
+               name.append ("]");
+
+        if (fDebug) {
+            System.out.println ("PHPStackFrame getName: " + name.toString ());
+        }
 
                return name.toString();
        }
@@ -474,14 +493,14 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 
                thread.prepareForResume(DebugEvent.STEP_INTO);                          // Don't know why, but this is necessary
                this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this);
-               
+
         // Commented out sending the RESUME event because it was already sent by prepareForResume.
         // The second RESUME event leads only to a little flickering within the variables view.
         // It is also not clear why this event was necessary in eclipse < 3.2
         // Also sending a SUSPEND event here leads to a total rebuild of the variables view.
         // (eclipse 3.2 has a build in timeout of 500 ms which leads to a auto suspend, with
         // no flickering... but why???)
-        // 
+        //
                //ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_INTO);
                //DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { ev });
        }
@@ -496,7 +515,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
                this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this);
 
         // See comment within the previous stepInto method.
-        // 
+        //
                //ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_OVER);
                //DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev });
        }
@@ -612,16 +631,19 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         * <li> 1 if the index of this stackframe is greater.
         * </ul>
         */
-       public int compareTo(Object obj) {
+       public int compareTo (Object obj) {
                if (!(obj instanceof PHPStackFrame)) {
-                       throw new IllegalArgumentException("A PHPStackFrame can only be compared with another PHPStackFrame");
+                       throw new IllegalArgumentException ("A PHPStackFrame can only be compared with another PHPStackFrame");
                }
+
                int frameIndex = ((PHPStackFrame) obj).getIndex();
+
                if (index < frameIndex) {
                        return -1;
                } else if (index > frameIndex) {
                        return 1;
                }
+
                return 0;
        }
 }