@@ -124,39 +124,25 @@ impl Language for Kotlin {
124
124
writeln ! ( w, "@JvmInline" ) ?;
125
125
writeln ! ( w, "value class {}{}(" , self . prefix, ty. id. renamed) ?;
126
126
127
- if ty. is_redacted {
128
- self . write_private_element (
129
- w,
130
- & RustField {
131
- id : Id {
132
- original : String :: from ( "value" ) ,
133
- renamed : String :: from ( "value" ) ,
134
- } ,
135
- ty : ty. r#type . clone ( ) ,
136
- comments : vec ! [ ] ,
137
- has_default : false ,
138
- decorators : HashMap :: new ( ) ,
139
- } ,
140
- & [ ] ,
141
- false ,
142
- ) ?;
143
- } else {
144
- self . write_element (
145
- w,
146
- & RustField {
147
- id : Id {
148
- original : String :: from ( "value" ) ,
149
- renamed : String :: from ( "value" ) ,
150
- } ,
151
- ty : ty. r#type . clone ( ) ,
152
- comments : vec ! [ ] ,
153
- has_default : false ,
154
- decorators : HashMap :: new ( ) ,
127
+ self . write_element (
128
+ w,
129
+ & RustField {
130
+ id : Id {
131
+ original : String :: from ( "value" ) ,
132
+ renamed : String :: from ( "value" ) ,
155
133
} ,
156
- & [ ] ,
157
- false ,
158
- ) ?;
159
- }
134
+ ty : ty. r#type . clone ( ) ,
135
+ comments : vec ! [ ] ,
136
+ has_default : false ,
137
+ decorators : HashMap :: new ( ) ,
138
+ } ,
139
+ & [ ] ,
140
+ false ,
141
+ match ty. is_redacted {
142
+ true => Visibility :: Private ,
143
+ false => Visibility :: Public
144
+ } ,
145
+ ) ?;
160
146
161
147
writeln ! ( w) ?;
162
148
@@ -216,10 +202,10 @@ impl Language for Kotlin {
216
202
217
203
if let Some ( ( last, elements) ) = rs. fields . split_last ( ) {
218
204
for f in elements. iter ( ) {
219
- self . write_element ( w, f, rs. generic_types . as_slice ( ) , requires_serial_name) ?;
205
+ self . write_element ( w, f, rs. generic_types . as_slice ( ) , requires_serial_name, Visibility :: Public ) ?;
220
206
writeln ! ( w, "," ) ?;
221
207
}
222
- self . write_element ( w, last, rs. generic_types . as_slice ( ) , requires_serial_name) ?;
208
+ self . write_element ( w, last, rs. generic_types . as_slice ( ) , requires_serial_name, Visibility :: Public ) ?;
223
209
writeln ! ( w) ?;
224
210
}
225
211
@@ -295,6 +281,11 @@ impl Language for Kotlin {
295
281
}
296
282
}
297
283
284
+ enum Visibility {
285
+ Public ,
286
+ Private
287
+ }
288
+
298
289
impl Kotlin {
299
290
fn write_enum_variants ( & mut self , w : & mut dyn Write , e : & RustEnum ) -> std:: io:: Result < ( ) > {
300
291
match e {
@@ -422,6 +413,7 @@ impl Kotlin {
422
413
f : & RustField ,
423
414
generic_types : & [ String ] ,
424
415
requires_serial_name : bool ,
416
+ visibility : Visibility ,
425
417
) -> std:: io:: Result < ( ) > {
426
418
self . write_comments ( w, 1 , & f. comments ) ?;
427
419
if requires_serial_name {
@@ -434,46 +426,28 @@ impl Kotlin {
434
426
. map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e) ) ?,
435
427
} ;
436
428
437
- write ! (
438
- w,
439
- "\t val {}: {}{}" ,
440
- remove_dash_from_identifier( & f. id. renamed) ,
441
- ty,
442
- ( f. has_default && !f. ty. is_optional( ) )
443
- . then_some( "? = null" )
444
- . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
445
- . unwrap_or_default( )
446
- )
447
- }
448
-
449
- fn write_private_element (
450
- & mut self ,
451
- w : & mut dyn Write ,
452
- f : & RustField ,
453
- generic_types : & [ String ] ,
454
- requires_serial_name : bool ,
455
- ) -> std:: io:: Result < ( ) > {
456
- self . write_comments ( w, 1 , & f. comments ) ?;
457
- if requires_serial_name {
458
- writeln ! ( w, "\t @SerialName({:?})" , & f. id. renamed) ?;
429
+ match visibility {
430
+ Visibility :: Public => write ! (
431
+ w,
432
+ "\t val {}: {}{}" ,
433
+ remove_dash_from_identifier( & f. id. renamed) ,
434
+ ty,
435
+ ( f. has_default && !f. ty. is_optional( ) )
436
+ . then_some( "? = null" )
437
+ . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
438
+ . unwrap_or_default( )
439
+ ) ,
440
+ Visibility :: Private => write ! (
441
+ w,
442
+ "\t private val {}: {}{}" ,
443
+ remove_dash_from_identifier( & f. id. renamed) ,
444
+ ty,
445
+ ( f. has_default && !f. ty. is_optional( ) )
446
+ . then_some( "? = null" )
447
+ . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
448
+ . unwrap_or_default( )
449
+ )
459
450
}
460
- let ty = match f. type_override ( SupportedLanguage :: Kotlin ) {
461
- Some ( type_override) => type_override. to_owned ( ) ,
462
- None => self
463
- . format_type ( & f. ty , generic_types)
464
- . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e) ) ?,
465
- } ;
466
-
467
- write ! (
468
- w,
469
- "\t private val {}: {}{}" ,
470
- remove_dash_from_identifier( & f. id. renamed) ,
471
- ty,
472
- ( f. has_default && !f. ty. is_optional( ) )
473
- . then_some( "? = null" )
474
- . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
475
- . unwrap_or_default( )
476
- )
477
451
}
478
452
479
453
fn write_comment (
0 commit comments