From b1c9487215f830ec991c4e07b8899503f354826c Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 17 Jun 2019 16:30:39 +0300 Subject: [PATCH] Implement KTypeImpl.toString() --- .../kotlin/native/internal/KTypeImpl.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/runtime/src/main/kotlin/kotlin/native/internal/KTypeImpl.kt b/runtime/src/main/kotlin/kotlin/native/internal/KTypeImpl.kt index fb6d8db2c51..f5bc895dd7f 100644 --- a/runtime/src/main/kotlin/kotlin/native/internal/KTypeImpl.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/KTypeImpl.kt @@ -21,6 +21,40 @@ internal class KTypeImpl( override fun hashCode(): Int { return (classifier?.hashCode() ?: 0) * 31 * 31 + this.arguments.hashCode() * 31 + if (isMarkedNullable) 1 else 0 } + + override fun toString(): String { + val classifierString = when (classifier) { + is KClass<*> -> classifier.qualifiedName ?: classifier.simpleName + else -> null + } ?: return "(non-denotable type)" + + return buildString { + append(classifierString) + + if (arguments.isNotEmpty()) { + append('<') + + arguments.forEachIndexed { index, argument -> + if (index > 0) append(", ") + + if (argument.variance == null) { + append('*') + } else { + append(when (argument.variance) { + KVariance.INVARIANT -> "" + KVariance.IN -> "in " + KVariance.OUT -> "out " + }) + append(argument.type) + } + } + + append('>') + } + + if (isMarkedNullable) append('?') + } + } } internal class KTypeImplForGenerics : KType {