This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 290
/
DelegatingDebugTextHover.java
87 lines (76 loc) · 2.66 KB
/
DelegatingDebugTextHover.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package melnorme.lang.ide.debug.ui;
import melnorme.lang.ide.ui.editor.ILangEditorTextHover;
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.ui.IEditorPart;
/**
* Common debug text hover delegating to debugger specific implementations
* based on active debug context.
*
* @since 7.0
*/
//BM: adapted to ILangEditorTextHover
// TODO: try to find a way to restrict the hover to relevant launches only?
public class DelegatingDebugTextHover
implements ILangEditorTextHover<Object>, ITextHoverExtension, ITextHoverExtension2 {
private IEditorPart fEditor;
private ICEditorTextHover fDelegate;
@Override
public IRegion getHoverRegion(ITextViewer viewer, int offset) {
fDelegate = getDelegate();
if (fDelegate != null) {
return fDelegate.getHoverRegion(viewer, offset);
}
return null;
}
@Override
@SuppressWarnings("deprecation")
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
fDelegate = getDelegate();
if (fDelegate != null) {
return fDelegate.getHoverInfo(textViewer, hoverRegion);
}
return null;
}
@Override
@SuppressWarnings("deprecation")
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
fDelegate = getDelegate();
if (fDelegate instanceof ITextHoverExtension2) {
return ((ITextHoverExtension2) fDelegate).getHoverInfo2(textViewer, hoverRegion);
}
// fall back to legacy method
if (fDelegate != null) {
return fDelegate.getHoverInfo(textViewer, hoverRegion);
}
return null;
}
@Override
public IInformationControlCreator getHoverControlCreator() {
if (fDelegate instanceof ITextHoverExtension) {
return ((ITextHoverExtension) fDelegate).getHoverControlCreator();
}
return null;
}
@Override
public final void setEditor(IEditorPart editor) {
fEditor = editor;
}
private ICEditorTextHover getDelegate() {
IAdaptable context = DebugUITools.getDebugContext();
if (context != null) {
ICEditorTextHover hover = (ICEditorTextHover) context.getAdapter(ICEditorTextHover.class);
if (hover != null) {
hover.setEditor(fEditor);
}
return hover;
}
return null;
}
}