Skip to content

Commit b2fa032

Browse files
authored
don't allow inheritance from Java/C# API classes (#46)
1 parent 0057aea commit b2fa032

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

generators/dotnet-oo-bindgen/src/class.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ pub(crate) fn generate(
1919
xmldoc_print(f, &class.doc, lib)
2020
})?;
2121

22-
let static_specifier = if class.is_static() { "static " } else { "" };
23-
f.writeln(&format!("public {}class {}", static_specifier, classname))?;
22+
let class_type = if class.is_static() {
23+
"static"
24+
} else {
25+
"sealed"
26+
};
27+
28+
f.writeln(&format!("public {} class {}", class_type, classname))?;
2429
if class.destructor.is_some() {
2530
f.write(": IDisposable")?;
2631
}
@@ -141,7 +146,7 @@ fn generate_destructor(
141146
f.newline()?;
142147

143148
// The IDisposable implementation
144-
f.writeln("protected virtual void Dispose(bool disposing)")?;
149+
f.writeln("private void Dispose(bool disposing)")?;
145150
blocked(f, |f| {
146151
f.writeln("if (this.disposed)")?;
147152
f.writeln(" return;")?;

generators/java-oo-bindgen/src/java/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn generate(
1414
documentation(f, |f| javadoc_print(f, &class.doc, lib))?;
1515

1616
// Class definition
17-
f.writeln(&format!("public class {}", classname))?;
17+
f.writeln(&format!("public final class {}", classname))?;
1818
if class.destructor.is_some() {
1919
f.write(" implements AutoCloseable")?;
2020
}

generators/java-oo-bindgen/src/java/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn generate(
2626
documentation(f, |f| javadoc_print(f, &set.doc, lib))?;
2727

2828
// class definition
29-
f.writeln(&format!("public class {}", set_name))?;
29+
f.writeln(&format!("public final class {}", set_name))?;
3030
blocked(f, |f| {
3131
f.writeln("// not constructable")?;
3232
f.writeln(&format!("private {}() {{}}", set_name))?;

generators/java-oo-bindgen/src/java/structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) fn generate(
3636
documentation(f, |f| javadoc_print(f, &doc, lib))?;
3737

3838
// Structure definition
39-
f.writeln(&format!("public class {}", struct_name))?;
39+
f.writeln(&format!("public final class {}", struct_name))?;
4040
blocked(f, |f| {
4141
// Write Java structure elements
4242
for el in native_struct.elements() {

0 commit comments

Comments
 (0)