Search in sources :

Example 1 with IExpressionScope

use of org.eclipse.xtext.xbase.typesystem.IExpressionScope 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)

Example 2 with IExpressionScope

use of org.eclipse.xtext.xbase.typesystem.IExpressionScope in project xtext-eclipse by eclipse.

the class XbaseProposalProvider method createReceiverProposals.

protected void createReceiverProposals(XExpression receiver, CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
    // long time = System.currentTimeMillis();
    String ruleName = getConcreteSyntaxRuleName(crossReference);
    Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(ruleName, contentAssistContext);
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(receiver);
    LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
    if (receiverType == null || receiverType.isPrimitiveVoid()) {
        return;
    }
    IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
    // TODO exploit the type name information
    IScope scope;
    if (contentAssistContext.getCurrentModel() != receiver) {
        EObject currentModel = contentAssistContext.getCurrentModel();
        if (currentModel instanceof XMemberFeatureCall && ((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver) {
            scope = filterByConcreteSyntax(expressionScope.getFeatureScope((XAbstractFeatureCall) currentModel), crossReference);
        } else {
            scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
        }
    } else {
        scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
    }
    getCrossReferenceProposalCreator().lookupCrossReference(scope, receiver, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
// System.out.printf("XbaseProposalProvider.createReceiverProposals = %d\n", System.currentTimeMillis() - time);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EObject(org.eclipse.emf.ecore.EObject) IExpressionScope(org.eclipse.xtext.xbase.typesystem.IExpressionScope) IScope(org.eclipse.xtext.scoping.IScope) StyledString(org.eclipse.jface.viewers.StyledString) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with IExpressionScope

use of org.eclipse.xtext.xbase.typesystem.IExpressionScope in project xtext-eclipse by eclipse.

the class NewFeatureNameUtil method setFeatureScopeContext.

public void setFeatureScopeContext(XExpression siblingExpression) {
    XBlockExpression containerBlock = (siblingExpression.eContainer() instanceof XBlockExpression) ? (XBlockExpression) siblingExpression.eContainer() : null;
    EObject context = siblingExpression;
    if (containerBlock != null && !containerBlock.getExpressions().isEmpty()) {
        context = containerBlock.getExpressions().get(containerBlock.getExpressions().size() - 1);
    }
    IExpressionScope expressionScope = batchTypeResolver.resolveTypes(context).getExpressionScope(context, IExpressionScope.Anchor.AFTER);
    featureCallScope = expressionScope.getFeatureScope();
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) EObject(org.eclipse.emf.ecore.EObject) IExpressionScope(org.eclipse.xtext.xbase.typesystem.IExpressionScope)

Aggregations

IExpressionScope (org.eclipse.xtext.xbase.typesystem.IExpressionScope)3 EObject (org.eclipse.emf.ecore.EObject)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 StyledString (org.eclipse.jface.viewers.StyledString)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 IScope (org.eclipse.xtext.scoping.IScope)2 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)2 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)2 JvmFeature (org.eclipse.xtext.common.types.JvmFeature)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)1 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)1 StaticFeatureDescription (org.eclipse.xtext.xbase.scoping.batch.StaticFeatureDescription)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1