Search in sources :

Example 11 with JvmMethodParameterSignature

use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature 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

JvmMethodParameterSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature)11 JvmMethodParameterKind (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind)5 KotlinType (org.jetbrains.kotlin.types.KotlinType)5 NotNull (org.jetbrains.annotations.NotNull)3 TypeAliasConstructorDescriptor (org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor)2 BindingContextUtils.getNotNull (org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull)2 Type (org.jetbrains.org.objectweb.asm.Type)2 ArrayList (java.util.ArrayList)1 AnnotatedWithOnlyTargetedAnnotations (org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 KotlinTypeMapper (org.jetbrains.kotlin.codegen.state.KotlinTypeMapper)1 Annotated (org.jetbrains.kotlin.descriptors.annotations.Annotated)1 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)1 SamConstructorDescriptor (org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor)1 DefaultValueArgument (org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument)1 ResolvedValueArgument (org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)1 JvmMethodGenericSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature)1 JvmMethodSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature)1 Type.getObjectType (org.jetbrains.org.objectweb.asm.Type.getObjectType)1 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)1