use of org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor 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.IHyperlinkAcceptor in project xtext-eclipse by eclipse.
the class XbaseHyperLinkHelper method createHyperlinksByOffset.
/**
* If multiple links are requested, all ambiguous candidates are provided for feature and constructor calls.
*/
@Override
public IHyperlink[] createHyperlinksByOffset(XtextResource resource, int offset, boolean createMultipleHyperlinks) {
List<IHyperlink> links = Lists.newArrayList();
IHyperlinkAcceptor acceptor = new XbaseHyperlinkAcceptor(links, createMultipleHyperlinks);
super.createHyperlinksByOffset(resource, offset, acceptor);
INode crossRefNode = getEObjectAtOffsetHelper().getCrossReferenceNode(resource, new TextRegion(offset, 0));
if (crossRefNode == null) {
this.createHyperlinksByOffset(resource, offset, acceptor);
} else {
this.createHyperlinksForCrossRef(resource, crossRefNode, acceptor);
}
if (!links.isEmpty())
return Iterables.toArray(links, IHyperlink.class);
return null;
}
use of org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor 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