@@ -16,7 +16,7 @@ pub(crate) fn generate(
1616
1717 // Class definition
1818 f. writeln ( & format ! ( "public final class {}" , classname) ) ?;
19- if class. is_manual_destruction ( ) {
19+ if matches ! ( class. destruction_mode , DestructionMode :: Dispose ) {
2020 f. write ( " implements AutoCloseable" ) ?;
2121 }
2222
@@ -39,7 +39,7 @@ pub(crate) fn generate(
3939 }
4040
4141 if let Some ( destructor) = & class. destructor {
42- generate_destructor ( f, destructor, class. is_manual_destruction ( ) , lib) ?;
42+ generate_destructor ( f, destructor, & class. destruction_mode , lib) ?;
4343 f. newline ( ) ?;
4444 }
4545
@@ -145,10 +145,10 @@ fn generate_constructor(
145145fn generate_destructor (
146146 f : & mut dyn Printer ,
147147 destructor : & NativeFunctionHandle ,
148- is_manual_destruction : bool ,
148+ destruction_mode : & DestructionMode ,
149149 lib : & Library ,
150150) -> FormattingResult < ( ) > {
151- if is_manual_destruction {
151+ if destruction_mode . is_manual_destruction ( ) {
152152 documentation ( f, |f| {
153153 // Print top-level documentation
154154 javadoc_print ( f, & destructor. doc , lib) ?;
@@ -164,12 +164,18 @@ fn generate_destructor(
164164 } ) ?;
165165 }
166166
167- if is_manual_destruction {
168- // AutoCloseable implementation
169- f. writeln ( "@Override" ) ?;
170- f. writeln ( "public void close()" ) ?;
171- } else {
172- f. writeln ( "private void close()" ) ?;
167+ match destruction_mode {
168+ DestructionMode :: Automatic => {
169+ f. writeln ( "private void close()" ) ?;
170+ }
171+ DestructionMode :: Custom ( name) => {
172+ f. writeln ( & format ! ( "public void {}()" , name. to_mixed_case( ) ) ) ?;
173+ }
174+ DestructionMode :: Dispose => {
175+ // AutoCloseable implementation
176+ f. writeln ( "@Override" ) ?;
177+ f. writeln ( "public void close()" ) ?;
178+ }
173179 }
174180
175181 blocked ( f, |f| {
@@ -186,10 +192,16 @@ fn generate_destructor(
186192
187193 f. newline ( ) ?;
188194
189- // Dispose method
195+ // Finalizer method
190196 f. writeln ( "@Override" ) ?;
191197 f. writeln ( "public void finalize()" ) ?;
192- blocked ( f, |f| f. writeln ( "this.close();" ) )
198+ blocked ( f, |f| {
199+ if let DestructionMode :: Custom ( name) = destruction_mode {
200+ f. writeln ( & format ! ( "this.{}();" , name. to_mixed_case( ) ) )
201+ } else {
202+ f. writeln ( "this.close();" )
203+ }
204+ } )
193205}
194206
195207fn generate_method ( f : & mut dyn Printer , method : & Method , lib : & Library ) -> FormattingResult < ( ) > {
0 commit comments