@Override
public IHyperlink createHyperlink(String name, String target, Node node, Node parentNode, IDocument document,
ITextViewer textViewer, IRegion hyperlinkRegion, IRegion cursor, Node annotation) {
IFile file = BeansEditorUtils.getFile(document);
ToolAnnotationData annotationData = ToolAnnotationUtils.getToolAnnotationData(annotation);
if (REF_ATTRIBUTE.equals(annotationData.getKind())) {
Node bean = BeansEditorUtils.getFirstReferenceableNodeById(node.getOwnerDocument(), target, file);
if (bean != null) {
IRegion region = getHyperlinkRegion(bean);
return new NodeElementHyperlink(hyperlinkRegion, region, textViewer);
}
else {
// assume this is an external reference
Iterator<?> beans = BeansEditorUtils.getBeansFromConfigSets(file).iterator();
while (beans.hasNext()) {
IBean modelBean = (IBean) beans.next();
if (modelBean.getElementName().equals(target)) {
return new ExternalBeanHyperlink(modelBean, hyperlinkRegion);
}
}
}
}
else if (Class.class.getName().equals(annotationData.getExpectedType())) {
IHyperlink[] detectedHyperlinks = HyperlinkUtils.getXmlJavaHyperlinks(textViewer, hyperlinkRegion);
// only return hyperlink if no xml Java hyperlink will be created to avoid duplicates
if (detectedHyperlinks == null || detectedHyperlinks.length == 0) {
if (file != null && file.exists()) {
IType type = JdtUtils.getJavaType(file.getProject(), target);
if (type != null) {
return new JavaElementHyperlink(hyperlinkRegion, type);
}
}
}
}
if (annotationData.getExpectedMethodType() != null) {
String className = evaluateXPathExpression(annotationData.getExpectedMethodType(), node);
return createMethodHyperlink(target, hyperlinkRegion, file, className);
}
else if (annotationData.getExpectedMethodRef() != null) {
String typeName = evaluateXPathExpression(annotationData.getExpectedMethodRef(), node);
String className = BeansEditorUtils.getClassNameForBean(file, node.getOwnerDocument(), typeName);
return createMethodHyperlink(target, hyperlinkRegion, file, className);
}
return null;
}