Search in sources :

Example 31 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project n4js by eclipse.

the class ImportsAwareReferenceProposalCreator method lookupCrossReference.

/**
 * Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
 * list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
 * assist requirements, instead filter here.
 *
 * @param proposalFactory
 *            usually this will be an instance of
 *            {@link AbstractJavaBasedContentProposalProvider.DefaultProposalCreator DefaultProposalCreator}.
 * @param filter
 *            by default an instance of {@link N4JSCandidateFilter} will be provided here.
 */
@SuppressWarnings("javadoc")
public void lookupCrossReference(EObject model, EReference reference, ContentAssistContext context, ICompletionProposalAcceptor acceptor, Predicate<IEObjectDescription> filter, Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
    if (model != null) {
        final IScope scope = ((IContentAssistScopeProvider) scopeProvider).getScopeForContentAssist(model, reference);
        // iterate over candidates, filter them, and create ICompletionProposals for them
        final Iterable<IEObjectDescription> candidates = scope.getAllElements();
        // don't use candidates.forEach since we want an early exit
        for (IEObjectDescription candidate : candidates) {
            if (!acceptor.canAcceptMoreProposals())
                return;
            if (filter.apply(candidate)) {
                QualifiedName qfn = candidate.getQualifiedName();
                String tmodule = null;
                if (qfn.getSegmentCount() >= 2) {
                    tmodule = qfn.getSegment(qfn.getSegmentCount() - 2);
                }
                // In case of main module, adjust the qualified name, e.g. index.Element -> react.Element
                IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
                QualifiedName candidateName;
                if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
                    candidateName = QualifiedName.create(project.getProjectId(), candidate.getQualifiedName().getLastSegment().toString());
                } else {
                    candidateName = candidate.getQualifiedName();
                }
                final ICompletionProposal proposal = getProposal(candidate, model, scope, reference, context, filter, proposalFactory);
                if (proposal instanceof ConfigurableCompletionProposal && candidate.getName().getSegmentCount() > 1) {
                    ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
                    castedProposal.setAdditionalData(FQNImporter.KEY_QUALIFIED_NAME, candidateName);
                    // Original qualified name is the qualified name before adjustment
                    castedProposal.setAdditionalData(FQNImporter.KEY_ORIGINAL_QUALIFIED_NAME, candidate.getQualifiedName());
                }
                acceptor.accept(proposal);
            }
        }
    }
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IContentAssistScopeProvider(org.eclipse.n4js.scoping.IContentAssistScopeProvider) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 32 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project dsl-devkit by dsldevkit.

the class CheckCfgProposalProvider method completeConfiguredParameter_NewValue.

@Override
public // CHECKSTYLE:OFF
void completeConfiguredParameter_NewValue(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
    // CHECKSTYLE:ON
    // TODO filter depending on type of linked parameter
    FormalParameter parameter = ((ConfiguredParameter) model).getParameter();
    ICheckCfgPropertySpecification propertySpecification = null;
    String[] validValues = null;
    if (parameter != null) {
        propertySpecification = CheckCfgUtil.getPropertySpecification(parameter.getName());
        if (propertySpecification != null) {
            validValues = propertySpecification.getExpectedValues();
        }
    }
    if (validValues != null && validValues.length > 0) {
        String info = propertySpecification.getInfo();
        for (String validValue : validValues) {
            ICompletionProposal proposal = createCompletionProposal(String.format("\"%s\"", validValue), new StyledString(validValue), getImage(model), 0, context.getPrefix(), context);
            if (proposal instanceof ConfigurableCompletionProposal) {
                ((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(info);
            }
            acceptor.accept(proposal);
        }
        return;
    }
    super.completeConfiguredParameter_NewValue(model, assignment, context, acceptor);
}
Also used : FormalParameter(com.avaloq.tools.ddk.check.check.FormalParameter) ConfiguredParameter(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredParameter) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ICheckCfgPropertySpecification(com.avaloq.tools.ddk.checkcfg.ICheckCfgPropertySpecification)

Example 33 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project dsl-devkit by dsldevkit.

the class AcfContentAssistProcessorTestBuilder method applyText.

/**
 * Applies a content assist proposal using the expected display string.
 *
 * @param expectedDisplayString
 *          the content assist proposal to apply
 * @param appendSpace
 *          whether to append a space
 * @return a new {@link AcfContentAssistProcessorTestBuilder} with the text applied.
 * @throws Exception
 *           if there was a problem loading the xtext resource
 */
public AcfContentAssistProcessorTestBuilder applyText(final String expectedDisplayString, final boolean appendSpace) throws Exception {
    ICompletionProposal proposal = null;
    for (final ICompletionProposal p : computeCompletionProposals(getModel(), getCursorPosition())) {
        if (expectedDisplayString.equals(p.getDisplayString())) {
            proposal = p;
            break;
        }
    }
    assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
    String text = "";
    if (proposal instanceof ConfigurableCompletionProposal) {
        text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
    } else if (proposal instanceof XtextTemplateProposal) {
        // These may occur in the context of custom content assist templates
        text = ((XtextTemplateProposal) proposal).getAdditionalProposalInfo();
    }
    AcfContentAssistProcessorTestBuilder ret = append(text);
    if (appendSpace) {
        return ret.append(" ");
    }
    return ret;
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) XtextTemplateProposal(org.eclipse.xtext.ui.editor.templates.XtextTemplateProposal)

Example 34 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.

the class STextProposalProvider method alterPriority.

private void alterPriority(ICompletionProposal proposal, int delta) {
    if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal))
        return;
    ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
    castedProposal.setPriority(castedProposal.getPriority() + delta);
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)

Example 35 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project statecharts by Yakindu.

the class SGenProposalProvider method completeGeneratorModel_GeneratorId.

@Override
public void completeGeneratorModel_GeneratorId(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    Iterable<IGeneratorDescriptor> descriptions = GeneratorExtensions.getGeneratorDescriptors();
    for (IGeneratorDescriptor desc : descriptions) {
        ICompletionProposal proposal = createCompletionProposal(desc.getId(), new StyledString((desc.getName() != null) ? desc.getName() : "null"), PathToImageResolver.toImage(desc.getImagePath()), context);
        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
            configurable.setAdditionalProposalInfo(desc.getDescription());
        }
        acceptor.accept(proposal);
    }
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)35 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)21 StyledString (org.eclipse.jface.viewers.StyledString)16 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)8 PrefixMatcher (org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher)5 ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)4 EObject (org.eclipse.emf.ecore.EObject)3 QualifiedName (org.eclipse.xtext.naming.QualifiedName)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 EClass (org.eclipse.emf.ecore.EClass)2 EClassifier (org.eclipse.emf.ecore.EClassifier)2 EPackage (org.eclipse.emf.ecore.EPackage)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ContextTypeRegistry (org.eclipse.jface.text.templates.ContextTypeRegistry)2 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)2 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 EnumRule (org.eclipse.xtext.EnumRule)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 IScope (org.eclipse.xtext.scoping.IScope)2