[WASM] Add hashCode, equals and toString to KClass and KType implementations

This commit is contained in:
Igor Yakovlev
2021-11-04 19:10:17 +01:00
committed by TeamCityServer
parent ee7f4c7278
commit ec9fcce1bc
2 changed files with 26 additions and 1 deletions
@@ -45,4 +45,6 @@ internal class KClassImpl<T : Any>(private val typeData: TypeInfoData) : KClass<
(this === other) || (other is KClassImpl<*> && other.typeData.isInterface == typeData.isInterface && other.typeData.typeId == typeData.typeId)
override fun hashCode(): Int = typeData.typeId
override fun toString(): String = "class $qualifiedName"
}
@@ -11,4 +11,27 @@ internal class KTypeImpl(
override val classifier: KClassifier?,
override val arguments: List<KTypeProjection>,
override val isMarkedNullable: Boolean
) : KType
) : KType {
override fun equals(other: Any?): Boolean =
other is KTypeImpl &&
classifier == other.classifier && arguments == other.arguments && isMarkedNullable == other.isMarkedNullable
override fun hashCode(): Int =
(classifier.hashCode() * 31 + arguments.hashCode()) * 31 + isMarkedNullable.hashCode()
override fun toString(): String {
val kClass = (classifier as? KClass<*>)
val classifierName = when {
kClass == null -> classifier.toString()
kClass.simpleName != null -> kClass.simpleName
else -> "(non-denotable type)"
}
val args =
if (arguments.isEmpty()) ""
else arguments.joinToString(", ", "<", ">")
val nullable = if (isMarkedNullable) "?" else ""
return classifierName + args + nullable
}
}