Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugVariable.java
index a6646da..969c718 100644 (file)
@@ -6,11 +6,9 @@
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
-
 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
-
-import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.model.IValue;
 import org.eclipse.debug.core.model.IVariable;
 import org.w3c.dom.Node;
@@ -22,7 +20,6 @@ import org.w3c.dom.Node;
  * Window - Preferences - Java - Code Style - Code Templates
  */
 public class XDebugVariable  extends XDebugElement implements IVariable {
-       
        public static final int VARTYPE_UNKNOWN = -1;
        public static final int VARTYPE_UNINITIALIZED = 0;
        public static final int VARTYPE_STRING = 1;
@@ -31,18 +28,15 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
        public static final int VARTYPE_ARRAY = 8;
        public static final int VARTYPE_HASH = 9;
        public static final int VARTYPE_OBJECT = 10;
-
+       public static final int VARTYPE_RESOURCE = 11;
        
        // name & stack frmae
        private String fName;
        private XDebugStackFrame fFrame;
        private String fFullName;
-//     private String fTypeName;
-//     private int fType;
        private XDebugAbstractValue fValue;
        private String fEncoding;
        private int fNumChildren;
-//     private Node fVariableNode;
        
        /**
         * Constructs a variable contained in the given stack frame
@@ -51,11 +45,58 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
         * @param frame owning stack frame
         * @param name variable name
         */
+       public XDebugVariable( String typeName, String fullname ) {
+               fFullName = fullname;
+               fName = fullname;
+               if (typeName.equals("int") ) 
+                       fValue= new XDebugIntValue(this,typeName);
+               else if (typeName.equals("float") ) 
+                       fValue= new XDebugFloatValue(this,typeName);
+               else if (typeName.equals("bool") ) 
+                       fValue= new XDebugBooleanValue(this,typeName);
+               else if (typeName.equals("string") )
+                       fValue= new XDebugStringValue(this,typeName);
+               else if (typeName.equals("array") )
+                       fValue= new XDebugArrayValue(this,typeName);
+               else if (typeName.equals("hash") )
+                       fValue= new XDebugArrayValue(this,typeName);
+               else if (typeName.equals("object") )
+                       fValue= new XDebugArrayValue(this,typeName);
+               else if (typeName.equals("resource") )
+                       fValue= new XDebugResourceValue(this,typeName);
+               else
+                       fValue= new XDebugValue(this,typeName);
+       }
+       
        public XDebugVariable(XDebugStackFrame frame, Node property) {
                super((XDebugTarget) frame.getDebugTarget());
                fFrame = frame;
                init(property);
-
+       }
+       
+       public XDebugVariable(XDebugStackFrame frame, String fullname, String name, String typeName) {
+               super((XDebugTarget) frame.getDebugTarget());
+               fFrame = frame;
+               fFullName = fullname;
+               fName = name;
+               if (typeName.equals("int") ) 
+                       fValue= new XDebugIntValue(this,typeName);
+               else if (typeName.equals("float") ) 
+                       fValue= new XDebugFloatValue(this,typeName);
+               else if (typeName.equals("bool") ) 
+                       fValue= new XDebugBooleanValue(this,typeName);
+               else if (typeName.equals("string") )
+                       fValue= new XDebugStringValue(this,typeName);
+               else if (typeName.equals("array") )
+                       fValue= new XDebugArrayValue(this,typeName);
+               else if (typeName.equals("hash") )
+                       fValue= new XDebugArrayValue(this,typeName);
+               else if (typeName.equals("object") )
+                       fValue= new XDebugArrayValue(this,typeName);
+               else if (typeName.equals("resource") )
+                       fValue= new XDebugResourceValue(this,typeName);
+               else
+                       fValue= new XDebugValue(this,typeName);
        }
        
        private void  init(Node property) {
@@ -87,24 +128,8 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
                        fValue= new XDebugArrayValue(this,property,typeName);
                else
                        fValue= new XDebugValue(this,property,typeName);
-
-//             else if (typeName.equals("float") )
-//                     fTypeName= VARTYPE_FLOAT;
-//             else if (typeName.equals("string") )
-//                     fTypeName= VARTYPE_STRING;
-//             else if (typeName.equals("hash") )
-//                     fTypeName= VARTYPE_HASH;
-//             else if (typeName.equals("array") )
-//                     fTypeName= VARTYPE_ARRAY;
-//             else if (typeName.equals("object") )
-//                     fTypeName= VARTYPE_OBJECT;
-
-               
-                               
-//             fTypeName=type;
-//             
-//             fValue= new XDebugValue(this,property);
        }
+       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IVariable#getValue()
         */
@@ -112,6 +137,7 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
                return fValue;
 //             return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
        }
+       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IVariable#getName()
         */
@@ -121,43 +147,51 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
                else
                        return fName;
        }
+       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
         */
        public String getReferenceTypeName() throws DebugException {
                return fValue.getReferenceTypeName();
        }
+       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
         */
        public boolean hasValueChanged() throws DebugException {
-               // TODO Auto-generated method stub
-               return false;
+               return fValue.hasChanged();
        }
+       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
         */
        public void setValue(String expression) throws DebugException {
                if(fValue.setValue(expression))
                        fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
+               //fValue.setValueA(expression);
        }
+       
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
         */
        public void setValue(IValue value) throws DebugException {
+               fValue.setValueB(value);
        }
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
         */
        public boolean supportsValueModification() {
                return fValue.supportsValueModification();
        }
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
         */
        public boolean verifyValue(String expression) throws DebugException {
                return fValue.verifyValue(expression);
        }
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
         */
@@ -173,6 +207,11 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
        protected XDebugStackFrame getStackFrame() {
                return fFrame;
        }
+       
+       public void setStackFrame(XDebugStackFrame frame) {
+               fFrame=frame;
+               super.setDebugTarget((XDebugTarget)frame.getDebugTarget());
+       }
 
 //     public int getType() {
 //             return fType;
@@ -182,8 +221,12 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
                return fValue.getValueString();
        }
        
+       /*public setValueString(String newValueStrig) throws DebugException {
+               fValue.setValueString getValueString();
+       }*/
+       
        public boolean hasChildren() {
-               return (fNumChildren>0);
+               return (fNumChildren > 0);
        }
 
        public boolean isArray() {
@@ -206,4 +249,64 @@ public class XDebugVariable  extends XDebugElement implements IVariable {
                return fFullName;
        }
 
-}
+       public int getNumChildren() {
+               return fNumChildren;
+       }
+
+       public void setNumChildren(int numChildren) {
+               fNumChildren = numChildren;
+       }
+       
+       public void setChange(IVariable oldVariable)  throws DebugException {
+               XDebugAbstractValue oldValue = null;
+               IVariable[] newVariable = null;
+               IVariable[] oldVariable1 = null;
+
+               try {
+                       oldValue = (XDebugAbstractValue) oldVariable.getValue();
+               } catch (DebugException e) {
+               }
+
+               try {
+                       oldVariable1 = ((XDebugVariable)oldVariable).getValue().getVariables();
+                       newVariable = fValue.getVariables();
+               } catch (DebugException e) {
+               }
+               
+               
+               if(((XDebugVariable) oldVariable).getNumChildren() > 0) {
+                       if ( this.getNumChildren() == 0) {
+                               try {
+                                       if (!fValue.getValueString().equals(((XDebugAbstractValue)oldValue).getValueString())) {
+                                               fValue.sethasChanged(true);
+                                       } else {
+                                               fValue.sethasChanged(false);                                            
+                                       }
+                               } catch (DebugException e) {
+                               }
+                       } else {
+                               for(int i = 0; i < newVariable.length; i++) {
+                                       ((XDebugVariable)newVariable[i]).setChange(((XDebugVariable)oldVariable1[i]));
+                               }
+                       }                       
+               } else {
+                       if ( this.getNumChildren() == 0) {
+                               // controllare anche il tipo (unknow)
+                               //if (!fValue.getValueString().equals("uninitialized")) {
+                               if (!fValue.getValueString().equals(oldValue.getValueString())) {
+                                       fValue.sethasChanged(true);
+                               } else {
+                                       fValue.sethasChanged(false);                                    
+                               }
+                       } else {
+                               IVariable dummy = new XDebugVariable("UNKNOWN", "");
+                               dummy.setValue("uninitialized");
+                               for(int i = 0; i < newVariable.length; i++) {
+                                       ((XDebugVariable)newVariable[i]).setChange(dummy);
+                               }
+                               fValue.sethasChanged(true);                             
+                       }
+               }
+       }
+       
+}
\ No newline at end of file