CodeBuilder
class CodeBuilder(classesToImport: MutableMap<String, String> = mutableMapOf(), functionsToImport: MutableMap<String, MutableSet<String>> = mutableMapOf(), indentDepth: Int = 0, varCounts: MutableMap<String, Int> = mutableMapOf())
A class to simplify Kotlin code generation.
This is a simple, but somewhat more Kotlinized alternative to Kotlin Poet (which is basically a Java Poet port). Kotlin code generation is still emerging it seems, and better libraries may exist in the future. Consider them before adding too much functionality to this class.
Constructors
Link copied to clipboard
constructor(classesToImport: MutableMap<String, String> = mutableMapOf(), functionsToImport: MutableMap<String, MutableSet<String>> = mutableMapOf(), indentDepth: Int = 0, varCounts: MutableMap<String, Int> = mutableMapOf())
Functions
Link copied to clipboard
Add and import for a function from a given package.
Link copied to clipboard
Add given class to import list, simple class name can then be used in the code to refer to it.
Import class or function using its fully-qualified name.
Link copied to clipboard
Creates an insertion point where some code can be added later (until writeToFile is called).
Link copied to clipboard
Link copied to clipboard
Executes given lambda with increased indent depth.
Link copied to clipboard
fun writeToFile(codeGenerator: CodeGenerator, dependencies: Dependencies, packageName: String, fileName: String)
Write generated kode to a new source file in context of KSP.