|
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.core.model; |
|
6 |
|
7 import org.chromium.debug.core.ChromiumDebugPlugin; |
|
8 import org.chromium.debug.core.util.JsValueStringifier; |
|
9 import org.chromium.sdk.JsArray; |
|
10 import org.chromium.sdk.JsValue; |
|
11 import org.eclipse.core.runtime.IStatus; |
|
12 import org.eclipse.core.runtime.Status; |
|
13 import org.eclipse.debug.core.DebugException; |
|
14 import org.eclipse.debug.core.model.IValue; |
|
15 import org.eclipse.debug.core.model.IVariable; |
|
16 |
|
17 /** |
|
18 * A generic (non-array) implementation of IValue using a JsValue instance. |
|
19 */ |
|
20 public class Value extends DebugElementImpl implements IValue { |
|
21 |
|
22 private static final IVariable[] EMPTY_VARIABLES = new IVariable[0]; |
|
23 |
|
24 private final JsValue value; |
|
25 |
|
26 private IVariable[] variables; |
|
27 |
|
28 public static Value create(IChromiumDebugTarget debugTarget, JsValue value) { |
|
29 if (JsValue.Type.TYPE_ARRAY == value.getType()) { |
|
30 return new ArrayValue(debugTarget, (JsArray) value); |
|
31 } |
|
32 return new Value(debugTarget, value); |
|
33 } |
|
34 |
|
35 Value(IChromiumDebugTarget debugTarget, JsValue value) { |
|
36 super(debugTarget); |
|
37 this.value = value; |
|
38 } |
|
39 |
|
40 public String getReferenceTypeName() throws DebugException { |
|
41 return value.getType().toString(); |
|
42 } |
|
43 |
|
44 public String getValueString() throws DebugException { |
|
45 String valueText = JsValueStringifier.toVisibleString(value); |
|
46 if (value.asObject() != null) { |
|
47 String ref = value.asObject().getRefId(); |
|
48 if (ref != null) { |
|
49 valueText = valueText + " (id=" + ref + ")"; |
|
50 } |
|
51 } |
|
52 return valueText; |
|
53 } |
|
54 |
|
55 public IVariable[] getVariables() throws DebugException { |
|
56 try { |
|
57 if (variables == null) { |
|
58 if (value.asObject() != null) { |
|
59 variables = StackFrame.wrapVariables(getDebugTarget(), value.asObject().getProperties(), |
|
60 value.asObject().getInternalProperties()); |
|
61 } else { |
|
62 variables = EMPTY_VARIABLES; |
|
63 } |
|
64 } |
|
65 return variables; |
|
66 } catch (RuntimeException e) { |
|
67 // We shouldn't throw RuntimeException from here, because calling |
|
68 // ElementContentProvider#update will forget to call update.done(). |
|
69 throw new DebugException(new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, |
|
70 "Failed to read variables", e)); //$NON-NLS-1$ |
|
71 } |
|
72 } |
|
73 |
|
74 public boolean hasVariables() throws DebugException { |
|
75 return value.asObject() != null; |
|
76 } |
|
77 |
|
78 public boolean isAllocated() throws DebugException { |
|
79 return false; |
|
80 } |
|
81 |
|
82 public JsValue getJsValue() { |
|
83 return value; |
|
84 } |
|
85 |
|
86 } |