From 8ccbbf71ece2ad9921cb41e5e374269042dc7845 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 28 Jun 2018 19:32:32 +0200 Subject: [PATCH] Remove obsolete BuiltInFunction and mapIntrinsicFunctionSignature This is now fully covered by the JVM signature mapping, introduced in the previous commit. The change in KDeclarationContainerImpl.methodOwner is needed because primitive classes have no methods on JVM; and when we're looking for "Int.equals", we'll now look it up in the Class object for java.lang.Integer, not for the primitive int. --- .../jvm/internal/KDeclarationContainerImpl.kt | 3 +- .../reflect/jvm/internal/KFunctionImpl.kt | 1 - .../reflect/jvm/internal/RuntimeTypeMapper.kt | 43 ------------------- 3 files changed, 2 insertions(+), 45 deletions(-) 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 cdf05a88350..9d1d65eaace 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt @@ -27,6 +27,7 @@ import kotlin.jvm.internal.ClassBasedDeclarationContainer import kotlin.reflect.jvm.internal.components.RuntimeModuleData import kotlin.reflect.jvm.internal.structure.createArrayType import kotlin.reflect.jvm.internal.structure.safeClassLoader +import kotlin.reflect.jvm.internal.structure.wrapperByPrimitive internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContainer { abstract inner class Data { @@ -37,7 +38,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain } protected open val methodOwner: Class<*> - get() = jClass + get() = jClass.wrapperByPrimitive ?: jClass abstract val constructorDescriptors: Collection diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt index 8722ce17de9..ad3ac002b06 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt @@ -72,7 +72,6 @@ internal class KFunctionImpl private constructor( val methods = jvmSignature.methods return@caller AnnotationConstructorCaller(container.jClass, methods.map { it.name }, POSITIONAL_CALL, JAVA, methods) } - is BuiltInFunction -> jvmSignature.getMember(container) } when (member) { diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt index 99b51da97b0..8190f35a259 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt @@ -47,7 +47,6 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor import java.lang.reflect.Constructor import java.lang.reflect.Field -import java.lang.reflect.Member import java.lang.reflect.Method import kotlin.reflect.jvm.internal.structure.* @@ -87,16 +86,6 @@ internal sealed class JvmFunctionSignature { override fun asString(): String = methods.joinToString(separator = "", prefix = "(", postfix = ")V") { it.returnType.desc } } - - open class BuiltInFunction(private val signature: String) : JvmFunctionSignature() { - open fun getMember(container: KDeclarationContainerImpl): Member? = null - - override fun asString(): String = signature - - class Predefined(signature: String, private val member: Member) : BuiltInFunction(signature) { - override fun getMember(container: KDeclarationContainerImpl): Member = member - } - } } internal sealed class JvmPropertySignature { @@ -175,10 +164,6 @@ internal object RuntimeTypeMapper { when (function) { is DeserializedCallableMemberDescriptor -> { - mapIntrinsicFunctionSignature(function)?.let { - return it - } - val proto = function.proto if (proto is ProtoBuf.Function) { JvmProtoBufUtil.getJvmMethodSignature(proto, function.nameResolver, function.typeTable)?.let { signature -> @@ -258,34 +243,6 @@ internal object RuntimeTypeMapper { else -> descriptor.name.asString() } - private fun mapIntrinsicFunctionSignature(function: FunctionDescriptor): JvmFunctionSignature? { - val parameters = function.valueParameters - - when (function.name.asString()) { - "equals" -> if (parameters.size == 1 && KotlinBuiltIns.isNullableAny(parameters.single().type)) { - return JvmFunctionSignature.BuiltInFunction.Predefined( - "equals(Ljava/lang/Object;)Z", - Any::class.java.getDeclaredMethod("equals", Any::class.java) - ) - } - "hashCode" -> if (parameters.isEmpty()) { - return JvmFunctionSignature.BuiltInFunction.Predefined( - "hashCode()I", - Any::class.java.getDeclaredMethod("hashCode") - ) - } - "toString" -> if (parameters.isEmpty()) { - return JvmFunctionSignature.BuiltInFunction.Predefined( - "toString()Ljava/lang/String;", - Any::class.java.getDeclaredMethod("toString") - ) - } - // TODO: generalize and support other functions from built-ins - } - - return null - } - fun mapJvmClassToKotlinClassId(klass: Class<*>): ClassId { if (klass.isArray) { klass.componentType.primitiveType?.let {