diff --git a/core/descriptors.runtime/src/org/jetbrains/kotlin/descriptors/runtime/structure/reflectClassUtil.kt b/core/descriptors.runtime/src/org/jetbrains/kotlin/descriptors/runtime/structure/reflectClassUtil.kt index fba5e29b020..76eec25e191 100644 --- a/core/descriptors.runtime/src/org/jetbrains/kotlin/descriptors/runtime/structure/reflectClassUtil.kt +++ b/core/descriptors.runtime/src/org/jetbrains/kotlin/descriptors/runtime/structure/reflectClassUtil.kt @@ -67,16 +67,23 @@ val Class<*>.classId: ClassId } val Class<*>.desc: String - get() { - if (this == Void.TYPE) return "V" - // This is a clever exploitation of a format returned by Class.getName(): for arrays, it's almost an internal name, - // but with '.' instead of '/' - return createArrayType().name.substring(1).replace('.', '/') + get() = when { + isPrimitive -> when (name) { + "boolean" -> "Z" + "char" -> "C" + "byte" -> "B" + "short" -> "S" + "int" -> "I" + "float" -> "F" + "long" -> "J" + "double" -> "D" + "void" -> "V" + else -> throw IllegalArgumentException("Unsupported primitive type: $this") + } + isArray -> name.replace('.', '/') + else -> "L${name.replace('.', '/')};" } -fun Class<*>.createArrayType(): Class<*> = - Array.newInstance(this, 0)::class.java - /** * @return all arguments of a parameterized type, including those of outer classes in case this type represents an inner generic. * The returned list starts with the arguments to the innermost class, then continues with those of its outer class, and so on. diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt index d83e7387884..35d14c74401 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt @@ -19,7 +19,6 @@ package kotlin.reflect.jvm.internal import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.runtime.components.RuntimeModuleData import org.jetbrains.kotlin.descriptors.runtime.components.tryLoadClass -import org.jetbrains.kotlin.descriptors.runtime.structure.createArrayType import org.jetbrains.kotlin.descriptors.runtime.structure.safeClassLoader import org.jetbrains.kotlin.descriptors.runtime.structure.wrapperByPrimitive import org.jetbrains.kotlin.load.java.JvmAbi diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTypeImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTypeImpl.kt index 49666340603..5dd3fe793d4 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTypeImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KTypeImpl.kt @@ -19,7 +19,6 @@ package kotlin.reflect.jvm.internal import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.runtime.structure.createArrayType import org.jetbrains.kotlin.descriptors.runtime.structure.parameterizedTypeArguments import org.jetbrains.kotlin.descriptors.runtime.structure.primitiveByWrapper import org.jetbrains.kotlin.types.KotlinType diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/util.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/util.kt index cda72d58eb5..cf7dc541715 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/util.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/util.kt @@ -101,6 +101,9 @@ private fun loadClass(classLoader: ClassLoader, packageName: String, className: return classLoader.tryLoadClass(fqName) } +internal fun Class<*>.createArrayType(): Class<*> = + java.lang.reflect.Array.newInstance(this, 0)::class.java + internal fun DescriptorVisibility.toKVisibility(): KVisibility? = when (this) { DescriptorVisibilities.PUBLIC -> KVisibility.PUBLIC