a14bc08eacbe28c8fd90d024d90c9b03ef368fe4
[phpeclipse.git] /
1 package net.sourceforge.phpeclipse.xdebug.php.model;
2
3
4 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection;
5 import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.XDebugResponse;
6 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable;
7 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
8
9 import org.eclipse.debug.core.model.IDebugElement;
10 import org.eclipse.debug.core.model.IWatchExpressionDelegate;
11 import org.eclipse.debug.core.model.IWatchExpressionListener;
12 import org.eclipse.debug.core.model.IWatchExpressionResult;
13 import org.w3c.dom.Node;
14
15 public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate {
16         public void evaluateExpression(String expression, IDebugElement context, IWatchExpressionListener listener) {
17                 IWatchExpressionResult x;
18                 XDebugConnection connection;
19                 XDebugTarget s;
20
21                 x = new XDebugWatchExpressionResult(expression, null, null);
22                 
23                 s = (XDebugTarget) context.getDebugTarget();
24                 connection = (XDebugConnection) s.getDebugConnection();
25
26                 if( connection != null ) {
27                         try {
28                                 if( ! connection.isClosed() ) {
29                                         /*XDebugResponse*/ int evalCommand = connection.eval(expression);
30                                         
31                                         XDebugResponse response = s.getResponse(evalCommand);
32
33                                         
34                                         Node evalResponse = response.getParentNode();
35                                         Node evalProperty = evalResponse.getFirstChild();
36                                         XDebugVariable variable = new XDebugVariable(null, evalProperty);
37                                         XDebugVariable result[] = {variable};
38                                         
39                                         if (result.length == 0) {
40                                                 x = new XDebugWatchExpressionResult(expression, null, null);
41                                         } else {
42                                                 x = new XDebugWatchExpressionResult(expression, result[0].getValue(), null);
43                                         }
44                                 }
45                         } catch (Exception e) {
46                                 String[] s1;
47         
48                                 s1 = new String[1];
49                                 s1[0] = e.toString();
50                                 x = new XDebugWatchExpressionResult(expression, null, s1);
51                         }
52                 }
53
54                 listener.watchEvaluationFinished(x);
55         }
56 }