Patches from Robert Kraske (robekras):
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPValue.java
index caecb89..bf97de2 100644 (file)
@@ -23,56 +23,93 @@ import org.eclipse.debug.core.model.IValue;
 import org.eclipse.debug.core.model.IVariable;
 
 
+/**
+ * PHPValue object belongs to a PHPVariable (is a member of PHPVariable).
+ * A PHPValue itself can have PHPVariables as children.
+ *
+ */
 public class PHPValue implements IValue {
-       
-       final static String[] PEV_NAMES={"undefined","long","double","string","array",
-                        "object","boolean","resource","reference","soft reference"}; 
-       final static int PEVT_UNKNOWN =0;
-       final static int PEVT_LONG = 1;
-       final static int PEVT_DOUBLE=2;
-       final static int PEVT_STRING=3;
-       final static int PEVT_ARRAY=4;
-       final static int PEVT_OBJECT=5;
-       final static int PEVT_BOOLEAN=6;
-       final static int PEVT_RESOURCE=7;
-       final static int PEVT_REF=8;
-       final static int PEVT_SOFTREF=9;
-       
-       private int fValueType;
-       private boolean hasChildren;
-       private String fValueString;
-       private Vector fVariables;
-       private PHPStackFrame fStackFrame;
-       
-       PHPValue() {
-               this(null,"",PEVT_UNKNOWN,null);
-       }
-       
-       PHPValue(PHPStackFrame frame,String value,int fValueType,Vector subitems)
+
+       final static String[] PEV_NAMES = {"undefined",                 // 0
+                                          "long",                      // 1
+                                                                          "double",                    // 2
+                                                                          "string",                    // 3
+                                                                          "array",                     // 4
+                                                                          "object",                    // 5
+                                                                          "boolean",                   // 6
+                                                                          "resource",                  // 7
+                                                                          "reference",                 // 8
+                                                                          "soft reference"};           // 9
+       final static int PEVT_UNKNOWN   = 0;
+       final static int PEVT_LONG              = 1;
+       final static int PEVT_DOUBLE    = 2;
+       final static int PEVT_STRING    = 3;
+       final static int PEVT_ARRAY             = 4;
+       final static int PEVT_OBJECT    = 5;
+       final static int PEVT_BOOLEAN   = 6;
+       final static int PEVT_RESOURCE  = 7;
+       final static int PEVT_REF               = 8;
+       final static int PEVT_SOFTREF   = 9;
+
+       private int                     fValueType;                             // The type of this value (see the PEVT_... values)
+       private boolean                 hasChildren;                            // This value (variable) has children (more variables)
+       private String                  fValueString;                           // The value of this variable as text
+       private Vector                  fVariables;                             // The children of this variable (other variables) if any
+       private PHPStackFrame   fStackFrame;                            // The stackframe this value (variable) belongs to
+                                                                                                                                       //
+
+       /**
+        *
+        */
+       PHPValue () {
+               this (null, "", PEVT_UNKNOWN, null);                                            // Creates an empty value
+       }
+
+       /**
+        *
+        * @param frame       The stackframe this value (and variable) belongs to.
+        * @param value       The value of this value.
+        * @param fValueType  The type of this value (see the PEVT_... values).
+        * @param subitems    This value has subitems.
+        */
+       PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems)
        {
-               this.fValueType=fValueType;
-               this.fValueString=value;
-               this.fStackFrame=frame;
-               if (subitems !=null)
-                       this.fVariables=new Vector(subitems);
-               else
-                       this.fVariables = new Vector();
-       }
-       
-       Vector addVariable(Vector item)
-       {       
-               if (item!=null)
-                       this.fVariables.addAll(item);
+               this.fValueType   = fValueType;
+               this.fValueString = value;
+               this.fStackFrame  = frame;
+
+               if (subitems != null) {                                     // If there are children for this value (variable)
+                       this.fVariables = new Vector (subitems);                // Then add the children to this value (variable)
+               }
+               else {
+                       this.fVariables = new Vector ();                        // Create an empty vector
+               }
+       }
+
+       /**
+        *
+        * @param item
+        */
+       Vector addVariable (Vector item)
+       {
+               if (item != null) {                                                                                     // If there is something we want to add
+                       this.fVariables.addAll (item);                          //
+               }
+
                return this.fVariables;
        }
-       
-       public void setParent(PHPVariable parent) {
-               if (!fVariables.isEmpty()) {
-                       Iterator iter=fVariables.iterator();
-                       while (iter.hasNext()) {
-                               ((PHPVariable)iter.next()).setParent(parent);
+
+       /**
+        *
+        * @param parent
+        */
+       public void setParent (PHPVariable 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
+                               ((PHPVariable) iter.next ()).setParent (parent);    // Set all child's parent
                        }
-               
                }
        }
 
@@ -82,13 +119,28 @@ public class PHPValue implements IValue {
        public String getReferenceTypeName(){
                return PEV_NAMES[fValueType];
        }
-       
+
+       /**
+        *
+        */
        public int getReferenceType(){
                return fValueType;
        }
-       
-       public int setReferenceType(int type){
-               return fValueType=type;
+
+       /**
+        * @param type Set the reference type (see the PEVT_... values).
+        */
+       public int setReferenceType (int type) {
+               return fValueType = type;
+       }
+
+       /**
+        * This method is called whenever this value (variable) is changed.
+        *
+        * @param value The changed value for this variable.
+        */
+       public void setValueString (String value) {
+               fValueString = value;
        }
 
        /**
@@ -107,17 +159,33 @@ public class PHPValue implements IValue {
 
        /**
         * @see org.eclipse.debug.core.model.IValue#getVariables()
+        *
+        * @return The array of child variable for this value (variable).
         */
        public IVariable[] getVariables() {
-               return (PHPVariable[])fVariables.toArray(new PHPVariable[fVariables.size()]);
+               return (PHPVariable[]) fVariables.toArray (new PHPVariable[fVariables.size ()]);
 //             return  (IVariable[])fVariables.toArray();
        }
 
        /**
+        *
+        */
+       public Vector getChildVariables () {
+               return (fVariables);
+       }
+
+       /**
         * @see org.eclipse.debug.core.model.IValue#hasVariables()
+        *
+        * @return
+        * <ul>
+        * <li> <code>true</code> if this value (variable) has child variables
+        * <li> <code>false</code> if no child variable available
+        * </ul>
         */
        public boolean hasVariables() throws DebugException {
-               return (!fVariables.isEmpty());
+               // return (!fVariables.isEmpty ());
+               return (fVariables.size () != 0);
        }
 
        /**
@@ -128,7 +196,7 @@ public class PHPValue implements IValue {
                return null;
        }
 
-       /** 
+       /**
         * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
         */
        public IDebugTarget getDebugTarget() {