Search in sources :

Example 11 with ConfigurableCompletionProposal

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

the class STextProposalProvider method getProposalFactory.

protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName, ContentAssistContext contentAssistContext) {
    return new DefaultProposalCreator(contentAssistContext, ruleName, getQualifiedNameConverter()) {

        @Override
        public ICompletionProposal apply(IEObjectDescription candidate) {
            ICompletionProposal proposal = super.apply(candidate);
            EObject eObjectOrProxy = candidate.getEObjectOrProxy();
            if (eObjectOrProxy.eIsProxy()) {
                return proposal;
            }
            if (eObjectOrProxy instanceof Operation) {
                Operation operation = (Operation) eObjectOrProxy;
                if (operation.getParameters().size() > 0 && (proposal instanceof ConfigurableCompletionProposal)) {
                    ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) proposal;
                    configurableProposal.setReplacementString(configurableProposal.getReplacementString() + "()");
                    configurableProposal.setCursorPosition(configurableProposal.getCursorPosition() + 1);
                }
            }
            return proposal;
        }
    };
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EObject(org.eclipse.emf.ecore.EObject) Operation(org.yakindu.base.types.Operation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 12 with ConfigurableCompletionProposal

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

the class STextProposalProvider method complete_HEX.

@Override
public void complete_HEX(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    ICompletionProposalAcceptor priorityOptimizer = getCustomAcceptor(model, "integer", acceptor);
    String proposalText = "0x1";
    ICompletionProposal proposal = createCompletionProposal(proposalText, proposalText + " - " + ruleCall.getRule().getName(), null, context);
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
        configurable.setSelectionLength(proposalText.length() - 2);
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
    }
    priorityOptimizer.accept(proposal);
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) ICompletionProposalAcceptor(org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor)

Example 13 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal 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 14 with ConfigurableCompletionProposal

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

the class StringProposalDelegate method accept.

@Override
public void accept(ICompletionProposal proposal) {
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurableCompletionProposal = (ConfigurableCompletionProposal) proposal;
        int endPos = configurableCompletionProposal.getReplacementOffset() + configurableCompletionProposal.getReplacementLength();
        if (ctx.getDocument() != null && ctx.getDocument().getLength() > endPos) {
            // We are not at the end of the file
            try {
                if ("\"".equals(ctx.getDocument().get(endPos, 1))) {
                    configurableCompletionProposal.setReplacementLength(configurableCompletionProposal.getReplacementLength() - 1);
                    configurableCompletionProposal.setReplacementString(configurableCompletionProposal.getReplacementString().substring(0, configurableCompletionProposal.getReplacementString().length() - 1));
                }
            } catch (BadLocationException e) {
                LOG.debug("Skipped propsal adjustment.", e);
            }
        }
    }
    super.accept(proposal);
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 15 with ConfigurableCompletionProposal

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

the class ContentAssistProcessorTestBuilder method getProposedText.

protected String getProposedText(ICompletionProposal completionProposal) {
    String proposedText = completionProposal.getDisplayString();
    if (completionProposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) completionProposal;
        proposedText = configurableProposal.getReplacementString();
        if (configurableProposal.getTextApplier() instanceof ReplacementTextApplier) {
            proposedText = ((ReplacementTextApplier) configurableProposal.getTextApplier()).getActualReplacementString(configurableProposal);
        }
    }
    return proposedText;
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ReplacementTextApplier(org.eclipse.xtext.ui.editor.contentassist.ReplacementTextApplier)

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