Search in sources :

Example 1 with ITextHoverExtension2

use of org.eclipse.jface.text.ITextHoverExtension2 in project eclipse.platform.text by eclipse.

the class CompositeTextHover method getHoverInfo2.

@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion requestRegion) {
    this.currentHovers = new LinkedHashMap<>();
    for (ITextHover hover : this.allHovers) {
        IRegion currentRegion = this.regions.get(hover);
        if (currentRegion == null) {
            continue;
        }
        Object res = hover instanceof ITextHoverExtension2 ? ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, currentRegion) : hover.getHoverInfo(textViewer, currentRegion);
        if (res != null) {
            this.currentHovers.put(hover, res);
        }
    }
    if (this.currentHovers.isEmpty()) {
        return null;
    } else if (this.currentHovers.size() == 1) {
        return this.currentHovers.values().iterator().next();
    } else {
        return this.currentHovers;
    }
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) ITextHoverExtension2(org.eclipse.jface.text.ITextHoverExtension2) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with ITextHoverExtension2

use of org.eclipse.jface.text.ITextHoverExtension2 in project xtext-xtend by eclipse.

the class XtendHoverInEditorTest method testHoverOfReferencedElement.

@Test
public void testHoverOfReferencedElement() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("/**");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("* Hello Foo");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("class Foo {}");
        _builder.newLine();
        final String contentFoo = _builder.toString();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("class Bar extends Foo {}");
        _builder_1.newLine();
        final String contentBar = _builder_1.toString();
        final IFile fileFoo = this.helper.createFile("Foo.xtend", contentFoo);
        final IFile fileBar = this.helper.createFile("Bar.xtend", contentBar);
        this._syncUtil.waitForBuild(null);
        final XtextEditor editor = this.helper.openEditor(fileBar);
        ISourceViewer _internalSourceViewer = editor.getInternalSourceViewer();
        Region _region = new Region(19, 1);
        Object _hoverInfo2 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer), _region);
        final XtextBrowserInformationControlInput info = ((XtextBrowserInformationControlInput) _hoverInfo2);
        Assert.assertTrue(info.getHtml().contains("Hello Foo"));
        final XtextEditor fooEditor = this.helper.openEditor(fileFoo);
        IXtextDocument _document = fooEditor.getDocument();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("/**");
        _builder_2.newLine();
        _builder_2.append(" ");
        _builder_2.append("* Hello BAZ");
        _builder_2.newLine();
        _builder_2.append(" ");
        _builder_2.append("*/");
        _builder_2.newLine();
        _builder_2.append("class Foo {}");
        _builder_2.newLine();
        _document.set(_builder_2.toString());
        this._syncUtil.waitForReconciler(fooEditor);
        this._syncUtil.waitForReconciler(editor);
        ISourceViewer _internalSourceViewer_1 = editor.getInternalSourceViewer();
        Region _region_1 = new Region(19, 1);
        Object _hoverInfo2_1 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer_1), _region_1);
        final XtextBrowserInformationControlInput info2 = ((XtextBrowserInformationControlInput) _hoverInfo2_1);
        Assert.assertFalse(info2.getHtml().contains("Hello Foo"));
        Assert.assertTrue(info2.getHtml().contains("Hello BAZ"));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Region(org.eclipse.jface.text.Region) ITextHoverExtension2(org.eclipse.jface.text.ITextHoverExtension2) XtextBrowserInformationControlInput(org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ITextViewer(org.eclipse.jface.text.ITextViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 3 with ITextHoverExtension2

use of org.eclipse.jface.text.ITextHoverExtension2 in project webtools.sourceediting by eclipse.

the class BestMatchHover method getHoverInfo2.

public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
    Object information = null;
    controlCreatorProvider = null;
    // already have a best match hover picked out from getHoverRegion call
    if (fBestMatchHover instanceof ITextHoverExtension2) {
        information = ((ITextHoverExtension2) fBestMatchHover).getHoverInfo2(textViewer, hoverRegion);
    } else if (fBestMatchHover != null) {
        information = fBestMatchHover.getHoverInfo(textViewer, hoverRegion);
    }
    // either had no best match hover or best match hover returned null
    if (information == null) {
        // go through list of text hovers and return first display string
        Iterator i = getTextHovers().iterator();
        while ((i.hasNext()) && (information == null)) {
            ITextHover hover = (ITextHover) i.next();
            if (hover == fBestMatchHover)
                continue;
            if (hover instanceof ITextHoverExtension2) {
                information = ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
            } else {
                information = hover.getHoverInfo(textViewer, hoverRegion);
            }
            if (information != null) {
                controlCreatorProvider = hover;
            }
        }
    } else {
        controlCreatorProvider = fBestMatchHover;
    }
    return information;
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Iterator(java.util.Iterator) ITextHoverExtension2(org.eclipse.jface.text.ITextHoverExtension2)

Aggregations

ITextHoverExtension2 (org.eclipse.jface.text.ITextHoverExtension2)3 ITextHover (org.eclipse.jface.text.ITextHover)2 Iterator (java.util.Iterator)1 IFile (org.eclipse.core.resources.IFile)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 Region (org.eclipse.jface.text.Region)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 XtextBrowserInformationControlInput (org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 Test (org.junit.Test)1