1) Made getVariables and evalBlock methods in PHPDBGInterface synchronized (At least...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPStackFrame.java
index e47f21d..dcd372e 100644 (file)
@@ -6,11 +6,12 @@ which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/cpl-v10.html
 
 Contributors:
-    IBM Corporation - Initial implementation
-    Vicente Fernando - www.alfersoft.com.ar
+       IBM Corporation - Initial implementation
+       Vicente Fernando - www.alfersoft.com.ar
 **********************************************************************/
 package net.sourceforge.phpdt.internal.debug.core.model;
 
+import java.util.Arrays;
 import java.util.Vector;
 
 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
@@ -39,8 +40,11 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
        private int                     modno;              //
        private PHPVariable[]   variables;          // The array of variables TODO: better introduce a vector?
        private Vector          varList  = new Vector ();
-       private String                  description;        //
-       private boolean         fUpToDate;          //
+       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
 
        /**
         *
@@ -110,6 +114,32 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 
        /**
         *
+        */
+       public void setAvailable (boolean available) {
+               fAvailable = available;
+       }
+
+       /**
+        *
+        */
+       public boolean isAvailable () {
+               return fAvailable;
+       }
+
+
+       /**
+        * @see IAdaptable#getAdapter(Class)
+        */
+       public Object getAdapter(Class adapter) {
+               if (adapter == PHPStackFrame.class) {
+                       return this;
+               }
+
+               return super.getAdapter(adapter);
+       }
+
+       /**
+        *
         *
         */
        private void resetHasChangedInfo (Vector varList) {
@@ -215,9 +245,9 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 
                                        try {
                                                if (valOld.hasVariables () ||                           // If the 'static' value has child variables
-                                                   valNew.hasVariables ()) {                           //  or if the DBG 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
+                                                               !hasRecursion (varNew)) {                       // Both branches should not have a recursion
                                                                updateVariableList (valOld.getChildVariables (),        // Update the variable list for the child variables
                                                                                                        valNew.getChildVariables ());
                                                        }
@@ -278,17 +308,13 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         * @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
-
-               //variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy
-               //variables    = variablesNew;                                // Store the array the stackframes member variable
-
                if (!isUpToDate ()) {
                        resetHasChangedInfo (varList);
-               updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this));
+                       updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this));
                        setUpToDate (true);
 
                        variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
+                       Arrays.sort(variables, new PHPVariableComparator());
                }
 
                return variables;                                           // Give the array back to user interface
@@ -337,7 +363,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
        public IVariable findVariable (String s) throws DebugException {
                if (!isUpToDate ()) {
                        resetHasChangedInfo (varList);
-               updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this));
+                       updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this));
                        setUpToDate (true);
 
                        variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
@@ -350,7 +376,8 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
         *
         */
        public boolean hasVariables () throws DebugException {
-               return (varList.size () > 0);
+               return true;
+               // return (varList.size () > 0);
        }
 
        public int getLineNumber() {
@@ -372,10 +399,20 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
        }
 
        public String getName() {
-               if(!this.getDescription().equals(""))
-                       return this.getDescription() + " [line: " + this.getLineNumber() + "]";
-               else
-                       return this.getFileName() + " [line: " + this.getLineNumber() + "]";
+               StringBuffer name = new StringBuffer();
+
+               if (!this.getDescription().equals ("")) {
+                       name.append (this.getDescription ());
+               }
+               else {
+                       name.append (this.getFileName ());
+               }
+
+               name.append (" [line ");
+               name.append (this.getLineNumber ());
+               name.append ("]");
+
+               return name.toString();
        }
 
        public String getFileName() {
@@ -434,11 +471,18 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 
                setUpToDate (false);
 
-        thread.prepareForResume (DebugEvent.STEP_INTO);             // Don't know why, but this is necessary
+               thread.prepareForResume (DebugEvent.STEP_INTO);             // Don't know why, but this is necessary
                this.getPHPDBGProxy ().readStepIntoEnd (PHPStackFrame.this);
-
-               ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_INTO);
-               DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { ev });
+               
+        // 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 });
        }
 
        /**
@@ -449,11 +493,13 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 
                setUpToDate (false);
 
-        thread.prepareForResume (DebugEvent.STEP_OVER);
+               thread.prepareForResume (DebugEvent.STEP_OVER);
                this.getPHPDBGProxy ().readStepOverEnd (PHPStackFrame.this) ;
 
-               ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_OVER);
-               DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev });
+        // See comment within the previous stepInto method.
+        // 
+               //ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_OVER);
+               //DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev });
        }
 
        /**
@@ -464,7 +510,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa
 
                setUpToDate (false);
 
-        thread.prepareForResume (DebugEvent.STEP_RETURN);
+               thread.prepareForResume (DebugEvent.STEP_RETURN);
                this.getPHPDBGProxy ().readStepReturnEnd (PHPStackFrame.this) ;
 
                ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_RETURN);