refactory whole plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugWatchExpressionDelegate.java
index 64dbc32..2974ceb 100644 (file)
@@ -2,15 +2,20 @@ package net.sourceforge.phpeclipse.xdebug.php.model;
 
 
 import net.sourceforge.phpeclipse.xdebug.core.Base64;
+import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection;
 import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable;
 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
+
+import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IDebugElement;
+import org.eclipse.debug.core.model.IVariable;
 import org.eclipse.debug.core.model.IWatchExpressionDelegate;
 import org.eclipse.debug.core.model.IWatchExpressionListener;
 import org.eclipse.debug.core.model.IWatchExpressionResult;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate {
        public void evaluateExpression(String expression, IDebugElement context, IWatchExpressionListener listener) {
@@ -26,11 +31,10 @@ public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate {
                if( connection != null ) {
                        try {
                                if( ! connection.isClosed() ) {
-                                       String encoded = Base64.encodeBytes(expression.getBytes());
-                                       DebugResponse evalCommand = connection.sendRequestA( "eval", "-- "+encoded );
+                                       DebugResponse evalCommand = connection.eval(expression);
                                        
                                        Node evalNode = evalCommand.getParentNode();
-                                       XDebugVariable var= connection.getVariableFromNodeA( null, evalNode.getFirstChild());
+                                       XDebugVariable var= /*connection.*/getVariableFromNodeA( null, evalNode.getFirstChild());
                                        XDebugVariable result[] = {var};
                                        
                                        if (result.length == 0) {
@@ -50,4 +54,66 @@ public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate {
 
                listener.watchEvaluationFinished(x);
        }
+       
+       private XDebugVariable getVariableFromNodeA(XDebugStackFrame frame, Node property) {
+               String address = PHPDebugUtils.getAttributeValue(property, "address");
+               String varName;
+               String Name = PHPDebugUtils.getAttributeValue(property,"name");
+               if ("".equals(Name)) {
+                       varName = address;              
+               } else {
+                       varName = Name;
+               }
+
+               String varEncoding=PHPDebugUtils.getAttributeValue(property,"encoding");
+               int varNumChildren = 0;
+               if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals(""))
+                       varNumChildren = 0;
+               else
+                       varNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren"));
+
+               String typeName=PHPDebugUtils.getAttributeValue(property,"type");
+
+               XDebugVariable variable = new XDebugVariable(typeName, varName);
+               variable.setEncoding(varEncoding);
+               variable.setNumChildren(varNumChildren);
+               XDebugAbstractValue val=null;
+               try {
+                       val = (XDebugAbstractValue) variable.getValue();
+               } catch (DebugException e1) {
+                       e1.printStackTrace();
+               }
+               if (val.getType()!= XDebugAbstractValue.VALUETYPE_UNINITIALIZED) {
+                       if (variable.hasChildren()) {
+                               NodeList varNodes = property.getChildNodes();
+                               val.renderValueString(""+varNodes.getLength());
+                               IVariable[] variables = new IVariable[varNodes.getLength()];
+                               for (int i = 0; i<varNodes.getLength(); i++) {
+                                       Node propertyNode = varNodes.item(i);
+                                       variables[i] = getVariableFromNodeA(frame, propertyNode);
+                               }
+                               val.setChildVariables(variables);
+                       }else {
+                               String str="";
+                               try {
+                                       str=property.getFirstChild().getNodeValue();
+                               } catch (NullPointerException e) {
+                                       str="";
+                               }
+                               if (variable.getEncoding().equals("base64")) {
+                                       if (str.length()!=0)
+                                               str=new String(Base64.decode(str));
+                                       else
+                                               str="";
+                               }
+                               val.renderValueString(str);
+                       }
+                       
+                       String className=PHPDebugUtils.getAttributeValue(property,"classname");
+                       if(!"".equals(className))
+                               val.renderValueString(className);
+               }
+               return variable;
+               
+       }
 }
\ No newline at end of file