Search in sources :

Example 1 with AbstractCompositeHover

use of org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover in project xtext-eclipse by eclipse.

the class AbstractCompositeHoverTest method testMultipleHovers.

@SuppressWarnings("deprecation")
@Test
public void testMultipleHovers() {
    final ITextHover hover1 = new ITextHover() {

        @Override
        public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
            // TODO Auto-generated method stub
            if (offset == 0)
                return new Region(offset, 0);
            return null;
        }

        @Override
        public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
            return "hover1";
        }
    };
    final ITextHover hover2 = new ITextHover() {

        @Override
        public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
            // TODO Auto-generated method stub
            if (offset == 1)
                return new Region(offset, 0);
            return null;
        }

        @Override
        public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
            return "hover2";
        }
    };
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            List<ITextHover> hovers = Lists.newArrayList();
            hovers.add(hover1);
            hovers.add(hover2);
            return hovers;
        }
    };
    assertEquals(2, hover.getHovers().size());
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertEquals("hover1", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 1));
    assertEquals("hover2", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(1, 0)));
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 2 with AbstractCompositeHover

use of org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover in project xtext-eclipse by eclipse.

the class AbstractCompositeHoverTest method testNullHoverList.

@SuppressWarnings("deprecation")
@Test
public void testNullHoverList() {
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            return null;
        }
    };
    assertEquals(null, hover.getHovers());
    assertNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertNull(hover.getHoverControlCreator());
    assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNull(hover.getHoverInfo2(editor.getInternalSourceViewer(), new Region(0, 0)));
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 3 with AbstractCompositeHover

use of org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover in project xtext-eclipse by eclipse.

the class AbstractCompositeHoverTest method testEmptyHoverList.

@SuppressWarnings("deprecation")
@Test
public void testEmptyHoverList() {
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            List<ITextHover> hovers = Lists.newArrayList();
            return hovers;
        }
    };
    assertEquals(0, hover.getHovers().size());
    assertNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertNull(hover.getHoverControlCreator());
    assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNull(hover.getHoverInfo2(editor.getInternalSourceViewer(), new Region(0, 0)));
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 4 with AbstractCompositeHover

use of org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover in project xtext-eclipse by eclipse.

the class AbstractCompositeHoverTest method testSingleHover.

@SuppressWarnings("deprecation")
@Test
public void testSingleHover() {
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            List<ITextHover> hovers = Lists.newArrayList();
            hovers.add(new ITextHover() {

                @Override
                public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
                    // TODO Auto-generated method stub
                    if (offset == 0)
                        return new Region(offset, 0);
                    return null;
                }

                @Override
                public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
                    return "test";
                }
            });
            return hovers;
        }
    };
    assertEquals(1, hover.getHovers().size());
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertEquals("test", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 5));
    assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Aggregations

IRegion (org.eclipse.jface.text.IRegion)4 ITextHover (org.eclipse.jface.text.ITextHover)4 Region (org.eclipse.jface.text.Region)4 AbstractCompositeHover (org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover)4 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)4 Test (org.junit.Test)4 ITextViewer (org.eclipse.jface.text.ITextViewer)2