Reformat typeSignatureMapping.kt file
This commit is contained in:
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* 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.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.load.kotlin
|
package org.jetbrains.kotlin.load.kotlin
|
||||||
@@ -44,7 +33,7 @@ interface JvmTypeFactory<T : Any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : Any> JvmTypeFactory<T>.boxTypeIfNeeded(possiblyPrimitiveType: T, needBoxedType: Boolean) =
|
private fun <T : Any> JvmTypeFactory<T>.boxTypeIfNeeded(possiblyPrimitiveType: T, needBoxedType: Boolean) =
|
||||||
if (needBoxedType) boxType(possiblyPrimitiveType) else possiblyPrimitiveType
|
if (needBoxedType) boxType(possiblyPrimitiveType) else possiblyPrimitiveType
|
||||||
|
|
||||||
interface TypeMappingConfiguration<out T : Any> {
|
interface TypeMappingConfiguration<out T : Any> {
|
||||||
fun commonSupertype(types: Collection<@JvmSuppressWildcards KotlinType>): KotlinType
|
fun commonSupertype(types: Collection<@JvmSuppressWildcards KotlinType>): KotlinType
|
||||||
@@ -56,21 +45,21 @@ interface TypeMappingConfiguration<out T : Any> {
|
|||||||
const val NON_EXISTENT_CLASS_NAME = "error/NonExistentClass"
|
const val NON_EXISTENT_CLASS_NAME = "error/NonExistentClass"
|
||||||
|
|
||||||
private val CONTINUATION_INTERNAL_NAME =
|
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 <T : Any> mapType(
|
fun <T : Any> mapType(
|
||||||
kotlinType: KotlinType,
|
kotlinType: KotlinType,
|
||||||
factory: JvmTypeFactory<T>,
|
factory: JvmTypeFactory<T>,
|
||||||
mode: TypeMappingMode,
|
mode: TypeMappingMode,
|
||||||
typeMappingConfiguration: TypeMappingConfiguration<T>,
|
typeMappingConfiguration: TypeMappingConfiguration<T>,
|
||||||
descriptorTypeWriter: JvmDescriptorTypeWriter<T>?,
|
descriptorTypeWriter: JvmDescriptorTypeWriter<T>?,
|
||||||
writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3
|
writeGenericType: (KotlinType, T, TypeMappingMode) -> Unit = DO_NOTHING_3
|
||||||
): T {
|
): T {
|
||||||
if (kotlinType.isSuspendFunctionType) {
|
if (kotlinType.isSuspendFunctionType) {
|
||||||
return mapType(
|
return mapType(
|
||||||
transformSuspendFunctionToRuntimeFunctionType(kotlinType),
|
transformSuspendFunctionToRuntimeFunctionType(kotlinType),
|
||||||
factory, mode, typeMappingConfiguration, descriptorTypeWriter,
|
factory, mode, typeMappingConfiguration, descriptorTypeWriter,
|
||||||
writeGenericType
|
writeGenericType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +79,14 @@ fun <T : Any> mapType(
|
|||||||
// So replace arguments with star-projections to prevent infinite recursive mapping
|
// So replace arguments with star-projections to prevent infinite recursive mapping
|
||||||
// It's not very important because such types anyway are prohibited in declarations
|
// It's not very important because such types anyway are prohibited in declarations
|
||||||
return mapType(
|
return mapType(
|
||||||
commonSupertype.replaceArgumentsWithStarProjections(),
|
commonSupertype.replaceArgumentsWithStarProjections(),
|
||||||
factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
|
factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val descriptor =
|
val descriptor =
|
||||||
constructor.declarationDescriptor
|
constructor.declarationDescriptor
|
||||||
?: throw UnsupportedOperationException("no descriptor for type constructor of " + kotlinType)
|
?: throw UnsupportedOperationException("no descriptor for type constructor of " + kotlinType)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
ErrorUtils.isError(descriptor) -> {
|
ErrorUtils.isError(descriptor) -> {
|
||||||
@@ -121,15 +111,15 @@ fun <T : Any> mapType(
|
|||||||
writeClass(arrayElementType)
|
writeClass(arrayElementType)
|
||||||
writeArrayEnd()
|
writeArrayEnd()
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
descriptorTypeWriter?.writeArrayType()
|
descriptorTypeWriter?.writeArrayType()
|
||||||
|
|
||||||
arrayElementType =
|
arrayElementType =
|
||||||
mapType(
|
mapType(
|
||||||
memberType, factory,
|
memberType, factory,
|
||||||
mode.toGenericArgumentMode(memberProjection.projectionKind),
|
mode.toGenericArgumentMode(memberProjection.projectionKind),
|
||||||
typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
|
typeMappingConfiguration, descriptorTypeWriter, writeGenericType
|
||||||
|
)
|
||||||
|
|
||||||
descriptorTypeWriter?.writeArrayEnd()
|
descriptorTypeWriter?.writeArrayEnd()
|
||||||
}
|
}
|
||||||
@@ -139,19 +129,18 @@ fun <T : Any> mapType(
|
|||||||
|
|
||||||
descriptor is ClassDescriptor -> {
|
descriptor is ClassDescriptor -> {
|
||||||
val jvmType =
|
val jvmType =
|
||||||
if (mode.isForAnnotationParameter && KotlinBuiltIns.isKClass(descriptor)) {
|
if (mode.isForAnnotationParameter && KotlinBuiltIns.isKClass(descriptor)) {
|
||||||
factory.javaLangClassType
|
factory.javaLangClassType
|
||||||
}
|
} else {
|
||||||
else {
|
typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original)
|
||||||
typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original)
|
?: run {
|
||||||
?: run {
|
// refer to enum entries by enum type in bytecode unless ASM_TYPE is written
|
||||||
// refer to enum entries by enum type in bytecode unless ASM_TYPE is written
|
val enumClassIfEnumEntry = if (descriptor.kind == ClassKind.ENUM_ENTRY)
|
||||||
val enumClassIfEnumEntry = if (descriptor.kind == ClassKind.ENUM_ENTRY)
|
descriptor.containingDeclaration as ClassDescriptor
|
||||||
descriptor.containingDeclaration as ClassDescriptor
|
else descriptor
|
||||||
else descriptor
|
factory.createObjectType(computeInternalName(enumClassIfEnumEntry.original, typeMappingConfiguration))
|
||||||
factory.createObjectType(computeInternalName(enumClassIfEnumEntry.original, typeMappingConfiguration))
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
writeGenericType(kotlinType, jvmType, mode)
|
writeGenericType(kotlinType, jvmType, mode)
|
||||||
|
|
||||||
@@ -159,8 +148,10 @@ fun <T : Any> mapType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
descriptor is TypeParameterDescriptor -> {
|
descriptor is TypeParameterDescriptor -> {
|
||||||
val type = mapType(getRepresentativeUpperBound(descriptor),
|
val type = mapType(
|
||||||
factory, mode, typeMappingConfiguration, writeGenericType = DO_NOTHING_3, descriptorTypeWriter = null)
|
getRepresentativeUpperBound(descriptor),
|
||||||
|
factory, mode, typeMappingConfiguration, writeGenericType = DO_NOTHING_3, descriptorTypeWriter = null
|
||||||
|
)
|
||||||
descriptorTypeWriter?.writeTypeVariable(descriptor.getName(), type)
|
descriptorTypeWriter?.writeTypeVariable(descriptor.getName(), type)
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
@@ -173,7 +164,7 @@ fun <T : Any> mapType(
|
|||||||
fun hasVoidReturnType(descriptor: CallableDescriptor): Boolean {
|
fun hasVoidReturnType(descriptor: CallableDescriptor): Boolean {
|
||||||
if (descriptor is ConstructorDescriptor) return true
|
if (descriptor is ConstructorDescriptor) return true
|
||||||
return KotlinBuiltIns.isUnit(descriptor.returnType!!) && !TypeUtils.isNullableType(descriptor.returnType!!)
|
return KotlinBuiltIns.isUnit(descriptor.returnType!!) && !TypeUtils.isNullableType(descriptor.returnType!!)
|
||||||
&& descriptor !is PropertyGetterDescriptor
|
&& descriptor !is PropertyGetterDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : Any> mapBuiltInType(type: KotlinType, typeFactory: JvmTypeFactory<T>, mode: TypeMappingMode): T? {
|
private fun <T : Any> mapBuiltInType(type: KotlinType, typeFactory: JvmTypeFactory<T>, mode: TypeMappingMode): T? {
|
||||||
@@ -210,8 +201,8 @@ private fun <T : Any> mapBuiltInType(type: KotlinType, typeFactory: JvmTypeFacto
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun computeInternalName(
|
fun computeInternalName(
|
||||||
klass: ClassDescriptor,
|
klass: ClassDescriptor,
|
||||||
typeMappingConfiguration: TypeMappingConfiguration<*> = TypeMappingConfigurationImpl
|
typeMappingConfiguration: TypeMappingConfiguration<*> = TypeMappingConfigurationImpl
|
||||||
): String {
|
): String {
|
||||||
val container = klass.containingDeclaration
|
val container = klass.containingDeclaration
|
||||||
|
|
||||||
@@ -222,11 +213,13 @@ fun computeInternalName(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val containerClass = container as? ClassDescriptor
|
val containerClass = container as? ClassDescriptor
|
||||||
?: throw IllegalArgumentException("Unexpected container: $container for $klass")
|
?: throw IllegalArgumentException("Unexpected container: $container for $klass")
|
||||||
|
|
||||||
val containerInternalName =
|
val containerInternalName =
|
||||||
typeMappingConfiguration.getPredefinedInternalNameForClass(containerClass) ?:
|
typeMappingConfiguration.getPredefinedInternalNameForClass(containerClass) ?: computeInternalName(
|
||||||
computeInternalName(containerClass, typeMappingConfiguration)
|
containerClass,
|
||||||
|
typeMappingConfiguration
|
||||||
|
)
|
||||||
return containerInternalName + "$" + name
|
return containerInternalName + "$" + name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user