From 82d38c5cb0bc577b12b0416eeef47773dfffa1c3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 5 Jan 2021 22:24:59 +0600 Subject: [PATCH] update algorithm --- tgbotapi.core/src/jvmTest/kotlin/Temporal.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tgbotapi.core/src/jvmTest/kotlin/Temporal.kt b/tgbotapi.core/src/jvmTest/kotlin/Temporal.kt index 70ba32f659..a219ecc5cf 100644 --- a/tgbotapi.core/src/jvmTest/kotlin/Temporal.kt +++ b/tgbotapi.core/src/jvmTest/kotlin/Temporal.kt @@ -23,7 +23,12 @@ fun printlnInstanceSubclassesFuns(kclass: KClass<*>) { fun printlnInstancesSubclassesFuns(kclass: KClass<*>, subclasses: Set>): List> { return subclasses.map { subclass -> - "${subclass.qualifiedName}" to "inline fun ${kclass.simpleName}.as${subclass.simpleName}(): ${subclass.simpleName}? = this as? ${subclass.simpleName}" + val typeUpperBounds = subclass.typeParameters.map { it.upperBounds.first() } + val imports = "import ${subclass.qualifiedName}" + if (typeUpperBounds.isEmpty()) "" else typeUpperBounds.joinToString("\nimport ", "\nimport ") + val subtype = "${subclass.simpleName}${if (typeUpperBounds.isEmpty()) "" else "<${typeUpperBounds.joinToString() { (it.classifier as KClass<*>).simpleName!! }}>"}" + val code = "inline fun ${kclass.simpleName}.as${subclass.simpleName}(): $subtype? = this as? $subtype\n" + + "inline fun ${kclass.simpleName}.require${subclass.simpleName}(): $subtype = this as $subtype" + imports to code } } @@ -254,7 +259,7 @@ fun main() { val importsToFuns = result.keys.flatMap { printlnInstancesSubclassesFuns(it, result.getValue(it)) } - importsToFuns.forEach { println("import ${it.first}") } + importsToFuns.forEach { println(it.first) } println() importsToFuns.forEach { println(it.second) } // printlnInstanceSubclassesFuns(Message::class)