Search in sources :

Example 1 with StaticFeatureDescription

use of org.eclipse.xtext.xbase.scoping.batch.StaticFeatureDescription in project xtext-eclipse by eclipse.

the class XbaseProposalProvider method createLocalVariableAndImplicitProposals.

protected void createLocalVariableAndImplicitProposals(EObject context, IExpressionScope.Anchor anchor, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
    String prefix = contentAssistContext.getPrefix();
    if (prefix.length() > 0) {
        if (!Character.isJavaIdentifierStart(prefix.charAt(0))) {
            if (prefix.length() > 1) {
                if (prefix.charAt(0) == '^' && !Character.isJavaIdentifierStart(prefix.charAt(1))) {
                    return;
                }
            }
        }
    }
    // long time = System.currentTimeMillis();
    Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext);
    IResolvedTypes resolvedTypes = context != null ? typeResolver.resolveTypes(context) : typeResolver.resolveTypes(contentAssistContext.getResource());
    IExpressionScope expressionScope = resolvedTypes.getExpressionScope(context, anchor);
    // TODO use the type name information
    IScope scope = expressionScope.getFeatureScope();
    getCrossReferenceProposalCreator().lookupCrossReference(scope, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
    // System.out.printf("XbaseProposalProvider.createLocalVariableAndImplicitProposals = %d\n", System.currentTimeMillis() - time);
    // time = System.currentTimeMillis();
    // TODO use the type name information
    proposeDeclaringTypeForStaticInvocation(context, null, /* ignore */
    contentAssistContext, acceptor);
    // System.out.printf("XbaseProposalProvider.proposeDeclaringTypeForStaticInvocation = %d\n", System.currentTimeMillis() - time);
    if (context != null && !(context instanceof XMemberFeatureCall)) {
        Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(context, input -> true);
        // Create StaticFeatureDescription instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters
        Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> {
            QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName());
            return new StaticFeatureDescription(qualifiedName, feature, 0, true);
        });
        // Scope for all static features
        IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
        proposeFavoriteStaticFeatures(context, contentAssistContext, acceptor, staticMemberScope);
    }
}
Also used : IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IExpressionScope(org.eclipse.xtext.xbase.typesystem.IExpressionScope) StyledString(org.eclipse.jface.viewers.StyledString) StaticFeatureDescription(org.eclipse.xtext.xbase.scoping.batch.StaticFeatureDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IScope(org.eclipse.xtext.scoping.IScope)

Aggregations

ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 StyledString (org.eclipse.jface.viewers.StyledString)1 JvmFeature (org.eclipse.xtext.common.types.JvmFeature)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)1 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)1 StaticFeatureDescription (org.eclipse.xtext.xbase.scoping.batch.StaticFeatureDescription)1 IExpressionScope (org.eclipse.xtext.xbase.typesystem.IExpressionScope)1 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)1