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);
}
}
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));
}
Aggregations