use super::unreal::annotated_declarations;
use super::{Check, CheckContext, DiagnosticCode};
pub struct UeGenerateBody;
impl Check for UeGenerateBody {
const CODES: &'static [DiagnosticCode] = &[DiagnosticCode::UeGenerateBody];
fn check(context: &mut CheckContext<'_>) {
for annotated in annotated_declarations(context, &["UCLASS", "USTRUCT", "UINTERFACE"]) {
if !annotated.has_a_class_body {
continue;
}
let Some((start, end)) = annotated.body_in_the_file else {
continue;
};
let Some(body) = context.written.get(start..end) else {
continue;
};
let generated = [
"GENERATED_BODY",
"GENERATED_UCLASS_BODY",
"GENERATED_USTRUCT_BODY",
"GENERATED_IINTERFACE_BODY",
]
.iter()
.any(|spelling| body.contains(spelling));
if generated {
continue;
}
let name = annotated.name.clone();
context.add_in_the_file(
DiagnosticCode::UeGenerateBody,
annotated.name_in_the_file,
name.clone(),
format!(
"`{name}` writes `{}` and no `GENERATED_BODY()` — the macro is what the engine's build replaces \
with the reflection data, so the class does not compile without it",
annotated.macro_name
),
);
}
}
}