2
|
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.editors;
|
|
6 |
|
|
7 |
import org.chromium.debug.core.model.StackFrame;
|
|
8 |
import org.chromium.debug.core.util.JsValueStringifier;
|
|
9 |
import org.chromium.sdk.CallFrame;
|
|
10 |
import org.chromium.sdk.JsVariable;
|
|
11 |
import org.eclipse.core.runtime.IAdaptable;
|
|
12 |
import org.eclipse.debug.ui.DebugUITools;
|
|
13 |
import org.eclipse.jface.text.IDocument;
|
|
14 |
import org.eclipse.jface.text.IRegion;
|
|
15 |
import org.eclipse.jface.text.ITextHover;
|
|
16 |
import org.eclipse.jface.text.ITextViewer;
|
|
17 |
|
|
18 |
/**
|
|
19 |
* Supplies a hover for JavaScript expressions while on a breakpoint.
|
|
20 |
*/
|
|
21 |
public class JsDebugTextHover implements ITextHover {
|
|
22 |
|
|
23 |
private static final JsValueStringifier STRINGIFIER = new JsValueStringifier();
|
|
24 |
|
|
25 |
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
|
|
26 |
IDocument doc = textViewer.getDocument();
|
|
27 |
String expression = JavascriptUtil.extractSurroundingJsIdentifier(doc, hoverRegion.getOffset());
|
|
28 |
if (expression == null) {
|
|
29 |
return null;
|
|
30 |
}
|
|
31 |
|
|
32 |
IAdaptable context = DebugUITools.getDebugContext();
|
|
33 |
if (context == null) { // debugger not active
|
|
34 |
return null;
|
|
35 |
}
|
|
36 |
|
|
37 |
StackFrame frame = (StackFrame) context.getAdapter(StackFrame.class);
|
|
38 |
if (frame == null) { // not a stackframe-related context
|
|
39 |
return null;
|
|
40 |
}
|
|
41 |
|
|
42 |
final JsVariable[] result = new JsVariable[1];
|
|
43 |
frame.getCallFrame().evaluateSync(expression, new CallFrame.EvaluateCallback() {
|
|
44 |
public void success(JsVariable var) {
|
|
45 |
result[0] = var;
|
|
46 |
}
|
|
47 |
public void failure(String errorMessage) {
|
|
48 |
}
|
|
49 |
});
|
|
50 |
if (result[0] == null) {
|
|
51 |
return null;
|
|
52 |
}
|
|
53 |
|
|
54 |
return STRINGIFIER.render(result[0].getValue());
|
|
55 |
}
|
|
56 |
|
|
57 |
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
|
|
58 |
IDocument doc = textViewer.getDocument();
|
|
59 |
return JavascriptUtil.getSurroundingIdentifierRegion(doc, offset, false);
|
|
60 |
}
|
|
61 |
|
|
62 |
}
|