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)