Java Code Examples for org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor#accept()

The following examples show how to use org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor#accept() . 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: 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 2
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 3
Source File: PackageImportHyperlinkHelper.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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 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: DomainmodelHyperlinkHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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 6
Source File: JdtHyperlinkFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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);
}