1) Added parameter 'parent' to XDebugVariable, so we can determine whether a variable...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugWatchExpressionDelegate.java
index 2974ceb..d434a53 100644 (file)
 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) {
-               IWatchExpressionResult x;
-               XDebugConnection connection;
-               XDebugTarget s;
-
-               x = new XDebugWatchExpressionResult(expression, null, null);
-               
-               s = (XDebugTarget) context.getDebugTarget();
-               connection = (XDebugConnection) s.getDebugConnection();
+               IWatchExpressionResult x = new XDebugWatchExpressionResult(expression, null, null);
+
+               /* Active debug session */
+               if (context instanceof XDebugStackFrame) {
+                       XDebugStackFrame frame = (XDebugStackFrame)context;
+                       Node evalProperty = null;
+                               
+                       try {   
+                               evalProperty = frame.eval(expression);
+                       } catch (Exception e) {
+                               // 
+                               e.printStackTrace();
+                       }
 
-               if( connection != null ) {
+                       XDebugVariable variable = null;
                        try {
-                               if( ! connection.isClosed() ) {
-                                       DebugResponse evalCommand = connection.eval(expression);
-                                       
-                                       Node evalNode = evalCommand.getParentNode();
-                                       XDebugVariable var= /*connection.*/getVariableFromNodeA( null, evalNode.getFirstChild());
-                                       XDebugVariable result[] = {var};
-                                       
-                                       if (result.length == 0) {
-                                               x = new XDebugWatchExpressionResult(expression, null, null);
-                                       } else {
-                                               x = new XDebugWatchExpressionResult(expression, result[0].getValue(), null);
-                                       }
-                               }
-                       } catch (Exception e) {
-                               String[] s1;
-       
-                               s1 = new String[1];
-                               s1[0] = e.toString();
-                               x = new XDebugWatchExpressionResult(expression, null, s1);
+                               variable = new XDebugVariable(frame, evalProperty, null);
+                               x = new XDebugWatchExpressionResult(expression, variable.getValue(), null);
+                       } catch (DebugException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
                        }
                }
 
                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