[IR generator] Don't use kotlinpoet for auto-generating IR tree classes

KT-61970 Fixed
KT-61703 Fixed
This commit is contained in:
Sergej Jaskiewicz
2023-10-27 18:55:48 +02:00
committed by Space Team
parent 63e9dd588c
commit ed28923282
52 changed files with 392 additions and 646 deletions
@@ -69,7 +69,7 @@ abstract class AbstractElementPrinter<Element : AbstractElement<Element, Field>,
if (body.isNotEmpty()) {
println(" {")
print(body)
print(body.trimStart('\n'))
print("}")
}
println()
@@ -32,6 +32,10 @@ abstract class AbstractField {
open val withGetter: Boolean get() = false
open val customSetter: String? get() = null
var deprecation: Deprecated? = null
var visibility: Visibility = Visibility.PUBLIC
var fromParent: Boolean = false
open val defaultValueInImplementation: String? get() = null
@@ -35,6 +35,17 @@ abstract class AbstractFieldPrinter<Field : AbstractField>(
) {
printer.run {
printKDoc(field.kDoc)
field.deprecation?.let {
println("@Deprecated(")
withIndent {
println("message = \"", it.message, "\",")
println("replaceWith = ReplaceWith(\"", it.replaceWith.expression, "\"),")
println("level = DeprecationLevel.", it.level.name, ",")
}
println(")")
}
if (field.isVolatile) {
println("@", type<Volatile>().render())
}
@@ -50,6 +61,10 @@ abstract class AbstractFieldPrinter<Field : AbstractField>(
}
}
if (field.visibility != Visibility.PUBLIC) {
print(field.visibility.name.toLowerCaseAsciiOnly(), " ")
}
modality?.let {
print(it.name.toLowerCaseAsciiOnly(), " ")
}
@@ -68,12 +68,20 @@ class ImportCollector(currentPackage: String) {
addImport(packageName, "*")
}
fun printAllImports(printer: Appendable) {
/**
* Prints all the collected imports in alphabetical order.
*
* @return `true` if at least one import was printed, `false` if no imports were printed.
*/
fun printAllImports(printer: Appendable): Boolean {
var atLeastOneImport = false
for ((packageName, entities) in imports) {
for (entity in entities) {
atLeastOneImport = true
printer.append("import ", packageName, ".", entity, "\n")
}
}
return atLeastOneImport
}
fun addAllImports(importables: Collection<Importable>) {
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.generators.tree
enum class Visibility {
PUBLIC, PROTECTED, INTERNAL, PRIVATE
}
@@ -45,7 +45,9 @@ fun printGeneratedType(
}
appendLine("package $packageName")
appendLine()
importCollector.printAllImports(this)
if (importCollector.printAllImports(this)) {
appendLine()
}
append(stringBuilder)
}
)