1) Improvements for the XDebug plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugAbstractValue.java
index eb91e5b..df5c92a 100644 (file)
@@ -5,6 +5,9 @@
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Vector;
 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
 
 import org.eclipse.debug.core.DebugException;
@@ -20,83 +23,125 @@ import org.w3c.dom.Node;
  */
 
 public /*abstract*/ class XDebugAbstractValue  extends XDebugElement implements IValue {
-       private IVariable[] fVariables;
-       private String fValueString;
-       private String fTypeName;
-       private boolean fhasChanged;
-       protected String rowValue;
-       
+       private String          fValueString;
+       private String          fTypeName;
+       private boolean         fhasChanged;
+       protected String        rowValue;
+       private boolean         fSorted;
+       private Vector          fVariables;                                                     // The children of this variable (other variables) if any
+
        public XDebugAbstractValue(XDebugStackFrame frame, Node value) throws DebugException  {
                super(frame == null ? null : (XDebugTarget)frame.getDebugTarget());
 
-               fTypeName = PHPDebugUtils.getAttributeValue(value, "type");
-               
-               fVariables = new IVariable[0];
+               fTypeName     = PHPDebugUtils.getAttributeValue(value, "type");
+
+               fVariables    = new Vector();                                           // Create an empty vector
+               fValueString  = "";
+               rowValue      = "";
+               fSorted       = false;
 
-               rowValue = "";
                try {
                        rowValue = value.getFirstChild().getNodeValue();
                } catch (NullPointerException e) {
                        rowValue = "";
                }
        }
-       
+
        public boolean hasChanged() {
                return fhasChanged;
        }
-       
+
+       public void setChanged(boolean changed) {
+               fhasChanged = changed;
+       }
+
+       /**
+        *
+        * @param item
+        */
+       public Vector addVariable(Vector item) {
+               if (item != null) {                                                                             // If there is something we want to add
+                       fVariables.addAll(item);
+                       fSorted = false;
+               }
+
+               return this.fVariables;
+       }
+
+       /**
+        *
+        * @param parent
+        */
+       public void setParent(XDebugVariable parent) {
+               if (!fVariables.isEmpty()) {                                                            // If we have child variables
+                       Iterator iter = fVariables.iterator();                                  // Create an iterator for the children
+
+                       while (iter.hasNext()) {                                                                // As long as we have children
+                               ((XDebugVariable) iter.next()).setParent(parent);       // Set all child's parent
+                       }
+               }
+       }
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
         */
        public String getReferenceTypeName() throws DebugException {
                return fTypeName;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#getValueString()
         */
        public String getValueString() throws DebugException {
                return fValueString;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#isAllocated()
         */
        public boolean isAllocated() throws DebugException {
                return true;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#getVariables()
         */
        public IVariable[] getVariables() throws DebugException {
+               return (XDebugVariable[]) getChildVariables().toArray(
+                               new XDebugVariable[fVariables.size()]);
+       }
+
+       /**
+        *
+        */
+       public Vector getChildVariables() {
                return fVariables;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#hasVariables()
         */
        public boolean hasVariables() throws DebugException {
-               return (fVariables.length > 0);
+               return (fVariables.size() != 0);
        }
-       
+
        public boolean setValue(String expression) throws DebugException {
                return true;
        };
-       
+
        protected boolean verifyValue(String expression) {
                return true;
        }
-       
+
        protected boolean supportsValueModification() {
                return false;
        }
-       
+
        protected void setValueString(String valueString) {
                fValueString = valueString;
        }
 
        protected void setChildren(IVariable[] newChildren) {
-               fVariables = newChildren;
+               fVariables = new Vector (Arrays.asList(newChildren));
        }
-}
\ No newline at end of file
+}