use of org.eclipse.jface.text.ITextHover 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;
}
}
use of org.eclipse.jface.text.ITextHover 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)));
}
use of org.eclipse.jface.text.ITextHover 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)));
}
use of org.eclipse.jface.text.ITextHover 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)));
}
use of org.eclipse.jface.text.ITextHover in project webtools.sourceediting by eclipse.
the class BestMatchHover method createTextHoversList.
/**
* Create a list of text hovers applicable to this best match hover
* processor
*
* @return List of ITextHover - in abstract class this is empty list
*/
private List createTextHoversList() {
List hoverList = new ArrayList();
// best match
if (Logger.isTracing(DebugInfoHoverProcessor.TRACEFILTER)) {
hoverList.add(new DebugInfoHoverProcessor());
}
hoverList.add(new ProblemAnnotationHoverProcessor());
if (fPartitionType != null && fTagInfoHovers == null) {
List extendedTextHover = ExtendedConfigurationBuilder.getInstance().getConfigurations(ExtendedConfigurationBuilder.DOCUMENTATIONTEXTHOVER, fPartitionType);
fTagInfoHovers = (ITextHover[]) extendedTextHover.toArray(new ITextHover[extendedTextHover.size()]);
}
if (fTagInfoHovers != null) {
for (int i = 0; i < fTagInfoHovers.length; i++) {
hoverList.add(fTagInfoHovers[i]);
}
}
hoverList.add(new AnnotationHoverProcessor());
return hoverList;
}
Aggregations