kotlin-codegen 0.2.0

A declaration model and renderer for generating Kotlin source code
Documentation
//! Expression value positions in the declaration model.

use super::code::KtCode;

/// A property's value: no value, an initializer, or a delegate.
///
/// Replaces the old two-`Option<String>` fields — a sum, so the illegal
/// state (both set at once) is unrepresentable.
#[derive(Clone, Debug, Default)]
pub enum KtPropertyValue {
    /// No value — an abstract property, or one with only accessors.
    #[default]
    None,
    /// `val x = <expr>`.
    Initializer(KtCode),
    /// `val x by <expr>` (e.g. `lazy { … }`).
    Delegate(KtCode),
}

impl KtPropertyValue {
    pub fn collect_imports(&self, sink: &mut Vec<String>) {
        match self {
            KtPropertyValue::None => {}
            KtPropertyValue::Initializer(c) | KtPropertyValue::Delegate(c) => {
                c.collect_imports(sink)
            }
        }
    }
}