Fix variable view value modification and refactored XDebugAbstractValue and derived...
authorincastrix <incastrix>
Wed, 28 Jan 2009 15:35:43 +0000 (15:35 +0000)
committerincastrix <incastrix>
Wed, 28 Jan 2009 15:35:43 +0000 (15:35 +0000)
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugAbstractValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugArrayValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugBooleanValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugFloatValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugIntValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugObjectValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugResourceValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStringValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugValue.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java

index 32ea3fa..eb91e5b 100644 (file)
@@ -5,15 +5,12 @@
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
-import net.sourceforge.phpeclipse.xdebug.core.Base64;
 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
 
-import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IValue;
 import org.eclipse.debug.core.model.IVariable;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 /**
  * @author Axel
@@ -22,52 +19,26 @@ import org.w3c.dom.NodeList;
  * Window - Preferences - Java - Code Style - Code Templates
  */
 
-public abstract class XDebugAbstractValue  extends XDebugElement implements IValue {
+public /*abstract*/ class XDebugAbstractValue  extends XDebugElement implements IValue {
        private IVariable[] fVariables;
        private String fValueString;
        private String fTypeName;
        private boolean fhasChanged;
+       protected String rowValue;
+       
+       public XDebugAbstractValue(XDebugStackFrame frame, Node value) throws DebugException  {
+               super(frame == null ? null : (XDebugTarget)frame.getDebugTarget());
 
-       public XDebugAbstractValue(XDebugStackFrame frame, Node varNode) throws DebugException  {
-               super(frame == null ? null : (XDebugTarget) frame.getDebugTarget());
-
-               fTypeName = PHPDebugUtils.getAttributeValue(varNode,"type");
-
-               int NumChildren = 0;
-               if (!PHPDebugUtils.getAttributeValue(varNode,"numchildren").equals("")) {
-                       NumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(varNode, "numchildren"));
-               }               
-
-               if (NumChildren > 0) {
-                       NodeList property = varNode.getChildNodes();
-                       renderValueString(""+property.getLength());
-                       fVariables = new IVariable[property.getLength()];
-                       for (int i = 0; i<property.getLength(); i++) {
-                               Node propertyNode = property.item(i);
-                               fVariables[i] = new XDebugVariable(frame, propertyNode);
-                       }
-               }else {
-                       fVariables = new IVariable[0];
-                       String str="";
-                       try {
-                               str=varNode.getFirstChild().getNodeValue();
-                       } catch (NullPointerException e) {
-                               str="";
-                       }
+               fTypeName = PHPDebugUtils.getAttributeValue(value, "type");
+               
+               fVariables = new IVariable[0];
 
-                       String Encoding = PHPDebugUtils.getAttributeValue(varNode,"encoding");
-                       
-                       if (Encoding.equals("base64")) {
-                               if (str.length()!=0)
-                                       str=new String(Base64.decode(str));
-                               else
-                                       str="";
-                       }
-                       renderValueString(str);
+               rowValue = "";
+               try {
+                       rowValue = value.getFirstChild().getNodeValue();
+               } catch (NullPointerException e) {
+                       rowValue = "";
                }
-               String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
-               if(!"".equals(className))
-                       renderValueString(className);
        }
        
        public boolean hasChanged() {
@@ -109,26 +80,23 @@ public abstract class XDebugAbstractValue  extends XDebugElement implements IVal
                return (fVariables.length > 0);
        }
        
-       public abstract void renderValueString(String data) throws DebugException;
-
-       public abstract boolean verifyValue(String expression);
-       
        public boolean setValue(String expression) throws DebugException {
-               if (!verifyValue(expression)) {
-                       return false;
-               }
-               
-               renderValueString(expression);
-               fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
-        
+               return true;
+       };
+       
+       protected boolean verifyValue(String expression) {
                return true;
        }
        
-       public boolean supportsValueModification() {
+       protected boolean supportsValueModification() {
                return false;
        }
        
-       public void setValueString(String valueString) {
+       protected void setValueString(String valueString) {
                fValueString = valueString;
        }
+
+       protected void setChildren(IVariable[] newChildren) {
+               fVariables = newChildren;
+       }
 }
\ No newline at end of file
index 7a1dbad..6174c3e 100644 (file)
@@ -1,26 +1,46 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
+
 import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IVariable;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class XDebugArrayValue extends XDebugAbstractValue {
+       private int NumChildren;
+
        public XDebugArrayValue(XDebugStackFrame variable, Node value) throws DebugException {
                super(variable, value);
+
+               NumChildren = 0;
+               if (!PHPDebugUtils.getAttributeValue(value, "numchildren").equals("")) {
+                       NumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(value, "numchildren"));
+               }               
+
+               if (NumChildren > 0) {
+                       NodeList property = value.getChildNodes();
+                       renderValueString(""+property.getLength());
+                       IVariable[] Variables = new IVariable[property.getLength()];
+                       
+                       for (int i = 0; i<property.getLength(); i++) {
+                               Node propertyNode = property.item(i);
+                               Variables[i] = new XDebugVariable(variable, propertyNode);
+                       }
+                       
+                       setChildren(Variables);
+               }
        }
 
-       public void renderValueString(String data) throws DebugException  {
+       private void renderValueString(String data) throws DebugException  {
                if (data.equals("")) {
-                       setValueString("empty")/*fValueString = "empty"*/;
+                       setValueString("empty");
                } else {
                        if ("array".equals(getReferenceTypeName())) {
-                               setValueString("array")/*fValueString = "array"*/;
+                               setValueString("array(" + NumChildren + ")");
                        } else {
-                               setValueString(data)/*fValueString = data*/;
+                               setValueString(data);
                        }
                }
        }
-
-       public boolean verifyValue(String expression) {
-               return false;
-       }
 }
\ No newline at end of file
index 1960aa9..e826240 100644 (file)
@@ -1,49 +1,54 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.w3c.dom.Node;
 
 public class XDebugBooleanValue extends XDebugAbstractValue {
        public XDebugBooleanValue(XDebugStackFrame variable, Node value) throws DebugException {
                super(variable, value);
+
+               renderValueString(rowValue);
        }
        
        public boolean supportsValueModification() {
                return true;
        }
 
-       public void renderValueString(String data) {
-               int value=-1;
-               try {
-                       value=Integer.parseInt(data);
-               } catch (NumberFormatException e) {
-                       data=data.toLowerCase();
-                       if (data.equals("true") || data.equals("false"))
-                               setValueString(data)/*fValueString=data*/;
-                       else
-                               setValueString("not defined")/*fValueString="not defined"*/;
+       public boolean setValue(String expression) throws DebugException {
+               if (isValid(expression)) {
+                       renderValueString(expression);
+                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
+                       return true;
                }
-               if (value==0) 
-                       setValueString("false")/*fValueString="false"*/;
-               else if (value==1)
-                       setValueString("false")/*fValueString="true"*/;
-               else
-                       setValueString("not defined")/*fValueString="not defined"*/;
+               return false;
        }
 
-       public boolean verifyValue(String expression) {
-               int value=-1;
+       private void renderValueString(String data) {
+               if (data.equals("0") || data.toLowerCase().equals("false")) { 
+                       setValueString("false");
+               } else if (data.equals("1") || data.toLowerCase().equals("true")) {
+                       setValueString("true");
+               }
+       }
+
+       private boolean isValid(String expression) {
+               int value = -1;
                try {
-                       value=Integer.parseInt(expression);
+                       value = Integer.parseInt(expression);
                } catch (NumberFormatException e) {
-                       expression=expression.toLowerCase();
+                       expression = expression.toLowerCase();
                        if (expression.equals("true") || expression.equals("false"))
                                return true;
                        else
                                return false;
                }
-               if ((value>=0)&& (value <=1))
+               if ((value >= 0)&& (value <= 1))
                        return true;
                return false;
        }
+       
+       public boolean verifyValue(String expression) {
+               return isValid(expression);
+       }
 }
\ No newline at end of file
index 990e371..fd2e709 100644 (file)
@@ -1,22 +1,37 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.w3c.dom.Node;
 
 public class XDebugFloatValue extends XDebugAbstractValue {
-       public XDebugFloatValue(XDebugStackFrame variable, Node value) throws DebugException {
-               super(variable, value);
+       public XDebugFloatValue(XDebugStackFrame stackFrame, Node value) throws DebugException {
+               super(stackFrame, value);
+
+               if (isValid(rowValue)) {
+                       setValueString(rowValue);
+               }
        }
        
        public boolean supportsValueModification() {
                return true;
        }
 
-       public void renderValueString(String data) {
-               setValueString(data)/*fValueString = data*/;
+       public boolean setValue(String expression) throws DebugException {
+               if (isValid(expression)) {
+                       setValueString(expression);
+                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
+                       return true;
+               }
+               
+               return false;
        }
 
        public boolean verifyValue(String expression) {
+               return isValid(expression);
+       }
+
+       private boolean isValid(String expression) {
                try {
                        Float.parseFloat(expression);
                } catch (NumberFormatException e) {
index f45eaa8..010c2a9 100644 (file)
@@ -1,22 +1,33 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.w3c.dom.Node;
 
 public class XDebugIntValue extends XDebugAbstractValue {
-       public XDebugIntValue(XDebugStackFrame frame, Node value) throws DebugException {
-               super(frame, value);
+       public XDebugIntValue(XDebugStackFrame stackFrame, Node value) throws DebugException {
+               super(stackFrame, value);
+
+               if (isValid(rowValue)) {
+                       setValueString(rowValue);
+               }
        }
        
        public boolean supportsValueModification() {
                return true;
        }
                
-       public void renderValueString(String dataString) {
-               setValueString(dataString)/*fValueString = dataString*/;
+       public boolean setValue(String expression) throws DebugException {
+               if (isValid(expression)) {
+                       setValueString(expression);
+                       fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
+                       return true;
+               }
+               
+               return false;
        }
-       
-       public boolean verifyValue(String expression) {
+
+       private boolean isValid(String expression) {
                try {
                        Integer.parseInt(expression);
                } catch (NumberFormatException e) {
@@ -24,4 +35,8 @@ public class XDebugIntValue extends XDebugAbstractValue {
                }
                return true;
        }
+
+       public boolean verifyValue(String expression) {
+               return isValid(expression);
+       }
 }
\ No newline at end of file
index 01fabba..1af871a 100644 (file)
@@ -1,18 +1,38 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
+
 import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IVariable;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class XDebugObjectValue extends XDebugAbstractValue {
+       private int NumChildren;
+
        public XDebugObjectValue(XDebugStackFrame variable, Node value) throws DebugException {
                super(variable, value);
-       }
 
-       public void renderValueString(String data) {
-               setValueString(data)/*fValueString = data*/;
-       }
+               NumChildren = 0;
+               if (!PHPDebugUtils.getAttributeValue(value, "numchildren").equals("")) {
+                       NumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(value, "numchildren"));
+               }               
 
-       public boolean verifyValue(String expression) {
-               return false;
+               if (NumChildren > 0) {
+                       NodeList property = value.getChildNodes();
+                       IVariable[] Variables = new IVariable[property.getLength()];
+                       
+                       for (int i = 0; i<property.getLength(); i++) {
+                               Node propertyNode = property.item(i);
+                               Variables[i] = new XDebugVariable(variable, propertyNode);
+                       }
+                       
+                       setChildren(Variables);
+               }
+               
+               String className = PHPDebugUtils.getAttributeValue(value,"classname");
+               if(!"".equals(className)) {
+                       setValueString(className);
+               }
        }
 }
\ No newline at end of file
index 2edb55f..87cf6c3 100644 (file)
@@ -9,14 +9,6 @@ public class XDebugResourceValue extends XDebugAbstractValue {
        }
 
        public void renderValueString(String data) {
-               setValueString("\"" + data + "\"")/*fValueString = "\"" + data + "\""*/;
-       }
-
-       public boolean supportsValueModification() {
-               return true;
-       }
-
-       public boolean verifyValue(String expression) {
-               return true;
+               setValueString("\"" + data + "\"");
        }
 }
\ No newline at end of file
index 841b9b7..58bcf24 100644 (file)
@@ -1,22 +1,27 @@
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import net.sourceforge.phpeclipse.xdebug.core.Base64;
+
+import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.w3c.dom.Node;
 
 public class XDebugStringValue extends XDebugAbstractValue {
        public XDebugStringValue(XDebugStackFrame variable, Node value) throws DebugException {
                super(variable, value);
-       }
 
-       public void renderValueString(String data) {
-               setValueString("\"" + data + "\"")/*fValueString = "\"" + data + "\""*/;
+               rowValue = new String(Base64.decode(rowValue));
+
+               setValueString(rowValue);
        }
 
-       public boolean supportsValueModification() {
+       public boolean setValue(String expression) throws DebugException {
+               setValueString(expression);
+               fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
                return true;
        }
 
-       public boolean verifyValue(String expression) {
+       public boolean supportsValueModification() {
                return true;
        }
 }
\ No newline at end of file
index 89be6d5..3847ae6 100644 (file)
@@ -6,13 +6,7 @@ import org.w3c.dom.Node;
 public class XDebugValue extends XDebugAbstractValue {
        public XDebugValue(XDebugStackFrame variable, Node value) throws DebugException {
                super(variable, value);
-       }
-       
-       public void renderValueString(String data) {
-               setValueString("uninitialized")/*fValueString = "uninitialized"*/;
-       }
 
-       public boolean verifyValue(String expression) {
-               return false;
+               setValueString("uninitialized");
        }
 }
\ No newline at end of file
index 0ab3875..240ec9c 100644 (file)
@@ -57,10 +57,8 @@ public class XDebugVariable extends XDebugElement implements IVariable {
                        fValue = new XDebugStringValue(frame, property);
                else if (typeName.equals("array") )
                        fValue = new XDebugArrayValue(frame, property);
-               else if (typeName.equals("hash") )
-                       fValue = new XDebugArrayValue(frame, property);
                else if (typeName.equals("object") )
-                       fValue = new XDebugArrayValue(frame, property);
+                       fValue = new XDebugObjectValue(frame, property);
                else if (typeName.equals("resource") )
                        fValue = new XDebugResourceValue(frame, property);
                else
@@ -121,7 +119,7 @@ public class XDebugVariable extends XDebugElement implements IVariable {
         * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
         */
        public boolean verifyValue(String expression) throws DebugException {
-               return fValue.verifyValue(expression);
+               /*return true; */return fValue.verifyValue(expression);
        }
 
        /* (non-Javadoc)