napets napets - 3 years ago 195
C Question

Eclipse - custom text when hovering over a marker

I working on an Eclipse plugin and currently I am trying to make Eclipse (Luna) to show customized text when hovering over a marker. I know that I could achieve this by specifying the marker arguments, but I need to change the text dynamically, e.g:

Use case

I have already tried these approaches without success:

1) Having a custom

with custom

public class MyEditor extends TextEditor {

public MyEditor() {
setSourceViewerConfiguration(new SourceViewerConfiguration() {
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return new IAnnotationHover() {
public String getHoverInfo(ISourceViewer sv, int ln) {
return "Hello world!";

and the plugin.xml like this:


My method getHoverInfo is never called. Instead, the method getHoverInfo from the DefaultAnnotationHover is being called any time I open any *.c file and hover over the marker. I checked the available editors via the Eclipse->Preferences->General->Editors and the
is there.

2) Adding the custom annotation hover dynamically. I found here information that it is possible. So every time I open a "*.c" file, I have this code:

IPartListener2 partListener2 = new IPartListener2() {
public void partOpened(IWorkbenchPartReference partRef) {
if ("org.eclipse.cdt.ui.editor.CEditor".equals(((EditorReference) partRef).getDescriptor().getId())) {
CEditor currentCFileEditor = ((CEditor)((EditorReference) partRef).getEditor(false));
currentCFileEditor.getViewer().setAnnotationHover(new IAnnotationHover() {
public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
return "Hello world";

But again, I was not successful - my
is not called at all.

Any idea what I am doing wrong?

Answer Source

For those who have a similar problem - I have found a "hacky" solution. I have created my own class MyAwesomeHover:

public class MyAwesomeHover implements IAnnotationHover {
    public String getHoverInfo(ISourceViewer sw, int ln) {
        return "Hey hoo"

And then I use the reflection to set MyAweseomeHover as the displayed AnnotationHover.

    Field hm= SourceViewer.class.getDeclaredField("fVerticalRulerHoveringController");
    AnnotationBarHoverManager ma= (AnnotationBarHoverManager) hm.get(sourceViewer);
    Field ah= AnnotationBarHoverManager.class.getDeclaredField("fAnnotationHover");
    ah.set(ma, MyAwesomeHover());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download