org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor Java Examples
The following examples show how to use
org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N4JSHyperlinkHelper.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** This method provides multiple hyperlinks for composed members. */ private boolean provideHyperlinksForComposedTypes(XtextResource from, Region region, EObject target, IHyperlinkAcceptor acceptor) { if (target instanceof TMember) { TMember member = (TMember) target; if (member.isComposed()) { List<TMember> constituentMembers = member.getConstituentMembers(); for (TMember constituentMember : constituentMembers) { internalCreateHyperlinksTo(from, region, constituentMember, acceptor); } return true; } } return false; }
Example #2
Source File: PackageImportHyperlinkHelper.java From statecharts with Eclipse Public License 1.0 | 6 votes |
protected void createPackageImportHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { INode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset); if (node != null && node.getGrammarElement() instanceof RuleCall && node.getSemanticElement() instanceof ImportScope) { NodeModelUtils.findNodesForFeature(node.getSemanticElement(), TypesPackage.Literals.PACKAGE__IMPORT); ImportScope importScope = (ImportScope) node.getSemanticElement(); EList<String> imports = importScope.getImports(); for (String pkgImport : imports) { Optional<PackageImport> mappedImport = mapper.findPackageImport(resource, pkgImport); if (mappedImport.isPresent()) { acceptor.accept(createHyperlink(node, mappedImport.get())); } } } }
Example #3
Source File: CheckHyperlinkHelper.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
@Override public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) { IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (activeEditor.getEditorInput() instanceof XtextReadonlyEditorInput) { INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0)); if (crossRefNode == null) { return; } EObject crossLinkedEObject = eObjectAtOffsetHelper.getCrossReferencedElement(crossRefNode); if (crossLinkedEObject != null && crossLinkedEObject.eClass().getEPackage() != CheckPackage.eINSTANCE) { return; } // if EPackage of referenced object is CheckPackage, try to provide hyperlinks: works for included catalogs } super.createHyperlinksByOffset(resource, offset, acceptor); }
Example #4
Source File: FormatHyperlinkHelper.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ @Override public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) { final IParseResult parseResult = resource.getParseResult(); if (parseResult == null || parseResult.getRootNode() == null) { return; // Return, no need to call in super.createAdditionalHyperlinks } // Check if the current parse tree node represents an override keyword, in which case we want to link // to the overridden rule INode node = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset); if (node != null && isOverrideKeyword(node.getGrammarElement())) { Rule rule = (Rule) eObjectAtOffsetHelper.resolveElementAt(resource, offset); Region region = new Region(node.getOffset(), node.getLength()); List<Rule> extendedRules = getExtendedRules(rule); for (Rule extendedRule : extendedRules) { createHyperlinksTo(resource, region, extendedRule, acceptor); } } super.createHyperlinksByOffset(resource, offset, acceptor); }
Example #5
Source File: SolidityHyperlinkHelper.java From solidity-ide with Eclipse Public License 1.0 | 6 votes |
protected void createImportedNamespacesHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { INode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset); if (node != null) { List<INode> importNodes = NodeModelUtils.findNodesForFeature(node.getSemanticElement(), SolidityPackage.Literals.IMPORT_DIRECTIVE__IMPORTED_NAMESPACE); if (importNodes != null && !importNodes.isEmpty()) { for (INode importNode : importNodes) { ImportDirective importElement = (ImportDirective) importNode.getSemanticElement(); URI targetURI = getFileURIOfImport(importElement); XtextHyperlink result = getHyperlinkProvider().get(); result.setURI(targetURI); Region region = new Region(importNode.getOffset(), importNode.getLength()); result.setHyperlinkRegion(region); result.setHyperlinkText(targetURI.toString()); acceptor.accept(result); } } } }
Example #6
Source File: DotHyperlinkHelper.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { EObject eObject = getEObjectAtOffsetHelper().resolveElementAt(resource, offset); if (eObject instanceof NodeId) { NodeId nodeId = (NodeId) eObject; IRegion hyperlinkRegion = getHyperlinkRegion(nodeId); EObject container = nodeId.eContainer(); // if the node is either left or right part of an edge if (container instanceof EdgeStmtNode || container instanceof EdgeRhsNode) { createHyperlinkToNodeDefinition(resource, hyperlinkRegion, nodeId, acceptor); } } }
Example #7
Source File: XtextHyperlinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void createLinksToBase(ITextRegion nameLocation, AbstractRule rule, IHyperlinkAcceptor acceptor) { Set<AbstractRule> visited = Sets.newHashSet(); Grammar grammar = GrammarUtil.getGrammar(rule); for(Grammar used: grammar.getUsedGrammars()) { String ruleName = rule.getName(); AbstractRule overwritten = GrammarUtil.findRuleForName(used, ruleName); if (overwritten != null && visited.add(overwritten)) { URIConverter uriConverter = rule.eResource().getResourceSet().getURIConverter(); String hyperlinkText = getLabelProvider().getText(rule) + " - " + GrammarUtil.getGrammar(overwritten).getName(); URI uri = uriConverter.normalize(EcoreUtil.getURI(overwritten)); XtextHyperlink result = getHyperlinkProvider().get(); deprecatedSetRegion(result, toRegion(nameLocation)); result.setURI(uri); result.setHyperlinkText(hyperlinkText); result.setTypeLabel("Go To Base"); acceptor.accept(result); } } }
Example #8
Source File: XbaseHyperLinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * 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; }
Example #9
Source File: XbaseHyperLinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
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); } }); } }
Example #10
Source File: XbaseHyperLinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Creates hyperlinks on types referenced in javadoc comments. * * @since 2.16 */ protected void createHyperlinksInJavaDoc(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { EObjectInComment eObjectReferencedInComment = javaDocTypeReferenceProvider.computeEObjectReferencedInComment(resource, offset); if(eObjectReferencedInComment != null) { EObject target = eObjectReferencedInComment.getEObject(); ITextRegion region = eObjectReferencedInComment.getRegion(); createHyperlinksTo(resource, new Region(region.getOffset(), region.getLength()), target, acceptor); } }
Example #11
Source File: XtendHyperlinkHelper.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * This redirects the hyperlinks to all source elements of an inferred element. */ @Override public void createHyperlinksTo(XtextResource from, Region region, EObject to, IHyperlinkAcceptor acceptor) { Set<EObject> sourceElements = associations.getSourceElements(to); if (sourceElements.isEmpty()) { super.createHyperlinksTo(from, region, to, acceptor); } else { for (EObject sourceElement : sourceElements) { super.createHyperlinksTo(from, region, sourceElement, acceptor); } } }
Example #12
Source File: DotHyperlinkHelper.java From gef with Eclipse Public License 2.0 | 5 votes |
private void createHyperlinkToNodeDefinition(XtextResource resource, IRegion hyperlinkRegion, NodeId nodeId, IHyperlinkAcceptor acceptor) { NodeId targetSemanticObject = DotAstHelper.getNodeId(nodeId); if (targetSemanticObject != null) { createHyperlinksTo(resource, (Region) hyperlinkRegion, targetSemanticObject, acceptor); } }
Example #13
Source File: TypeAwareHyperlinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void createHyperlinksTo(XtextResource from, Region region, EObject to, IHyperlinkAcceptor acceptor) { if (jdtHyperlinkFactory.canHandle(to)) jdtHyperlinkFactory.createHyperlink(region, to, acceptor); else super.createHyperlinksTo(from, region, to, acceptor); }
Example #14
Source File: JdtHyperlinkFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void createHyperlink(Region region, EObject to, IHyperlinkAcceptor acceptor) { JvmIdentifiableElement element = (JvmIdentifiableElement) to; IJavaElement javaElement = javaElementFinder.findElementFor(element); if (javaElement == null) return; String label = JavaElementLabels.getElementLabel(javaElement, JavaElementLabels.ALL_DEFAULT); JdtHyperlink result = jdtHyperlinkProvider.get(); result.setHyperlinkRegion(region); result.setHyperlinkText(label); result.setJavaElement(javaElement); acceptor.accept(result); }
Example #15
Source File: N4JSHyperlinkHelper.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public void createHyperlinksTo(XtextResource from, Region region, EObject target, IHyperlinkAcceptor acceptor) { boolean linksProvided = provideHyperlinksForComposedTypes(from, region, target, acceptor); if (!linksProvided) { internalCreateHyperlinksTo(from, region, target, acceptor); } }
Example #16
Source File: DomainmodelHyperlinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { super.createHyperlinksByOffset(resource, offset, acceptor); EObject eObject = getEObjectAtOffsetHelper().resolveElementAt(resource, offset); if (eObject instanceof Entity) { List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject, DomainmodelPackage.Literals.ABSTRACT_ELEMENT__NAME); if (!nodes.isEmpty()) { INode node = nodes.get(0); if (node.getOffset() <= offset && node.getOffset() + node.getLength() > offset) { String qualifiedJavaName = qualifiedNameConverter.toString(qualifiedNameProvider.getFullyQualifiedName(eObject)); if (resource.getResourceSet() instanceof XtextResourceSet) { XtextResourceSet resourceSet = (XtextResourceSet) resource.getResourceSet(); Object uriContext = resourceSet.getClasspathURIContext(); if (uriContext instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) uriContext; try { IType type = javaProject.findType(qualifiedJavaName); if (type != null) { JdtHyperlink hyperlink = jdtHyperlinkProvider.get(); hyperlink.setJavaElement(type); hyperlink.setTypeLabel("Navigate to generated source code."); hyperlink.setHyperlinkText("Go to type " + qualifiedJavaName); hyperlink.setHyperlinkRegion((IRegion) new Region(node.getOffset(), node.getLength())); acceptor.accept(hyperlink); } } catch(JavaModelException e) { logger.error(e.getMessage(), e); } } } } } } }
Example #17
Source File: XtextHyperlinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { super.createHyperlinksByOffset(resource, offset, acceptor); EObject objectAtOffset = eObjectAtOffsetHelper.resolveElementAt(resource, offset); if (objectAtOffset instanceof AbstractRule) { ITextRegion nameLocation = locationInFileProvider.getSignificantTextRegion(objectAtOffset, XtextPackage.Literals.ABSTRACT_RULE__NAME, 0); if (nameLocation != null && nameLocation.contains(offset)) { AbstractRule rule = (AbstractRule) objectAtOffset; createLinksToBase(nameLocation, rule, acceptor); if (rule.getType() != null && rule.getType().getClassifier() != null && NodeModelUtils.getNode(rule.getType()) == null) { createHyperlinksTo(resource, toRegion(nameLocation), rule.getType().getClassifier(), acceptor); } } } }
Example #18
Source File: SolidityHyperlinkHelper.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
@Override public void createHyperlinksTo(XtextResource from, Region region, EObject target, IHyperlinkAcceptor acceptor) { if (((AbstractTypeSystem)typeSystem).getResource() == target.eResource()) { // build-in elements are defined in the resource of the type system // don't create hyperlinks to them return; } super.createHyperlinksTo(from, region, target, acceptor); }
Example #19
Source File: N4JSHyperlinkHelper.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void superCreateHyperlinksTo(IRegion region, EObject target, IHyperlinkAcceptor acceptor, URI normalized) { String hyperlinkText = labelProvider.getText(target); XtextHyperlink result = hyperlinkProvider.get(); result.setHyperlinkRegion(region); result.setURI(normalized); result.setHyperlinkText(hyperlinkText); acceptor.accept(result); }
Example #20
Source File: N4JSHyperlinkHelper.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** This method converts file URIs to platform URIs for external library files. */ private boolean provideHyperlinksForExternalFiles(IRegion region, EObject target, IHyperlinkAcceptor acceptor) { URI targetUriWithFragment = EcoreUtil.getURI(target); if (targetUriWithFragment.isFile()) { URI uri = URIUtils.tryToPlatformUri(targetUriWithFragment); superCreateHyperlinksTo(region, target, acceptor, uri); return true; } return false; }
Example #21
Source File: N4JSHyperlinkHelper.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void internalCreateHyperlinksTo(XtextResource from, Region region, EObject target, IHyperlinkAcceptor acceptor) { boolean linksProvided = provideHyperlinksForExternalFiles(region, target, acceptor); if (!linksProvided) { super.createHyperlinksTo(from, region, target, acceptor); } }
Example #22
Source File: XtextHyperlinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public void createHyperlinksTo(XtextResource from, Region region, EObject to, IHyperlinkAcceptor acceptor) { if (acceptHyperLink(from, to)) { super.createHyperlinksTo(from, region, to, acceptor); } }
Example #23
Source File: SolidityHyperlinkHelper.java From solidity-ide with Eclipse Public License 1.0 | 4 votes |
@Override public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { createImportedNamespacesHyperlinksByOffset(resource, offset, acceptor); super.createHyperlinksByOffset(resource, offset, acceptor); }
Example #24
Source File: XtendHyperlinkHelper.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
private void createMultipleLinks(XtextResource resource, INode crossRefNode, List<? extends ILinkingCandidate> alternatives, IHyperlinkAcceptor acceptor) { for (ILinkingCandidate alternative : alternatives) { createHyperlinksTo(resource, crossRefNode, alternative.getFeature(), acceptor); } }
Example #25
Source File: PackageImportHyperlinkHelper.java From statecharts with Eclipse Public License 1.0 | 4 votes |
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { createPackageImportHyperlinksByOffset(resource, offset, acceptor); super.createHyperlinksByOffset(resource, offset, acceptor); }
Example #26
Source File: PackageImportHyperlinkHelper.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@Override public void createHyperlinksTo(XtextResource from, Region region, EObject target, IHyperlinkAcceptor acceptor) { super.createHyperlinksTo(from, region, getOriginTarget(target), acceptor); }
Example #27
Source File: XbaseHyperLinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 2 votes |
/** * Returns false if the acceptor can definitely not accept more than one hyperlink. * Otherwise or if in doubt, returns true. * * Only handles {@link XbaseHyperlinkAcceptor XbaseHyperlinkAcceptors} well. All other cases will assume true. * @since 2.8 */ protected boolean canShowMany(final IHyperlinkAcceptor acceptor) { if (acceptor instanceof XbaseHyperlinkAcceptor) return ((XbaseHyperlinkAcceptor)acceptor).canShowMany(); return true; }