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.
This commit is contained in:
@@ -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<ConstructorDescriptor>
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 = "<init>(", 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 {
|
||||
|
||||
Reference in New Issue
Block a user