Search in sources :

Example 1 with XtextBrowserInformationControlInput

use of org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput in project xtext-xtend by eclipse.

the class XtendHoverProvider method getHoverInfo.

@Override
protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion, XtextBrowserInformationControlInput previous) {
    XtextBrowserInformationControlInput hoverInfo = super.getHoverInfo(element, hoverRegion, previous);
    if (hoverInfo instanceof XbaseInformationControlInput) {
        XbaseInformationControlInput xbaseHoverInfo = (XbaseInformationControlInput) hoverInfo;
        Pair<String, String> prefixAndSuffixPair = xtendHoverSerializer.computePreAndSuffix(element);
        String unsugaredExpression = xtendHoverSerializer.computeUnsugaredExpression(element);
        return new XbaseInformationControlInput(previous, xbaseHoverInfo, prefixAndSuffixPair.getFirst(), unsugaredExpression, prefixAndSuffixPair.getSecond());
    }
    return hoverInfo;
}
Also used : XbaseInformationControlInput(org.eclipse.xtext.xbase.ui.hover.XbaseInformationControlInput) XtextBrowserInformationControlInput(org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput)

Example 2 with XtextBrowserInformationControlInput

use of org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput in project xtext-xtend by eclipse.

the class XtendHoverInEditorTest method testHoverOfReferencedElementWithAnnotation.

@Test
public void testHoverOfReferencedElementWithAnnotation() {
    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("@SuppressWarnings(\"foo\")");
        _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);
        final Runnable _function = () -> {
            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(), info.getHtml().contains("Hello Foo"));
            Assert.assertTrue(info.getHtml(), info.getHtml().contains("SuppressWarnings</a>(\"foo\")"));
        };
        final LoggingTester.LogCapture loggings = LoggingTester.captureLogging(Level.ERROR, AbstractBatchTypeResolver.class, _function);
        loggings.assertNoLogEntries();
        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("@SuppressWarnings(\"bar\")");
        _builder_2.newLine();
        _builder_2.append("class Foo {}");
        _builder_2.newLine();
        _document.set(_builder_2.toString());
        this._syncUtil.waitForReconciler(fooEditor);
        this._syncUtil.waitForReconciler(editor);
        final Runnable _function_1 = () -> {
            ISourceViewer _internalSourceViewer = editor.getInternalSourceViewer();
            Region _region = new Region(19, 1);
            Object _hoverInfo2 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer), _region);
            final XtextBrowserInformationControlInput info2 = ((XtextBrowserInformationControlInput) _hoverInfo2);
            Assert.assertFalse(info2.getHtml().contains("Hello Foo"));
            Assert.assertTrue(info2.getHtml().contains("Hello BAZ"));
            Assert.assertTrue(info2.getHtml(), info2.getHtml().contains("SuppressWarnings</a>(\"bar\")"));
        };
        final LoggingTester.LogCapture moreLoggings = LoggingTester.captureLogging(Level.ERROR, AbstractBatchTypeResolver.class, _function_1);
        moreLoggings.assertNoLogEntries();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextBrowserInformationControlInput(org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput) LoggingTester(org.eclipse.xtext.testing.logging.LoggingTester) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Region(org.eclipse.jface.text.Region) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 3 with XtextBrowserInformationControlInput

use of org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput 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)

Aggregations

XtextBrowserInformationControlInput (org.eclipse.xtext.ui.editor.hover.html.XtextBrowserInformationControlInput)3 IFile (org.eclipse.core.resources.IFile)2 Region (org.eclipse.jface.text.Region)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)2 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)2 Test (org.junit.Test)2 ITextHoverExtension2 (org.eclipse.jface.text.ITextHoverExtension2)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 LoggingTester (org.eclipse.xtext.testing.logging.LoggingTester)1 XbaseInformationControlInput (org.eclipse.xtext.xbase.ui.hover.XbaseInformationControlInput)1