Patches from Robert Kraske (robekras):
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPVariable.java
index fdb3b81..0cdad2a 100644 (file)
@@ -21,48 +21,76 @@ import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.IValue;
 import org.eclipse.debug.core.model.IVariable;
 
+
+/**
+ *
+ */
 public class PHPVariable implements IVariable {
 
-       
-       private PHPValue fValue;
-       private String fName;
-       private PHPStackFrame fStackFrame;
-       private PHPVariable fParent;
-       private String fLongName;
-       
-       PHPVariable(){
-               this(null,"",null,"",PHPValue.PEVT_UNKNOWN,null);
-       }
-       
-       PHPVariable(PHPStackFrame frame,String name, PHPVariable parent,String value,int valueType,Vector subitems)
+       private PHPValue                fValue;                                                                 // The value of this variable
+       private String                  fName;                                  // The name of the variable
+       private PHPStackFrame   fStackFrame;                            // The stackframe this variable belongs to
+       private PHPVariable     fParent;                                // The parent variable (a back link)
+       private String                  fLongName;                              // ???
+       private boolean         fHasChanged;                                                    //
+
+       /**
+        *
+        */
+       PHPVariable () {
+               this (null, "", null, "", PHPValue.PEVT_UNKNOWN, null);     // create an empty variable (a simple dummy node?)
+       }
+
+       /**
+        *
+        * @param frame     The stackframe this variable belongs to
+        * @param name      The name for this variable
+        * @param parent    The parent variable if this is not the root
+        * @param value     The value of this variable which is a simple value or again a variable
+        * @param valueType The type of the value (e.g. int, double, string etc.) @see PHPValue
+        * @param subitems
+        */
+       PHPVariable (PHPStackFrame frame, String name, PHPVariable parent, String value, int valueType, Vector subitems)
        {
-               this.fStackFrame=frame;
-               this.fValue=new PHPValue(frame,value,valueType,subitems);
-               this.fParent=parent;
-               setName(name);
+               this.fStackFrame = frame;
+               this.fValue      = new PHPValue (frame, value, valueType, subitems);
+               this.fParent     = parent;
+               this.fHasChanged = false;
+
+               setName (name);
        }
-       
-       private void setName(String name) {
-               if ((fParent==null) || (fParent.getName()=="")) {
-                       fLongName=name;
-                       fName=name;
+
+       /**
+        *
+        * @param name
+        */
+       private 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
+                       fName     = name;                                       //  and set the name
+
                        return;
                }
-               switch (fParent.getReferenceType()) {
-               case PHPValue.PEVT_ARRAY :
-                       fName="['"+name+"']";
-                       fLongName=fParent.getLongName()+fName;
-                       break;
-               case PHPValue.PEVT_OBJECT :
-                       fName=name;
-                       fLongName=fParent.getLongName()+"."+fName;
-                       break;
-               default :
-                       fName=name;
-                       fLongName=name;
-                       break;
+
+               switch (fParent.getReferenceType ()) {                      // Get the type of the parent variable
+                       case PHPValue.PEVT_ARRAY :                              // It's an array
+                               fName     = "['" + name + "']";                     // So set the variable name as [name]
+                               fLongName = fParent.getLongName () + fName;         // Set the longname to parentVariableLongname[name]
+                               break;
+
+                       case PHPValue.PEVT_OBJECT :                             // It's an object
+                               fName     = name;                                   // Set the name to name
+                               fLongName = fParent.getLongName () + "." + fName;   // Set the longname to parentVariableLongname.name
+                               break;
+
+                       default :
+                               fName     = name;                                   // Set the name to name
+                               fLongName = name;                                   // Set the Longname to name
+                               break;
                }
        }
+
        /**
         * @see org.eclipse.debug.core.model.IVariable#getValue()
         */
@@ -76,18 +104,27 @@ public class PHPVariable implements IVariable {
        public String getName()  {
                return fName;
        }
-       
+
+       /**
+        *
+        */
        public PHPVariable getParent()
        {
                return fParent;
        }
-       
+
+       /**
+        *
+        */
        public void setParent(PHPVariable parent)
        {
                this.fParent=parent;
                fLongName=parent.getLongName()+fName;
        }
-       
+
+       /**
+        *
+        */
        public String getLongName() {
                return fLongName;
        }
@@ -98,11 +135,17 @@ public class PHPVariable implements IVariable {
        public String getReferenceTypeName() {
                return fValue.getReferenceTypeName();
        }
-       
+
+       /**
+        *
+        */
        public int getReferenceType() {
                return fValue.getReferenceType();
        }
-       
+
+       /**
+        *
+        */
        public int setReferenceType(int type) {
                return ((PHPValue) getValue()).setReferenceType(type);
        }
@@ -112,10 +155,22 @@ public class PHPVariable implements IVariable {
         */
        public boolean hasValueChanged() throws DebugException {
                // TODO Auto-generated method stub
-               return false;
+               // return false;
+               return fHasChanged;
        }
-       
-          /**
+
+       /**
+        *
+        * @param changed This method is called after a suspend when the list of
+        *                variables is updated, to mark that this variable has a changed
+        *                value. The variable view will show this variable in
+        *                a different color.
+        */
+       public void setValueChanged (boolean changed) {
+               fHasChanged = changed;
+       }
+
+    /**
      * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
      */
     public String getModelIdentifier() {
@@ -136,7 +191,6 @@ public class PHPVariable implements IVariable {
         return getDebugTarget().getLaunch();
     }
 
-
        /**
         * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
         */
@@ -187,40 +241,49 @@ public class PHPVariable implements IVariable {
     public Object getAdapter(Class adapter) {
         return Platform.getAdapterManager().getAdapter(this, adapter);
     }
-    
-    public String toString() {
-       int type=-1;
-       String str="";
-       
-       switch (getReferenceType())
-               {
-               case PHPValue.PEVT_ARRAY :
-                       int elements=fValue.getVariables().length;
-                       switch (elements) {
-                       case 0:
-                                       str= this.getName() + " [no elements]";
-                                       break;
-                               case 1:
-                                       str= this.getName() + " [1 element]";
-                                       break;
-                               default:
-                                       str= this.getName() + " [" + elements + " elements]";
-                                       break;
+
+       /**
+        * This method is called from variable view and denominates the variables with
+        * a type specific explanation.
+        *
+        */
+    public String toString () {
+       int     type    =  -1;
+       String  str     = "";
+
+       switch (getReferenceType ()) {
+               case PHPValue.PEVT_ARRAY :                                          // Variable is an array
+                       int elements = fValue.getVariables ().length;                   // Get the number of child elements
+
+                       switch (elements) {                                                     // Switch for the number of child elements
+                               case 0:                                                     // We have no child element
+                                               str = this.getName () + " [no elements]";               // string => 'varname [no elements]'
+                                               break;
+
+                                       case 1:                                                     // We have exactly one child element
+                                               str = this.getName () + " [1 element]";                                 // string => 'varname [1 element]'
+                                               break;
+
+                                       default:                                                    // We have more than one element
+                                               str = this.getName () + " [" + elements + " elements]"; // string => 'varname [x elements]'
+                                               break;
                        }
                        break;
-               case PHPValue.PEVT_OBJECT :
-                       str =this.getName() + " [class: " + fValue.getValueString() + "]";
+
+               case PHPValue.PEVT_OBJECT :                                                     // Variable is an object
+                       str = this.getName () + " [class: " + fValue.getValueString() + "]";    // string => 'varname [class: varvalue]'
                        break;
-               case PHPValue.PEVT_STRING :
-                       str =this.getName() + " = \"" + fValue.getValueString() +"\"" ;
+
+               case PHPValue.PEVT_STRING :                                                 // Variable is a string
+                       str = this.getName () + " = \"" + fValue.getValueString() +"\"" ;               // string => 'varname = "varvalue"'
                                break;
-               case PHPValue.PEVT_SOFTREF :
-               default :
-                       str =this.getName() + " = " + fValue.getValueString();
+
+               case PHPValue.PEVT_SOFTREF :                                                // Variable is a soft reference
+               default :                                                                   // or anything else
+                       str = this.getName () + " = " + fValue.getValueString();                                // string => 'varname = varvalue'
                        break;
                }
-       
+
                return str;
-       
     }
 }