Skip to content

Commit 1bda87b

Browse files
committed
Mention final status in class docs
1 parent adfd7fb commit 1bda87b

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

godot-codegen/src/generator/classes.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ struct GeneratedClassModule {
7373
is_pub_sidecar: bool,
7474
}
7575

76+
struct Construction {
77+
constructor: TokenStream,
78+
construct_doc: &'static str,
79+
final_doc: Option<&'static str>,
80+
godot_default_impl: TokenStream,
81+
}
82+
7683
fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClass {
7784
let class_name = class.name();
7885

@@ -90,8 +97,16 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
9097
None => (quote! { crate::obj::NoBase }, None),
9198
};
9299

93-
let (constructor, construct_doc, godot_default_impl) = make_constructor_and_default(class, ctx);
94-
let construct_doc = construct_doc.replace("Self", &class_name.rust_ty.to_string());
100+
let Construction {
101+
constructor,
102+
construct_doc,
103+
final_doc,
104+
godot_default_impl,
105+
} = make_constructor_and_default(class, ctx);
106+
107+
let mut extended_class_doc = construct_doc.replace("Self", &class_name.rust_ty.to_string());
108+
extended_class_doc.push_str(final_doc.unwrap_or_default());
109+
95110
let api_level = class.api_level;
96111
let init_level = api_level.to_init_level();
97112

@@ -194,7 +209,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
194209
use super::*;
195210

196211
#[doc = #class_doc]
197-
#[doc = #construct_doc]
212+
#[doc = #extended_class_doc]
198213
#cfg_attributes
199214
#[derive(Debug)]
200215
#[repr(C)]
@@ -386,10 +401,7 @@ fn make_class_module_file(classes_and_modules: Vec<GeneratedClassModule>) -> Tok
386401
}
387402
}
388403

389-
fn make_constructor_and_default(
390-
class: &Class,
391-
ctx: &Context,
392-
) -> (TokenStream, &'static str, TokenStream) {
404+
fn make_constructor_and_default(class: &Class, ctx: &Context) -> Construction {
393405
let class_name = class.name();
394406

395407
let godot_class_stringname = make_string_name(&class_name.godot_ty);
@@ -437,6 +449,15 @@ fn make_constructor_and_default(
437449
has_godot_default_impl = true;
438450
}
439451

452+
let final_doc = if class.is_final {
453+
Some(
454+
"\n\n# Final class\n\n\
455+
This class is _final_, meaning you cannot inherit from it.",
456+
)
457+
} else {
458+
None
459+
};
460+
440461
let godot_default_impl = if has_godot_default_impl {
441462
let class_name = &class.name().rust_ty;
442463
quote! {
@@ -450,7 +471,12 @@ fn make_constructor_and_default(
450471
TokenStream::new()
451472
};
452473

453-
(constructor, construct_doc, godot_default_impl)
474+
Construction {
475+
constructor,
476+
construct_doc,
477+
final_doc,
478+
godot_default_impl,
479+
}
454480
}
455481

456482
fn make_deref_impl(class_name: &TyName, base_ty: &TokenStream) -> TokenStream {

0 commit comments

Comments
 (0)