jvmMain.ksp.GenerateDumper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yass2-generate-jvm Show documentation
Show all versions of yass2-generate-jvm Show documentation
Yet Another Service Solution
The newest version!
package ch.softappeal.yass2.generate.ksp
import ch.softappeal.yass2.generate.CSY
import ch.softappeal.yass2.generate.CodeWriter
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSType
internal fun CodeWriter.generateDumper(
treeConcreteClasses: List,
graphConcreteClasses: List,
) {
val classes = treeConcreteClasses + graphConcreteClasses
require(classes.size == classes.toSet().size) { "class must not be duplicated" }
checkNotEnum(classes, "must not be specified")
writeLine()
writeNestedLine("public fun createDumper(dumpValue: kotlin.text.Appendable.(value: kotlin.Any) -> kotlin.Unit): $CSY.Dumper =") {
writeNestedLine("$CSY.createDumper(") {
writeNestedLine("$CSY.dumperProperties(") {
(treeConcreteClasses + graphConcreteClasses).forEach { type ->
writeNestedLine("${type.qualifiedName}::class to listOf(") {
(type.declaration as KSClassDeclaration).getAllPropertiesNotThrowable().forEach { property ->
writeNestedLine("${type.qualifiedName}::${property.name} as kotlin.reflect.KProperty1,")
}
}
writeNestedLine("),")
}
}
writeNestedLine("),")
writeNestedLine("setOf(") {
graphConcreteClasses.forEach { type -> writeNestedLine("${type.qualifiedName}::class,") }
}
writeNestedLine("),")
writeNestedLine("dumpValue,")
}
writeNestedLine(")")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy