use of org.eclipse.xtext.ui.editor.hyperlinking.AbstractHyperlink in project xtext-eclipse by eclipse.
the class XbaseHyperLinkHelper method createHyperlinksForCrossRef.
protected void createHyperlinksForCrossRef(XtextResource resource, INode crossRefNode, final IHyperlinkAcceptor acceptor) {
EObject containedElementAt = getEObjectAtOffsetHelper().resolveContainedElementAt(resource, crossRefNode.getOffset());
if (containedElementAt instanceof XAbstractFeatureCall) {
IResolvedTypes resolveTypes = typeResolver.resolveTypes(resource);
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) containedElementAt;
final JvmIdentifiableElement targetElement = featureCall.getFeature();
if (targetElement instanceof JvmType || featureCall.getFeature() instanceof JvmEnumerationLiteral) {
return;
}
IJavaElement javaElement = javaElementFinder.findExactElementFor(targetElement);
if (sourceViewer != null && javaElement != null && (javaElement.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod) javaElement))) {
acceptor.accept(new XbaseImplementatorsHyperlink(javaElement, new Region(crossRefNode.getOffset(), crossRefNode.getLength()), sourceViewer, implOpener));
}
LightweightTypeReference typeReference = resolveTypes.getActualType(featureCall);
if (typeReference == null || typeReference.isPrimitive() || typeReference.isPrimitiveVoid()) {
return;
}
final JvmType type = typeReference.getType();
if (type != null)
createHyperlinksTo(resource, crossRefNode, type, new IHyperlinkAcceptor() {
@Override
public void accept(IHyperlink hyperlink) {
if (hyperlink instanceof AbstractHyperlink) {
String target = labelForTargetElement(targetElement);
((AbstractHyperlink) hyperlink).setHyperlinkText("Open " + target + " Type - " + type.getSimpleName());
}
acceptor.accept(hyperlink);
}
private String labelForTargetElement(final JvmIdentifiableElement targetElement) {
String target = "Return";
if (targetElement instanceof JvmField) {
target = "Field";
} else if (targetElement instanceof JvmFormalParameter) {
// special case for variables in switch and for loops
if (targetElement.eContainer() instanceof XSwitchExpression || targetElement.eContainer() instanceof XForLoopExpression) {
target = "Variable";
} else {
target = "Parameter";
}
} else if (targetElement instanceof XVariableDeclaration) {
target = "Variable";
}
return target;
}
});
}
}
use of org.eclipse.xtext.ui.editor.hyperlinking.AbstractHyperlink in project xtext-eclipse by eclipse.
the class XbaseHyperLinkHelper method addOpenInferredTypeHyperlink.
protected void addOpenInferredTypeHyperlink(final XtextResource resource, JvmIdentifiableElement typedElement, ILeafNode node, final IHyperlinkAcceptor acceptor) {
IResolvedTypes resolveTypes = typeResolver.resolveTypes(resource);
final LightweightTypeReference type = resolveTypes.getActualType(typedElement);
if (type != null && !type.isUnknown() && type.getType() != null) {
createHyperlinksTo(resource, new Region(node.getOffset(), node.getLength()), type.getType(), new IHyperlinkAcceptor() {
@Override
public void accept(IHyperlink hyperlink) {
if (hyperlink instanceof AbstractHyperlink) {
AbstractHyperlink abstractHyperlink = (AbstractHyperlink) hyperlink;
abstractHyperlink.setHyperlinkText("Open Inferred Type - " + type.getSimpleName());
abstractHyperlink.setTypeLabel(SingleHoverShowingHyperlinkPresenter.SHOW_ALWAYS);
}
acceptor.accept(hyperlink);
}
});
}
}
Aggregations