K/N: Use class FQN in default toString() implementation
^KT-47167
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
package kotlin
|
||||
|
||||
import kotlin.native.identityHashCode
|
||||
import kotlin.native.internal.fullName
|
||||
import kotlin.native.internal.ExportTypeInfo
|
||||
import kotlin.native.internal.GCUnsafeCall
|
||||
|
||||
@@ -41,8 +42,7 @@ public open class Any {
|
||||
* Returns a string representation of the object.
|
||||
*/
|
||||
public open fun toString(): String {
|
||||
val kClass = this::class
|
||||
val className = kClass.qualifiedName ?: kClass.simpleName ?: "<object>"
|
||||
val className = this::class.fullName ?: "<object>"
|
||||
// TODO: consider using [identityHashCode].
|
||||
val unsignedHashCode = this.hashCode().toLong() and 0xffffffffL
|
||||
val hashCodeStr = unsignedHashCode.toString(16)
|
||||
|
||||
@@ -27,20 +27,22 @@ internal class KClassImpl<T : Any>(private val typeInfo: NativePtr) : KClass<T>
|
||||
|
||||
override fun hashCode(): Int = typeInfo.hashCode()
|
||||
|
||||
override fun toString(): String {
|
||||
val relativeName = getRelativeName(typeInfo, false)
|
||||
val visibleName = if (relativeName != null) {
|
||||
val packageName = getPackageName(typeInfo, false)!!
|
||||
if (packageName.isEmpty()) relativeName else "$packageName.$relativeName"
|
||||
} else "<anonymous>"
|
||||
override fun toString(): String = "class ${fullName ?: "<anonymous>"}"
|
||||
|
||||
return "class $visibleName"
|
||||
}
|
||||
internal val fullName: String?
|
||||
get() {
|
||||
val relativeName = getRelativeName(typeInfo, false) ?: return null
|
||||
val packageName = getPackageName(typeInfo, false)!!
|
||||
return if (packageName.isEmpty()) relativeName else "$packageName.$relativeName"
|
||||
}
|
||||
|
||||
internal fun findAssociatedObjectImpl(key: KClassImpl<*>): Any? =
|
||||
findAssociatedObjectImpl(this.typeInfo, key.typeInfo)
|
||||
}
|
||||
|
||||
internal val KClass<*>.fullName: String?
|
||||
get() = (this as? KClassImpl<*>)?.fullName
|
||||
|
||||
@PublishedApi
|
||||
internal fun KClass<*>.findAssociatedObject(key: KClass<*>): Any? =
|
||||
if (this is KClassImpl<*> && key is KClassImpl<*>) {
|
||||
|
||||
Reference in New Issue
Block a user