Search in sources :

Example 6 with ResolvedValueArgument

use of org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument in project kotlin by JetBrains.

the class CodegenAnnotatingVisitor method checkSamCall.

private void checkSamCall(@NotNull KtCallElement expression) {
    ResolvedCall<?> call = CallUtilKt.getResolvedCall(expression, bindingContext);
    if (call == null)
        return;
    CallableDescriptor descriptor = call.getResultingDescriptor();
    if (!(descriptor instanceof FunctionDescriptor))
        return;
    recordSamConstructorIfNeeded(expression, call);
    FunctionDescriptor original = SamCodegenUtil.getOriginalIfSamAdapter((FunctionDescriptor) descriptor);
    if (original == null)
        return;
    List<ResolvedValueArgument> valueArguments = call.getValueArgumentsByIndex();
    if (valueArguments == null)
        return;
    for (ValueParameterDescriptor valueParameter : original.getValueParameters()) {
        SamType samType = SamType.create(TypeMapperUtilsKt.removeExternalProjections(valueParameter.getType()));
        if (samType == null)
            continue;
        ResolvedValueArgument resolvedValueArgument = valueArguments.get(valueParameter.getIndex());
        assert resolvedValueArgument instanceof ExpressionValueArgument : resolvedValueArgument;
        ValueArgument valueArgument = ((ExpressionValueArgument) resolvedValueArgument).getValueArgument();
        assert valueArgument != null;
        KtExpression argumentExpression = valueArgument.getArgumentExpression();
        assert argumentExpression != null : valueArgument.asElement().getText();
        bindingTrace.record(CodegenBinding.SAM_VALUE, argumentExpression, samType);
    }
}
Also used : ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument) ExpressionValueArgument(org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument) ExpressionValueArgument(org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument) ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)

Example 7 with ResolvedValueArgument

use of org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument in project kotlin by JetBrains.

the class ArrayAccessTranslator method contextWithValueParameterAliasInArrayGetAccess.

// this is hack for a[b]++ -> a.set(b, a.get(b) + 1). Frontend generate fake expression for a.get(b) + 1.
@NotNull
private TranslationContext contextWithValueParameterAliasInArrayGetAccess(@NotNull JsExpression toSetTo) {
    ResolvedCall<FunctionDescriptor> resolvedCall = BindingUtils.getResolvedCallForArrayAccess(bindingContext(), expression, /*isGetter = */
    false);
    List<ResolvedValueArgument> arguments = resolvedCall.getValueArgumentsByIndex();
    if (arguments == null) {
        throw new IllegalStateException("Failed to arrange value arguments by index: " + resolvedCall.getResultingDescriptor());
    }
    ResolvedValueArgument lastArgument = arguments.get(arguments.size() - 1);
    assert lastArgument instanceof ExpressionValueArgument : "Last argument of array-like setter must be ExpressionValueArgument: " + lastArgument;
    ValueArgument valueArgument = ((ExpressionValueArgument) lastArgument).getValueArgument();
    assert valueArgument != null;
    KtExpression element = valueArgument.getArgumentExpression();
    return context().innerContextWithAliasesForExpressions(Collections.singletonMap(element, toSetTo));
}
Also used : ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument) ExpressionValueArgument(org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument) ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) ExpressionValueArgument(org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument) ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument) KtExpression(org.jetbrains.kotlin.psi.KtExpression) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResolvedValueArgument (org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)7 ExpressionValueArgument (org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument)5 KtExpression (org.jetbrains.kotlin.psi.KtExpression)2 DefaultValueArgument (org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument)2 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 TypeAliasConstructorDescriptor (org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor)1 SamConstructorDescriptor (org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor)1 ValueArgument (org.jetbrains.kotlin.psi.ValueArgument)1 DelegatingResolvedCall (org.jetbrains.kotlin.resolve.calls.model.DelegatingResolvedCall)1 ResolvedCall (org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)1 JvmMethodParameterKind (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind)1 JvmMethodParameterSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature)1 ReceiverValue (org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue)1 Type (org.jetbrains.org.objectweb.asm.Type)1 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)1