|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.ui.actions; |
|
6 |
|
7 import org.chromium.debug.core.ChromiumDebugPlugin; |
|
8 import org.chromium.debug.core.model.StackFrame; |
|
9 import org.chromium.debug.core.model.Value; |
|
10 import org.chromium.sdk.JsVariable; |
|
11 import org.eclipse.core.runtime.PlatformObject; |
|
12 import org.eclipse.debug.core.DebugEvent; |
|
13 import org.eclipse.debug.core.DebugPlugin; |
|
14 import org.eclipse.debug.core.IDebugEventSetListener; |
|
15 import org.eclipse.debug.core.ILaunch; |
|
16 import org.eclipse.debug.core.model.IDebugElement; |
|
17 import org.eclipse.debug.core.model.IDebugTarget; |
|
18 import org.eclipse.debug.core.model.IErrorReportingExpression; |
|
19 import org.eclipse.debug.core.model.IValue; |
|
20 |
|
21 /** |
|
22 * An Eclipse object for the JavaScript inspected expression. |
|
23 */ |
|
24 public class JsInspectExpression extends PlatformObject |
|
25 implements IErrorReportingExpression, IDebugEventSetListener { |
|
26 |
|
27 private final StackFrame stackFrame; |
|
28 |
|
29 private final JsVariable variable; |
|
30 |
|
31 private final String errorMessage; |
|
32 |
|
33 private final String expression; |
|
34 |
|
35 public JsInspectExpression(StackFrame stackFrame, String expression, JsVariable variable, |
|
36 String errorMessage) { |
|
37 this.stackFrame = stackFrame; |
|
38 this.expression = expression; |
|
39 this.variable = variable; |
|
40 this.errorMessage = errorMessage; |
|
41 } |
|
42 |
|
43 public String[] getErrorMessages() { |
|
44 return errorMessage == null |
|
45 ? new String[0] |
|
46 : new String[] { errorMessage }; |
|
47 } |
|
48 |
|
49 public boolean hasErrors() { |
|
50 return errorMessage != null; |
|
51 } |
|
52 |
|
53 public void dispose() { |
|
54 } |
|
55 |
|
56 public IDebugTarget getDebugTarget() { |
|
57 IValue value = getValue(); |
|
58 if (value != null) { |
|
59 return value.getDebugTarget(); |
|
60 } |
|
61 return null; |
|
62 } |
|
63 |
|
64 public String getExpressionText() { |
|
65 return expression; |
|
66 } |
|
67 |
|
68 public IValue getValue() { |
|
69 return variable != null |
|
70 ? Value.create(stackFrame.getDebugTarget(), variable.getValue()) |
|
71 : null; |
|
72 } |
|
73 |
|
74 public ILaunch getLaunch() { |
|
75 return getValue().getLaunch(); |
|
76 } |
|
77 |
|
78 public String getModelIdentifier() { |
|
79 return ChromiumDebugPlugin.DEBUG_MODEL_ID; |
|
80 } |
|
81 |
|
82 public void handleDebugEvents(DebugEvent[] events) { |
|
83 for (DebugEvent event : events) { |
|
84 switch (event.getKind()) { |
|
85 case DebugEvent.TERMINATE: |
|
86 if (event.getSource().equals(getDebugTarget())) { |
|
87 DebugPlugin.getDefault().getExpressionManager().removeExpression(this); |
|
88 } |
|
89 break; |
|
90 case DebugEvent.SUSPEND: |
|
91 if (event.getDetail() != DebugEvent.EVALUATION_IMPLICIT && |
|
92 event.getSource() instanceof IDebugElement) { |
|
93 IDebugElement source = (IDebugElement) event.getSource(); |
|
94 if (source.getDebugTarget().equals(getDebugTarget())) { |
|
95 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { |
|
96 new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT) }); |
|
97 } |
|
98 } |
|
99 break; |
|
100 } |
|
101 } |
|
102 } |
|
103 |
|
104 } |