Search in sources :

Example 1 with DefaultValueArgument

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

the class InlineChecker method check.

@Override
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
    KtExpression expression = resolvedCall.getCall().getCalleeExpression();
    if (expression == null) {
        return;
    }
    //checking that only invoke or inlinable extension called on function parameter
    CallableDescriptor targetDescriptor = resolvedCall.getResultingDescriptor();
    checkCallWithReceiver(context, targetDescriptor, resolvedCall.getDispatchReceiver(), expression);
    checkCallWithReceiver(context, targetDescriptor, resolvedCall.getExtensionReceiver(), expression);
    if (inlinableParameters.contains(targetDescriptor)) {
        if (!isInsideCall(expression)) {
            context.getTrace().report(USAGE_IS_NOT_INLINABLE.on(expression, expression, descriptor));
        }
    }
    for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : resolvedCall.getValueArguments().entrySet()) {
        ResolvedValueArgument value = entry.getValue();
        ValueParameterDescriptor valueDescriptor = entry.getKey();
        if (!(value instanceof DefaultValueArgument)) {
            for (ValueArgument argument : value.getArguments()) {
                checkValueParameter(context, targetDescriptor, argument, valueDescriptor);
            }
        }
    }
    checkVisibilityAndAccess(targetDescriptor, expression, context);
    checkRecursion(context, targetDescriptor, expression);
}
Also used : ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument) ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument) DefaultValueArgument(org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument) DefaultValueArgument(org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument) Map(java.util.Map)

Example 2 with DefaultValueArgument

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

the class KotlinTypeMapper method writeSuperConstructorCallParameters.

private void writeSuperConstructorCallParameters(@NotNull JvmSignatureWriter sw, @NotNull ClassConstructorDescriptor descriptor, @NotNull ResolvedCall<ConstructorDescriptor> superCall, boolean hasOuter) {
    ConstructorDescriptor superDescriptor = SamCodegenUtil.resolveSamAdapter(superCall.getResultingDescriptor());
    List<ResolvedValueArgument> valueArguments = superCall.getValueArgumentsByIndex();
    assert valueArguments != null : "Failed to arrange value arguments by index: " + superDescriptor;
    List<JvmMethodParameterSignature> parameters = mapSignatureSkipGeneric(superDescriptor.getOriginal()).getValueParameters();
    int params = parameters.size();
    int args = valueArguments.size();
    // Mapped parameters should consist of captured values plus all of valueArguments
    assert params >= args : String.format("Incorrect number of mapped parameters vs arguments: %d < %d for %s", params, args, descriptor);
    // Include all captured values, i.e. those parameters for which there are no resolved value arguments
    for (int i = 0; i < params - args; i++) {
        JvmMethodParameterSignature parameter = parameters.get(i);
        JvmMethodParameterKind kind = parameter.getKind();
        if (kind == JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL)
            continue;
        if (hasOuter && kind == JvmMethodParameterKind.OUTER)
            continue;
        writeParameter(sw, JvmMethodParameterKind.SUPER_CALL_PARAM, parameter.getAsmType());
    }
    if (isAnonymousObject(descriptor.getContainingDeclaration())) {
        // For anonymous objects, also add all real non-default value arguments passed to the super constructor
        for (int i = 0; i < args; i++) {
            ResolvedValueArgument valueArgument = valueArguments.get(i);
            JvmMethodParameterSignature parameter = parameters.get(params - args + i);
            if (!(valueArgument instanceof DefaultValueArgument)) {
                writeParameter(sw, JvmMethodParameterKind.SUPER_CALL_PARAM, parameter.getAsmType());
            }
        }
    }
}
Also used : ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument) JvmMethodParameterSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature) JvmMethodParameterKind(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind) TypeAliasConstructorDescriptor(org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor) DefaultValueArgument(org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument)

Aggregations

DefaultValueArgument (org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument)2 ResolvedValueArgument (org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)2 Map (java.util.Map)1 TypeAliasConstructorDescriptor (org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor)1 JvmMethodParameterKind (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind)1 JvmMethodParameterSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature)1