Search in sources :

Example 6 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument 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)

Example 7 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument in project kotlin by JetBrains.

the class CallBasedArgumentGenerator method generateExpression.

@Override
protected void generateExpression(int i, @NotNull ExpressionValueArgument argument) {
    ValueParameterDescriptor parameter = valueParameters.get(i);
    Type type = valueParameterTypes.get(i);
    ValueArgument valueArgument = argument.getValueArgument();
    assert valueArgument != null;
    KtExpression argumentExpression = valueArgument.getArgumentExpression();
    assert argumentExpression != null : valueArgument.asElement().getText();
    callGenerator.genValueAndPut(parameter, argumentExpression, type, i);
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) KtExpression(org.jetbrains.kotlin.psi.KtExpression) ValueParameterDescriptor(org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)

Aggregations

ValueArgument (org.jetbrains.kotlin.psi.ValueArgument)7 KtExpression (org.jetbrains.kotlin.psi.KtExpression)4 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)3 Type (org.jetbrains.org.objectweb.asm.Type)2 SmartList (com.intellij.util.SmartList)1 NotNull (org.jetbrains.annotations.NotNull)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 TypeParameterDescriptor (org.jetbrains.kotlin.descriptors.TypeParameterDescriptor)1 KtSimpleNameExpression (org.jetbrains.kotlin.psi.KtSimpleNameExpression)1 ExpressionValueArgument (org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument)1 ResolvedValueArgument (org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)1 DataFlowInfo (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)1 TypeProjection (org.jetbrains.kotlin.types.TypeProjection)1