Search in sources :

Example 1 with StaticExtensionFeatureDescriptionWithImplicitFirstArgument

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

the class XbaseProposalProvider method completeXMemberFeatureCall_Feature.

@Override
public void completeXMemberFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model instanceof XMemberFeatureCall) {
        XExpression memberCallTarget = ((XMemberFeatureCall) model).getMemberCallTarget();
        IResolvedTypes resolvedTypes = typeResolver.resolveTypes(memberCallTarget);
        LightweightTypeReference memberCallTargetType = resolvedTypes.getActualType(memberCallTarget);
        Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(model, input -> {
            if (input instanceof JvmOperation && input.isStatic()) {
                List<JvmFormalParameter> parameters = ((JvmOperation) input).getParameters();
                if (parameters.size() > 0) {
                    JvmFormalParameter firstParam = parameters.get(0);
                    JvmTypeReference parameterType = firstParam.getParameterType();
                    if (parameterType != null) {
                        LightweightTypeReference lightweightTypeReference = memberCallTargetType.getOwner().toLightweightTypeReference(parameterType);
                        if (lightweightTypeReference != null) {
                            return memberCallTargetType.isAssignableFrom(lightweightTypeReference);
                        }
                    }
                }
            }
            return false;
        });
        // Create StaticExtensionFeatureDescriptionWithImplicitFirstArgument 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 StaticExtensionFeatureDescriptionWithImplicitFirstArgument(qualifiedName, feature, memberCallTarget, memberCallTargetType, 0, true);
        });
        // Scope for all static features
        IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
        proposeFavoriteStaticFeatures(model, context, acceptor, staticMemberScope);
        // Regular proposals
        createReceiverProposals(((XMemberFeatureCall) model).getMemberCallTarget(), (CrossReference) assignment.getTerminal(), context, acceptor);
    } else if (model instanceof XAssignment) {
        createReceiverProposals(((XAssignment) model).getAssignable(), (CrossReference) assignment.getTerminal(), context, acceptor);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StaticExtensionFeatureDescriptionWithImplicitFirstArgument(org.eclipse.xtext.xbase.scoping.batch.StaticExtensionFeatureDescriptionWithImplicitFirstArgument) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) IScope(org.eclipse.xtext.scoping.IScope) CrossReference(org.eclipse.xtext.CrossReference) XExpression(org.eclipse.xtext.xbase.XExpression) XAssignment(org.eclipse.xtext.xbase.XAssignment)

Aggregations

CrossReference (org.eclipse.xtext.CrossReference)1 JvmFeature (org.eclipse.xtext.common.types.JvmFeature)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)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 XAssignment (org.eclipse.xtext.xbase.XAssignment)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)1 StaticExtensionFeatureDescriptionWithImplicitFirstArgument (org.eclipse.xtext.xbase.scoping.batch.StaticExtensionFeatureDescriptionWithImplicitFirstArgument)1 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1