oo-bindgen 0.8.8

DSL-based binding geneator for C, C++, Java, and C#
Documentation
use super::doc::*;
use super::*;

pub(crate) fn generate(
    f: &mut impl Printer,
    set: &Handle<ConstantSet<Validated>>,
) -> FormattingResult<()> {
    fn get_type_as_string(value: &ConstantValue) -> &'static str {
        match value {
            ConstantValue::U8(_, _) => "UByte",
        }
    }

    fn get_value_as_string(value: &ConstantValue) -> String {
        match value {
            ConstantValue::U8(x, Representation::Hex) => format!("UByte.valueOf(0x{x:02X?})"),
        }
    }

    let set_name = set.name.camel_case();

    // Documentation
    documentation(f, |f| javadoc_print(f, &set.doc))?;

    // class definition
    f.writeln(&format!("public final class {set_name}"))?;
    blocked(f, |f| {
        f.writeln("// not constructable")?;
        f.writeln(&format!("private {set_name}() {{}}"))?;

        // Write the values
        for constant in &set.values {
            documentation(f, |f| javadoc_print(f, &constant.doc))?;
            f.writeln(&format!(
                "public static final {} {} = {};",
                get_type_as_string(&constant.value),
                constant.name.capital_snake_case(),
                get_value_as_string(&constant.value)
            ))?;
        }
        Ok(())
    })
}