author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 15 Mar 2010 17:36:40 -0700 | |
changeset 267 | a0f8d02facf1 |
parent 52 | f577ea64429e |
permissions | -rw-r--r-- |
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 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
7 |
import org.chromium.debug.core.model.EvaluateContext; |
2 | 8 |
import org.chromium.debug.core.util.JsValueStringifier; |
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
9 |
import org.chromium.sdk.JsEvaluateContext; |
2 | 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 |
||
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
37 |
EvaluateContext evaluateContext = (EvaluateContext) context.getAdapter(EvaluateContext.class); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
38 |
if (evaluateContext == null) { |
2 | 39 |
return null; |
40 |
} |
|
41 |
||
42 |
final JsVariable[] result = new JsVariable[1]; |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
43 |
evaluateContext.getJsEvaluateContext().evaluateSync(expression, |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
44 |
new JsEvaluateContext.EvaluateCallback() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
45 |
public void success(JsVariable var) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
46 |
result[0] = var; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
47 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
48 |
public void failure(String errorMessage) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
49 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
50 |
}); |
2 | 51 |
if (result[0] == null) { |
52 |
return null; |
|
53 |
} |
|
54 |
||
55 |
return STRINGIFIER.render(result[0].getValue()); |
|
56 |
} |
|
57 |
||
58 |
public IRegion getHoverRegion(ITextViewer textViewer, int offset) { |
|
59 |
IDocument doc = textViewer.getDocument(); |
|
60 |
return JavascriptUtil.getSurroundingIdentifierRegion(doc, offset, false); |
|
61 |
} |
|
62 |
||
63 |
} |