Search in sources :

Example 1 with PackageImport

use of org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport in project statecharts by Yakindu.

the class STextProposalProvider method completeImportScope_Imports.

@Override
public void completeImportScope_Imports(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    StringProposalDelegate stringProposalDelegate = new StringProposalDelegate(acceptor, context);
    Set<PackageImport> allImports = mapper.getAllImports(model.eResource());
    for (PackageImport pkgImport : allImports) {
        ConfigurableCompletionProposal doCreateProposal = doCreateProposal("\"" + pkgImport.getName() + "\"", computePackageStyledString(pkgImport), getIncludeImage(), pkgImport.getUri().isFile() ? -1 : 1, context);
        stringProposalDelegate.accept(doCreateProposal);
    }
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) PackageImport(org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport)

Example 2 with PackageImport

use of org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport in project statecharts by Yakindu.

the class PackageImportHyperlinkHelper method createPackageImportHyperlinksByOffset.

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()) {
                final URI targetURI = mappedImport.get().getUri();
                XtextHyperlink result = getHyperlinkProvider().get();
                result.setURI(targetURI);
                Region region = new Region(node.getOffset(), node.getLength());
                result.setHyperlinkRegion(region);
                result.setHyperlinkText(targetURI.toString());
                acceptor.accept(result);
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) XtextHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink) ImportScope(org.yakindu.sct.model.stext.stext.ImportScope) Region(org.eclipse.jface.text.Region) PackageImport(org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport) URI(org.eclipse.emf.common.util.URI) RuleCall(org.eclipse.xtext.RuleCall)

Example 3 with PackageImport

use of org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport in project statecharts by Yakindu.

the class StextImportAwareScopeProvider method createNamespaceResolver.

protected List<ImportNormalizer> createNamespaceResolver(Scope scope, boolean ignoreCase) {
    List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList();
    ImportScope importScope = (ImportScope) scope;
    for (String child : importScope.getImports()) {
        Optional<PackageImport> pkgImport = mapper.findPackageImport(scope.eResource(), child);
        if (pkgImport.isPresent()) {
            ImportNormalizer resolver = createImportedNamespaceResolver(pkgImport.get().getNamespace(), ignoreCase);
            if (resolver != null)
                importedNamespaceResolvers.add(resolver);
        }
    }
    return importedNamespaceResolvers;
}
Also used : ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) ImportScope(org.yakindu.sct.model.stext.stext.ImportScope) PackageImport(org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport)

Aggregations

PackageImport (org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport)3 ImportScope (org.yakindu.sct.model.stext.stext.ImportScope)2 URI (org.eclipse.emf.common.util.URI)1 Region (org.eclipse.jface.text.Region)1 RuleCall (org.eclipse.xtext.RuleCall)1 INode (org.eclipse.xtext.nodemodel.INode)1 ImportNormalizer (org.eclipse.xtext.scoping.impl.ImportNormalizer)1 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)1 XtextHyperlink (org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink)1