use of com.liferay.ide.xml.search.ui.editor.MarkerRegion in project liferay-ide by liferay.
the class XmlSearchTestsUtils method getTextHover.
private static String[] getTextHover(IFile file, int nodeType, String... nodeNames) throws Exception {
List<String> retval = new ArrayList<String>();
IDOMModel domModel = null;
Node targetNode = null;
final StructuredTextViewer viewer = getEditor(file).getTextViewer();
if (nodeType == Node.ELEMENT_NODE) {
String elementName = nodeNames[0];
domModel = getDOMModel(file, false);
// the actual node is text node of this.element
targetNode = domModel.getDocument().getElementsByTagName(elementName).item(0).getFirstChild();
} else if (nodeType == Node.ATTRIBUTE_NODE) {
String elementName = nodeNames[0];
String attrName = nodeNames[1];
domModel = getDOMModel(file, false);
NodeList elements = domModel.getDocument().getElementsByTagName(elementName);
Element element = getElementByAttr(elements, attrName);
targetNode = element.getAttributes().getNamedItem(attrName);
} else {
return null;
}
int offset = getRegion(targetNode).getOffset();
final Method getTextHoverMethod = ReflectionUtil.getDeclaredMethod(viewer.getClass(), "getTextHover", true, int.class, int.class);
getTextHoverMethod.setAccessible(true);
final ITextHover hover = (ITextHover) getTextHoverMethod.invoke(viewer, offset, 0);
final IRegion region = hover.getHoverRegion(viewer, offset);
if (region instanceof CompoundRegion) {
List<IRegion> regions = ((CompoundRegion) region).getRegions();
for (IRegion reg : regions) {
if (reg instanceof TemporaryRegion) {
String info = ((TemporaryRegion) reg).getAnnotation().getText();
retval.add(info);
}
if (reg instanceof MarkerRegion) {
MarkerAnnotation annotation = ((MarkerRegion) reg).getAnnotation();
String info = (annotation.getMarker().getAttribute(IMarker.MESSAGE)).toString();
retval.add(info);
}
if (reg instanceof InfoRegion) {
retval.add(((InfoRegion) reg).getInfo());
}
}
}
domModel.releaseFromRead();
return retval.toArray(new String[0]);
}
Aggregations