use yog_mirror::host::{ALL, HostMirror};
pub(super) const CLASS: &str = "YogMirrors";
fn class_of(m: &HostMirror) -> String {
super::class_name(
m.address
.rsplit(yog_ids::sep::PATH)
.next()
.unwrap_or_default(),
)
}
fn mirror(m: &HostMirror) -> String {
let mut out = format!(
"\n /** {address} (`yog_mirror::host`). */\n public static final class {class} {{\n private {class}() {{}}\n\n public static final String ADDRESS = \"{address}\";\n public static final String SPACE = \"{space}\";\n",
address = m.address,
class = class_of(m),
space = m.space,
);
for (i, f) in m.fields.iter().enumerate() {
out.push_str(&format!(
" /** Field `{}` ({:?} × {}): its index, its bit is {{@code 1L << index}}. */\n public static final int {} = {i};\n",
f.name,
f.kind,
f.count,
f.name.to_uppercase()
));
}
out.push_str(" }\n");
out
}
pub(super) fn file(package: &str) -> String {
let body: String = ALL.iter().map(|m| mirror(m)).collect();
format!(
"// Generated by yog-event-export from yog_mirror::host — don't edit.\npackage {package};\n\n/** The host's mirrors: their addresses, key spaces and fields. */\npublic final class {CLASS} {{\n private {CLASS}() {{}}\n{body}}}\n"
)
}