Avoid ArrayIndexOutOfBoundsException which occurs at changing value of variable.
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPVariable.java
index 0cdad2a..40519a2 100644 (file)
@@ -14,7 +14,10 @@ package net.sourceforge.phpdt.internal.debug.core.model;
 
 import java.util.Vector;
 
+import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
+
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.model.IDebugTarget;
@@ -32,7 +35,6 @@ public class PHPVariable implements IVariable {
        private PHPStackFrame   fStackFrame;                            // The stackframe this variable belongs to
        private PHPVariable     fParent;                                // The parent variable (a back link)
        private String                  fLongName;                              // ???
-       private boolean         fHasChanged;                                                    //
 
        /**
         *
@@ -55,7 +57,6 @@ public class PHPVariable implements IVariable {
                this.fStackFrame = frame;
                this.fValue      = new PHPValue (frame, value, valueType, subitems);
                this.fParent     = parent;
-               this.fHasChanged = false;
 
                setName (name);
        }
@@ -64,7 +65,7 @@ public class PHPVariable implements IVariable {
         *
         * @param name
         */
-       private void setName (String name) {
+       public void setName (String name) {
                if ((fParent == null) ||                                                                        // If we have no parent for this variable
                    (fParent.getName () == "")) {                           //  or we have a parent which is just a simple node ???
                        fLongName = name;                                       // Set the long name
@@ -154,9 +155,7 @@ public class PHPVariable implements IVariable {
         * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
         */
        public boolean hasValueChanged() throws DebugException {
-               // TODO Auto-generated method stub
-               // return false;
-               return fHasChanged;
+               return fValue.hasValueChanged ();
        }
 
        /**
@@ -167,7 +166,7 @@ public class PHPVariable implements IVariable {
         *                a different color.
         */
        public void setValueChanged (boolean changed) {
-               fHasChanged = changed;
+               fValue.setValueChanged (changed);
        }
 
     /**
@@ -201,6 +200,20 @@ public class PHPVariable implements IVariable {
                else
                        evalString=fLongName+"="+expression;
                PHPVariable[] vars=fStackFrame.getPHPDBGProxy().eval(fStackFrame,evalString);
+
+               if (vars == null || vars.length == 0) {
+                       vars = fStackFrame.getPHPDBGProxy().eval(fStackFrame, fLongName);
+                       if (vars == null || vars.length == 0) {
+                               // TODO code and message
+                               int code = 0;
+                               String msg = "Could not assign and get variable";
+                               Status status = new Status(Status.ERROR,
+                                               PHPDebugCorePlugin.PLUGIN_ID, code, msg, null);
+                               PHPDebugCorePlugin.log(status);
+                               throw new DebugException(status);
+                       }
+               }
+
                setValue(vars[0].fValue);
        }