Java Code Examples for org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink#setURI()

The following examples show how to use org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink#setURI() . 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: PackageJsonHyperlinkHelperExtension.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IHyperlink[] getHyperlinks(XtextResource resource, int offset) {
	EObject eObject = eObjectAtOffsetHelper.resolveElementAt(resource, offset);
	Pair<SafeURI<?>, Region> linkedProjectWithRegion = getUriRegionPair(eObject);

	if (linkedProjectWithRegion != null) {
		URI uri = linkedProjectWithRegion.getFirst().toURI();
		IRegion region = linkedProjectWithRegion.getSecond();
		IN4JSProject uriProject = model.findProject(uri).orNull();

		String lnkName = uriProject == null ? ProjectDescriptionUtils.deriveN4JSProjectNameFromURI(uri)
				: uriProject.getProjectName().getRawName();

		XtextHyperlink hyperlink = hyperlinkProvider.get();
		hyperlink.setHyperlinkRegion(region);
		hyperlink.setURI(uri);
		hyperlink.setHyperlinkText(lnkName);

		return new IHyperlink[] { hyperlink };
	}

	return null;
}
 
Example 2
Source File: SolidityHyperlinkHelper.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
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 3
Source File: XtextHyperlinkHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 4
Source File: N4JSHyperlinkHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
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 5
Source File: PackageImportHyperlinkHelper.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected IHyperlink createHyperlink(INode node, final PackageImport pkgImport) {
	XtextHyperlink result = getHyperlinkProvider().get();
	result.setURI(pkgImport.getFileURI());
	Region region = new Region(node.getOffset(), node.getLength());
	result.setHyperlinkRegion(region);
	result.setHyperlinkText(pkgImport.getUri().toString());
	return result;
}