Search in sources :

Example 1 with OverloadResolutionResults

use of org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults in project kotlin by JetBrains.

the class CallResolver method resolveFunctionCall.

@NotNull
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(@NotNull BasicCallResolutionContext context) {
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    Call.CallType callType = context.call.getCallType();
    if (callType == Call.CallType.ARRAY_GET_METHOD || callType == Call.CallType.ARRAY_SET_METHOD) {
        Name name = callType == Call.CallType.ARRAY_GET_METHOD ? OperatorNameConventions.GET : OperatorNameConventions.SET;
        KtArrayAccessExpression arrayAccessExpression = (KtArrayAccessExpression) context.call.getCallElement();
        return computeTasksAndResolveCall(context, name, arrayAccessExpression, NewResolutionOldInference.ResolutionKind.Function.INSTANCE);
    }
    KtExpression calleeExpression = context.call.getCalleeExpression();
    if (calleeExpression instanceof KtSimpleNameExpression) {
        KtSimpleNameExpression expression = (KtSimpleNameExpression) calleeExpression;
        return computeTasksAndResolveCall(context, expression.getReferencedNameAsName(), expression, NewResolutionOldInference.ResolutionKind.Function.INSTANCE);
    } else if (calleeExpression instanceof KtConstructorCalleeExpression) {
        return (OverloadResolutionResults) resolveCallForConstructor(context, (KtConstructorCalleeExpression) calleeExpression);
    } else if (calleeExpression instanceof KtConstructorDelegationReferenceExpression) {
        KtConstructorDelegationCall delegationCall = (KtConstructorDelegationCall) context.call.getCallElement();
        DeclarationDescriptor container = context.scope.getOwnerDescriptor();
        assert container instanceof ConstructorDescriptor : "Trying to resolve JetConstructorDelegationCall not in constructor. scope.ownerDescriptor = " + container;
        return (OverloadResolutionResults) resolveConstructorDelegationCall(context, delegationCall, (KtConstructorDelegationReferenceExpression) calleeExpression, (ClassConstructorDescriptor) container);
    } else if (calleeExpression == null) {
        return checkArgumentTypesAndFail(context);
    }
    // Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
    KotlinType expectedType = NO_EXPECTED_TYPE;
    if (calleeExpression instanceof KtLambdaExpression) {
        int parameterNumber = ((KtLambdaExpression) calleeExpression).getValueParameters().size();
        List<KotlinType> parameterTypes = new ArrayList<KotlinType>(parameterNumber);
        for (int i = 0; i < parameterNumber; i++) {
            parameterTypes.add(NO_EXPECTED_TYPE);
        }
        expectedType = FunctionTypesKt.createFunctionType(builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, null, context.expectedType);
    }
    KotlinType calleeType = expressionTypingServices.safeGetType(context.scope, calleeExpression, expectedType, context.dataFlowInfo, context.trace);
    ExpressionReceiver expressionReceiver = ExpressionReceiver.Companion.create(calleeExpression, calleeType, context.trace.getBindingContext());
    Call call = new CallTransformer.CallForImplicitInvoke(context.call.getExplicitReceiver(), expressionReceiver, context.call, false);
    TracingStrategyForInvoke tracingForInvoke = new TracingStrategyForInvoke(calleeExpression, call, calleeType);
    return resolveCallForInvoke(context.replaceCall(call), tracingForInvoke);
}
Also used : OverloadResolutionResults(org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults) KotlinType(org.jetbrains.kotlin.types.KotlinType) Name(org.jetbrains.kotlin.name.Name) ExpressionReceiver(org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 Name (org.jetbrains.kotlin.name.Name)1 OverloadResolutionResults (org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults)1 ExpressionReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1