Skip to main content

Crate kotlin_codegen

Crate kotlin_codegen 

Source
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§

ImportSet
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.
KtCtorParam
Primary-constructor parameter, optionally a val/var property.
KtEnumEntry
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).
KtFunInterface
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.
KtClassKind
The kind of class-like declaration.
KtDecl
A top-level (or member-level, for Raw) declaration.
KtPropertyValue
A property’s value: no value, an initializer, or a delegate.
KtType
A Kotlin type reference.
KtVis
Visibility modifier. Public renders explicitly (matching the existing generated style); Default renders nothing.
WriteKotlinError
Errors surfaced by Kotlin emission.

Functions§

merge_files
Merge fragments into one KtFile per 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.