Search in sources :

Example 1 with BothSignatureWriter

use of org.jetbrains.kotlin.codegen.signature.BothSignatureWriter 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)

Example 2 with BothSignatureWriter

use of org.jetbrains.kotlin.codegen.signature.BothSignatureWriter in project kotlin by JetBrains.

the class KotlinTypeMapper method mapAnnotationParameterSignature.

@NotNull
public JvmMethodGenericSignature mapAnnotationParameterSignature(@NotNull PropertyDescriptor descriptor) {
    JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
    sw.writeReturnType();
    mapType(descriptor.getType(), sw, TypeMappingMode.VALUE_FOR_ANNOTATION);
    sw.writeReturnTypeEnd();
    return sw.makeJvmMethodSignature(descriptor.getName().asString());
}
Also used : JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BothSignatureWriter

use of org.jetbrains.kotlin.codegen.signature.BothSignatureWriter in project kotlin by JetBrains.

the class ImplementationBodyCodegen method signature.

@NotNull
public static JvmClassSignature signature(@NotNull ClassDescriptor descriptor, @NotNull Type classAsmType, @NotNull SuperClassInfo superClassInfo, @NotNull KotlinTypeMapper typeMapper) {
    JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
    typeMapper.writeFormalTypeParameters(descriptor.getDeclaredTypeParameters(), sw);
    sw.writeSuperclass();
    if (superClassInfo.getKotlinType() == null) {
        sw.writeClassBegin(superClassInfo.getType());
        sw.writeClassEnd();
    } else {
        typeMapper.mapSupertype(superClassInfo.getKotlinType(), sw);
    }
    sw.writeSuperclassEnd();
    LinkedHashSet<String> superInterfaces = new LinkedHashSet<String>();
    Set<String> kotlinMarkerInterfaces = new LinkedHashSet<String>();
    for (KotlinType supertype : descriptor.getTypeConstructor().getSupertypes()) {
        if (isJvmInterface(supertype.getConstructor().getDeclarationDescriptor())) {
            sw.writeInterface();
            Type jvmInterfaceType = typeMapper.mapSupertype(supertype, sw);
            sw.writeInterfaceEnd();
            String jvmInterfaceInternalName = jvmInterfaceType.getInternalName();
            superInterfaces.add(jvmInterfaceInternalName);
            FqName kotlinInterfaceName = DescriptorUtils.getFqName(supertype.getConstructor().getDeclarationDescriptor()).toSafe();
            String kotlinMarkerInterfaceInternalName = KOTLIN_MARKER_INTERFACES.get(kotlinInterfaceName);
            if (kotlinMarkerInterfaceInternalName != null) {
                kotlinMarkerInterfaces.add(kotlinMarkerInterfaceInternalName);
            }
        }
    }
    for (String kotlinMarkerInterface : kotlinMarkerInterfaces) {
        sw.writeInterface();
        sw.writeAsmType(getObjectType(kotlinMarkerInterface));
        sw.writeInterfaceEnd();
    }
    superInterfaces.addAll(kotlinMarkerInterfaces);
    return new JvmClassSignature(classAsmType.getInternalName(), superClassInfo.getType().getInternalName(), new ArrayList<String>(superInterfaces), sw.makeJavaGenericSignature());
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type.getObjectType(org.jetbrains.org.objectweb.asm.Type.getObjectType) JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) FqName(org.jetbrains.kotlin.name.FqName) KotlinType(org.jetbrains.kotlin.types.KotlinType) JvmClassSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature) NotNull(org.jetbrains.annotations.NotNull) BindingContextUtils.getNotNull(org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull)

Example 4 with BothSignatureWriter

use of org.jetbrains.kotlin.codegen.signature.BothSignatureWriter in project kotlin by JetBrains.

the class KotlinTypeMapper method mapScriptSignature.

@NotNull
public JvmMethodSignature mapScriptSignature(@NotNull ScriptDescriptor script, @NotNull List<ScriptDescriptor> importedScripts) {
    JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
    sw.writeParametersStart();
    for (ScriptDescriptor importedScript : importedScripts) {
        writeParameter(sw, importedScript.getDefaultType(), /* callableDescriptor = */
        null);
    }
    for (ValueParameterDescriptor valueParameter : script.getUnsubstitutedPrimaryConstructor().getValueParameters()) {
        writeParameter(sw, valueParameter.getType(), /* callableDescriptor = */
        null);
    }
    writeVoidReturn(sw);
    return sw.makeJvmMethodSignature("<init>");
}
Also used : JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with BothSignatureWriter

use of org.jetbrains.kotlin.codegen.signature.BothSignatureWriter in project kotlin by JetBrains.

the class ClosureCodegen method generateDeclaration.

@Override
protected void generateDeclaration() {
    JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
    if (samType != null) {
        typeMapper.writeFormalTypeParameters(samType.getType().getConstructor().getParameters(), sw);
    }
    sw.writeSuperclass();
    superClassAsmType = typeMapper.mapSupertype(superClassType, sw);
    sw.writeSuperclassEnd();
    String[] superInterfaceAsmTypes = new String[superInterfaceTypes.size()];
    for (int i = 0; i < superInterfaceTypes.size(); i++) {
        KotlinType superInterfaceType = superInterfaceTypes.get(i);
        sw.writeInterface();
        superInterfaceAsmTypes[i] = typeMapper.mapSupertype(superInterfaceType, sw).getInternalName();
        sw.writeInterfaceEnd();
    }
    v.defineClass(element, state.getClassFileVersion(), ACC_FINAL | ACC_SUPER | visibilityFlag, asmType.getInternalName(), sw.makeJavaGenericSignature(), superClassAsmType.getInternalName(), superInterfaceAsmTypes);
    InlineCodegenUtil.initDefaultSourceMappingIfNeeded(context, this, state);
    v.visitSource(element.getContainingFile().getName(), null);
}
Also used : JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Aggregations

BothSignatureWriter (org.jetbrains.kotlin.codegen.signature.BothSignatureWriter)6 JvmSignatureWriter (org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter)6 NotNull (org.jetbrains.annotations.NotNull)5 KotlinType (org.jetbrains.kotlin.types.KotlinType)3 Type (org.jetbrains.org.objectweb.asm.Type)2 IElementType (com.intellij.psi.tree.IElementType)1 SpecialSignatureInfo (org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.SpecialSignatureInfo)1 JavaCallableMemberDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor)1 FqName (org.jetbrains.kotlin.name.FqName)1 BindingContextUtils.getNotNull (org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull)1 JvmClassSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature)1 JvmMethodGenericSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature)1 DeserializedCallableMemberDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)1 Type.getObjectType (org.jetbrains.org.objectweb.asm.Type.getObjectType)1