Search in sources :

Example 26 with ConfigurableCompletionProposal

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

the class JdtTypesProposalProvider method createTypeProposal.

protected void createTypeProposal(final String typeName, int modifiers, boolean isInnerType, ICompletionProposalFactory proposalFactory, ContentAssistContext context, ICompletionProposalAcceptor acceptor, final IJvmTypeProvider jvmTypeProvider, IValueConverter<String> valueConverter) {
    if (acceptor.canAcceptMoreProposals()) {
        int lastDot = typeName.lastIndexOf('.');
        final StyledString displayString;
        if (lastDot != -1) {
            if (isInnerType) {
                displayString = new StyledString(typeName.substring(lastDot + 1).replace('$', '.')).append(" - " + typeName.substring(0, lastDot), StyledString.QUALIFIER_STYLER);
            } else {
                displayString = new StyledString(typeName.substring(lastDot + 1)).append(" - " + typeName.substring(0, lastDot), StyledString.QUALIFIER_STYLER);
            }
        } else {
            displayString = new StyledString(isInnerType ? typeName.replace('$', '.') : typeName);
        }
        Image img = computeImage(typeName, isInnerType, modifiers);
        String proposalAsString = typeName;
        if (valueConverter != null) {
            try {
                proposalAsString = valueConverter.toString(isInnerType ? proposalAsString.replace('$', '.') : proposalAsString);
            } catch (ValueConverterException vce) {
                return;
            }
        }
        ICompletionProposal proposal = proposalFactory.createCompletionProposal(proposalAsString, displayString, img, context);
        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal theProposal = (ConfigurableCompletionProposal) proposal;
            // calculate the type lazy, as this require a lot of time for large completion lists
            theProposal.setAdditionalProposalInfo(new Provider<EObject>() {

                @Override
                public EObject get() {
                    return jvmTypeProvider.findTypeByName(typeName);
                }
            });
            theProposal.setHover(hover);
            priorities.adjustCrossReferencePriority(theProposal, context.getPrefix());
            theProposal.setPriority(theProposal.getPriority() + jdtTypeRelevance.getRelevance(typeName, context.getPrefix()));
        }
        acceptor.accept(proposal);
    }
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EObject(org.eclipse.emf.ecore.EObject) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) Image(org.eclipse.swt.graphics.Image)

Example 27 with ConfigurableCompletionProposal

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

the class TypeAwareReferenceProposalCreator method getWrappedFactory.

@Override
protected Function<IEObjectDescription, ICompletionProposal> getWrappedFactory(EObject model, EReference reference, final Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
    if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(getEReferenceType(model, reference))) {
        return new Function<IEObjectDescription, ICompletionProposal>() {

            @Override
            public ICompletionProposal apply(IEObjectDescription from) {
                ICompletionProposal result = proposalFactory.apply(from);
                if (result instanceof ConfigurableCompletionProposal) {
                    String flags = from.getUserData("flags");
                    if (flags != null) {
                        boolean inner = "true".equals(from.getUserData("inner"));
                        int modifiers = Integer.parseInt(flags);
                        ((ConfigurableCompletionProposal) result).setImage(computeImage(inner, modifiers));
                    }
                }
                return result;
            }
        };
    }
    return super.getWrappedFactory(model, reference, proposalFactory);
}
Also used : Function(com.google.common.base.Function) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 28 with ConfigurableCompletionProposal

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

the class UiToIdeContentProposalProvider method createProposals.

@Override
public void createProposals(final org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
    final ArrayList<Pair<ContentAssistEntry, Integer>> entries = new ArrayList<Pair<ContentAssistEntry, Integer>>();
    final IIdeContentProposalAcceptor ideAcceptor = new IIdeContentProposalAcceptor() {

        @Override
        public void accept(final ContentAssistEntry entry, final int priority) {
            if ((entry != null)) {
                Pair<ContentAssistEntry, Integer> _mappedTo = Pair.<ContentAssistEntry, Integer>of(entry, Integer.valueOf(priority));
                entries.add(_mappedTo);
            }
        }

        @Override
        public boolean canAcceptMoreProposals() {
            int _size = entries.size();
            int _maxProposals = UiToIdeContentProposalProvider.this.getMaxProposals();
            return (_size < _maxProposals);
        }
    };
    ContentAssistContext _ideContext = this.getIdeContext(context);
    this.ideProvider.createProposals(Collections.<ContentAssistContext>unmodifiableList(CollectionLiterals.<ContentAssistContext>newArrayList(_ideContext)), ideAcceptor);
    final AbstractContentProposalProvider.NullSafeCompletionProposalAcceptor uiAcceptor = new AbstractContentProposalProvider.NullSafeCompletionProposalAcceptor(acceptor);
    final Procedure2<Pair<ContentAssistEntry, Integer>, Integer> _function = (Pair<ContentAssistEntry, Integer> p, Integer idx) -> {
        final ContentAssistEntry entry = p.getKey();
        final ConfigurableCompletionProposal proposal = this.doCreateProposal(entry.getProposal(), this.getDisplayString(entry), this.getImage(entry), (p.getValue()).intValue(), context);
        uiAcceptor.accept(proposal);
    };
    IterableExtensions.<Pair<ContentAssistEntry, Integer>>forEach(entries, _function);
}
Also used : ArrayList(java.util.ArrayList) IIdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ContentAssistContext(org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext) AbstractContentProposalProvider(org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 29 with ConfigurableCompletionProposal

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

the class XbaseContentProposalPriorities method adjustCrossReferencePriority.

@Override
public void adjustCrossReferencePriority(final ICompletionProposal proposal, final String prefix) {
    if ((proposal instanceof ConfigurableCompletionProposal)) {
        Object _additionalData = ((ConfigurableCompletionProposal) proposal).getAdditionalData(XbaseProposalProvider.DESCRIPTION_KEY);
        final Object desc = _additionalData;
        boolean _matched = false;
        if (desc instanceof SimpleIdentifiableElementDescription) {
            if (((!Objects.equal(((ConfigurableCompletionProposal) proposal).getReplacementString(), "this")) && (!Objects.equal(((ConfigurableCompletionProposal) proposal).getReplacementString(), "super")))) {
                _matched = true;
                this.adjustPriority(proposal, prefix, 570);
                return;
            }
        }
        if (!_matched) {
            if (desc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) {
                _matched = true;
                this.adjustPriority(proposal, prefix, 560);
            }
        }
        if (!_matched) {
            if (desc instanceof IIdentifiableElementDescription) {
                _matched = true;
                JvmIdentifiableElement _elementOrProxy = ((IIdentifiableElementDescription) desc).getElementOrProxy();
                boolean _matched_1 = false;
                if (_elementOrProxy instanceof JvmField) {
                    _matched_1 = true;
                    this.adjustPriority(proposal, prefix, 550);
                    return;
                }
                if (!_matched_1) {
                    if (_elementOrProxy instanceof JvmExecutable) {
                        _matched_1 = true;
                        this.adjustPriority(proposal, prefix, 520);
                        return;
                    }
                }
            }
        }
    }
    super.adjustCrossReferencePriority(proposal, prefix);
}
Also used : SimpleIdentifiableElementDescription(org.eclipse.xtext.xbase.scoping.batch.SimpleIdentifiableElementDescription) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IIdentifiableElementDescription(org.eclipse.xtext.xbase.scoping.batch.IIdentifiableElementDescription) JvmField(org.eclipse.xtext.common.types.JvmField) StaticFeatureDescriptionWithTypeLiteralReceiver(org.eclipse.xtext.xbase.scoping.batch.StaticFeatureDescriptionWithTypeLiteralReceiver)

Example 30 with ConfigurableCompletionProposal

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

the class ImportsAwareReferenceProposalCreator method getProposal.

/**
 * Creates initial proposal adjusted for the N4JS imports. Then passes that proposal to the provided delegate
 * proposal factory. Obtained ICompletionProposal is configured with a FQNImporter as custom text. applier.
 *
 * @param candidate
 *            for which proposal is created
 * @param delegateProposalFactory
 *            delegate proposal factory
 * @return code completion proposal
 */
private ICompletionProposal getProposal(IEObjectDescription candidate, EObject model, IScope scope, EReference reference, ContentAssistContext context, Predicate<IEObjectDescription> filter, Function<IEObjectDescription, ICompletionProposal> delegateProposalFactory) {
    final IEObjectDescription inputToUse = getAliasedDescription(candidate, reference, context);
    final ICompletionProposal result = delegateProposalFactory.apply(inputToUse);
    if (result instanceof ConfigurableCompletionProposal) {
        final FQNImporter importer = fqnImporterFactory.create(model.eResource(), scope, valueConverter, filter, context.getViewer());
        ((ConfigurableCompletionProposal) result).setTextApplier(importer);
    }
    return result;
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

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