diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt index 0c8683bd689..1c950db948f 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.load.kotlin @@ -44,7 +33,7 @@ interface JvmTypeFactory { } private fun JvmTypeFactory.boxTypeIfNeeded(possiblyPrimitiveType: T, needBoxedType: Boolean) = - if (needBoxedType) boxType(possiblyPrimitiveType) else possiblyPrimitiveType + if (needBoxedType) boxType(possiblyPrimitiveType) else possiblyPrimitiveType interface TypeMappingConfiguration { fun commonSupertype(types: Collection<@JvmSuppressWildcards KotlinType>): KotlinType @@ -56,21 +45,21 @@ interface TypeMappingConfiguration { const val NON_EXISTENT_CLASS_NAME = "error/NonExistentClass" private val CONTINUATION_INTERNAL_NAME = - JvmClassName.byClassId(ClassId.topLevel(DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME)).internalName + JvmClassName.byClassId(ClassId.topLevel(DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME)).internalName fun mapType( - kotlinType: KotlinType, - factory: JvmTypeFactory, - mode: TypeMappingMode, - typeMappingConfiguration: TypeMappingConfiguration, - descriptorTypeWriter: JvmDescriptorTypeWriter?, - writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3 + kotlinType: KotlinType, + factory: JvmTypeFactory, + mode: TypeMappingMode, + typeMappingConfiguration: TypeMappingConfiguration, + descriptorTypeWriter: JvmDescriptorTypeWriter?, + writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3 ): T { if (kotlinType.isSuspendFunctionType) { return mapType( - transformSuspendFunctionToRuntimeFunctionType(kotlinType), - factory, mode, typeMappingConfiguration, descriptorTypeWriter, - writeGenericType + transformSuspendFunctionToRuntimeFunctionType(kotlinType), + factory, mode, typeMappingConfiguration, descriptorTypeWriter, + writeGenericType ) } @@ -90,13 +79,14 @@ fun mapType( // So replace arguments with star-projections to prevent infinite recursive mapping // It's not very important because such types anyway are prohibited in declarations return mapType( - commonSupertype.replaceArgumentsWithStarProjections(), - factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType) + commonSupertype.replaceArgumentsWithStarProjections(), + factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType + ) } val descriptor = - constructor.declarationDescriptor - ?: throw UnsupportedOperationException("no descriptor for type constructor of " + kotlinType) + constructor.declarationDescriptor + ?: throw UnsupportedOperationException("no descriptor for type constructor of " + kotlinType) when { ErrorUtils.isError(descriptor) -> { @@ -121,15 +111,15 @@ fun mapType( writeClass(arrayElementType) writeArrayEnd() } - } - else { + } else { descriptorTypeWriter?.writeArrayType() arrayElementType = mapType( - memberType, factory, - mode.toGenericArgumentMode(memberProjection.projectionKind), - typeMappingConfiguration, descriptorTypeWriter, writeGenericType) + memberType, factory, + mode.toGenericArgumentMode(memberProjection.projectionKind), + typeMappingConfiguration, descriptorTypeWriter, writeGenericType + ) descriptorTypeWriter?.writeArrayEnd() } @@ -139,19 +129,18 @@ fun mapType( descriptor is ClassDescriptor -> { val jvmType = - if (mode.isForAnnotationParameter && KotlinBuiltIns.isKClass(descriptor)) { - factory.javaLangClassType - } - else { - typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original) - ?: run { - // refer to enum entries by enum type in bytecode unless ASM_TYPE is written - val enumClassIfEnumEntry = if (descriptor.kind == ClassKind.ENUM_ENTRY) - descriptor.containingDeclaration as ClassDescriptor - else descriptor - factory.createObjectType(computeInternalName(enumClassIfEnumEntry.original, typeMappingConfiguration)) - } - } + if (mode.isForAnnotationParameter && KotlinBuiltIns.isKClass(descriptor)) { + factory.javaLangClassType + } else { + typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original) + ?: run { + // refer to enum entries by enum type in bytecode unless ASM_TYPE is written + val enumClassIfEnumEntry = if (descriptor.kind == ClassKind.ENUM_ENTRY) + descriptor.containingDeclaration as ClassDescriptor + else descriptor + factory.createObjectType(computeInternalName(enumClassIfEnumEntry.original, typeMappingConfiguration)) + } + } writeGenericType(kotlinType, jvmType, mode) @@ -159,8 +148,10 @@ fun mapType( } descriptor is TypeParameterDescriptor -> { - val type = mapType(getRepresentativeUpperBound(descriptor), - factory, mode, typeMappingConfiguration, writeGenericType = DO_NOTHING_3, descriptorTypeWriter = null) + val type = mapType( + getRepresentativeUpperBound(descriptor), + factory, mode, typeMappingConfiguration, writeGenericType = DO_NOTHING_3, descriptorTypeWriter = null + ) descriptorTypeWriter?.writeTypeVariable(descriptor.getName(), type) return type } @@ -173,7 +164,7 @@ fun mapType( fun hasVoidReturnType(descriptor: CallableDescriptor): Boolean { if (descriptor is ConstructorDescriptor) return true return KotlinBuiltIns.isUnit(descriptor.returnType!!) && !TypeUtils.isNullableType(descriptor.returnType!!) - && descriptor !is PropertyGetterDescriptor + && descriptor !is PropertyGetterDescriptor } private fun mapBuiltInType(type: KotlinType, typeFactory: JvmTypeFactory, mode: TypeMappingMode): T? { @@ -210,8 +201,8 @@ private fun mapBuiltInType(type: KotlinType, typeFactory: JvmTypeFacto } fun computeInternalName( - klass: ClassDescriptor, - typeMappingConfiguration: TypeMappingConfiguration<*> = TypeMappingConfigurationImpl + klass: ClassDescriptor, + typeMappingConfiguration: TypeMappingConfiguration<*> = TypeMappingConfigurationImpl ): String { val container = klass.containingDeclaration @@ -222,11 +213,13 @@ fun computeInternalName( } val containerClass = container as? ClassDescriptor - ?: throw IllegalArgumentException("Unexpected container: $container for $klass") + ?: throw IllegalArgumentException("Unexpected container: $container for $klass") val containerInternalName = - typeMappingConfiguration.getPredefinedInternalNameForClass(containerClass) ?: - computeInternalName(containerClass, typeMappingConfiguration) + typeMappingConfiguration.getPredefinedInternalNameForClass(containerClass) ?: computeInternalName( + containerClass, + typeMappingConfiguration + ) return containerInternalName + "$" + name }