kotlin-codegen
A declaration model and renderer for generating Kotlin source code.
Declarations (files, classes, functions, properties, parameters, types,
annotations) are typed model values (KtFile, KtClass, KtFun, KtType,
…); imports and formatting derive from the model automatically via
ImportSet. Statement bodies stay raw Kotlin text, structured through the
indentation-aware Code builder rather than modeled as a full expression AST.
You build a KtFile out of typed pieces, and the renderer produces
formatted, import-complete Kotlin source text plus a file-writer that lays
the result out on disk.
Why
This crate was made for the prebindgen-jni library, which generates JNI bindings for Rust libraries. The existing kotlin-poet-rs crate was not used for Not-Invented-Here reasons and because full control over the code generator was needed.
This crate will be supported as long as prebindgen-jni is alive.
Status
Early, dependency-free, and intentionally minimal. No macros, no derive, no external crates — just a plain declaration model and a renderer.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Releasing
Publishing is automated from GitHub Actions. See RELEASING.md for the release process and CHANGELOG.md for release notes.