Expand description
Kotlin code generator — a self-contained declaration model + renderer (KotlinPoet-style “spec model with raw code bodies”).
Declarations (files, classes, functions, properties, parameters, types,
annotations) are typed model values; imports and formatting derive from
the model. Statement bodies stay raw Kotlin text structured through
the indentation-aware KtCode builder.
This crate is deliberately dependency-free: it receives model values and strings, and produces source text and file paths. Consumers build the model; this crate renders it.
Structs§
- Import
Set - Per-file import collector. Maps simple name → owning FQN; first registration wins, later distinct FQNs with the same simple name render fully qualified.
- KtClass
- A class / object / enum / data / value-class declaration.
- KtCode
- A sequence of raw lines and nested blocks plus the imports its text references. Rendered with 4-space indentation per nesting level.
- KtCtor
Param - Primary-constructor parameter, optionally a
val/varproperty. - KtEnum
Entry - KtFile
- One Kotlin source file fragment: a package plus top-level declarations.
Fragments of the same package are merged by
super::file::merge_files. - KtFun
- A function declaration (top-level or member).
- KtFun
Interface - A
fun interface(SAM) declaration: exactly one abstract method. - KtParam
- A function parameter with an optional default-value expression.
- KtProperty
- A property declaration (top-level or member).
Enums§
- KtBody
- A function body.
- KtClass
Kind - The kind of class-like declaration.
- KtDecl
- A top-level (or member-level, for
Raw) declaration. - KtProperty
Value - A property’s value: no value, an initializer, or a delegate.
- KtType
- A Kotlin type reference.
- KtVis
- Visibility modifier.
Publicrenders explicitly (matching the existing generated style);Defaultrenders nothing. - Write
Kotlin Error - Errors surfaced by Kotlin emission.
Functions§
- merge_
files - Merge fragments into one
KtFileper package (sorted package order; within a package, fragments keep their emission order). Fails on a duplicate top-level declaration name within a package — a single merged file can’t hold two declarations of the same identity. - write_
files - Render and write every merged file; returns the written paths.