Search in sources :

Example 1 with SpecialSignatureInfo

use of org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.SpecialSignatureInfo in project kotlin by JetBrains.

the class KotlinTypeMapper method mapSignatureWithCustomParameters.

@NotNull
public JvmMethodGenericSignature mapSignatureWithCustomParameters(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind, @NotNull List<ValueParameterDescriptor> valueParameters, boolean skipGenericSignature) {
    checkOwnerCompatibility(f);
    JvmSignatureWriter sw = skipGenericSignature || f instanceof AccessorForCallableDescriptor ? new JvmSignatureWriter() : new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
    if (f instanceof ClassConstructorDescriptor) {
        sw.writeParametersStart();
        writeAdditionalConstructorParameters((ClassConstructorDescriptor) f, sw);
        for (ValueParameterDescriptor parameter : valueParameters) {
            writeParameter(sw, parameter.getType(), f);
        }
        if (f instanceof AccessorForConstructorDescriptor) {
            writeParameter(sw, JvmMethodParameterKind.CONSTRUCTOR_MARKER, DEFAULT_CONSTRUCTOR_MARKER);
        }
        writeVoidReturn(sw);
    } else {
        CallableMemberDescriptor directMember = DescriptorUtils.getDirectMember(f);
        KotlinType thisIfNeeded = null;
        if (OwnerKind.DEFAULT_IMPLS == kind) {
            ReceiverTypeAndTypeParameters receiverTypeAndTypeParameters = TypeMapperUtilsKt.patchTypeParametersForDefaultImplMethod(directMember);
            writeFormalTypeParameters(CollectionsKt.plus(receiverTypeAndTypeParameters.getTypeParameters(), directMember.getTypeParameters()), sw);
            thisIfNeeded = receiverTypeAndTypeParameters.getReceiverType();
        } else {
            writeFormalTypeParameters(directMember.getTypeParameters(), sw);
            if (isAccessor(f) && f.getDispatchReceiverParameter() != null) {
                thisIfNeeded = ((ClassDescriptor) f.getContainingDeclaration()).getDefaultType();
            }
        }
        sw.writeParametersStart();
        if (thisIfNeeded != null) {
            writeParameter(sw, JvmMethodParameterKind.THIS, thisIfNeeded, f);
        }
        ReceiverParameterDescriptor receiverParameter = f.getExtensionReceiverParameter();
        if (receiverParameter != null) {
            writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.getType(), f);
        }
        for (ValueParameterDescriptor parameter : valueParameters) {
            boolean forceBoxing = MethodSignatureMappingKt.forceSingleValueParameterBoxing(f);
            writeParameter(sw, forceBoxing ? TypeUtils.makeNullable(parameter.getType()) : parameter.getType(), f);
        }
        sw.writeReturnType();
        mapReturnType(f, sw);
        sw.writeReturnTypeEnd();
    }
    JvmMethodGenericSignature signature = sw.makeJvmMethodSignature(mapFunctionName(f));
    if (kind != OwnerKind.DEFAULT_IMPLS) {
        SpecialSignatureInfo specialSignatureInfo = BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo(f);
        if (specialSignatureInfo != null) {
            String newGenericSignature = CodegenUtilKt.replaceValueParametersIn(specialSignatureInfo, signature.getGenericsSignature());
            return new JvmMethodGenericSignature(signature.getAsmMethod(), signature.getValueParameters(), newGenericSignature);
        }
    }
    return signature;
}
Also used : BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) JvmMethodGenericSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature) JavaCallableMemberDescriptor(org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) SpecialSignatureInfo(org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.SpecialSignatureInfo) JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 BothSignatureWriter (org.jetbrains.kotlin.codegen.signature.BothSignatureWriter)1 JvmSignatureWriter (org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter)1 SpecialSignatureInfo (org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.SpecialSignatureInfo)1 JavaCallableMemberDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor)1 JvmMethodGenericSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature)1 DeserializedCallableMemberDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)1