[Kotlin] Improve field nullability based on (required) (#7658)

* [Kotlin] Only generate nullable return types if the field is not required

* [Kotlin] Fix generated code formatting according to kotlin style guide

Co-authored-by: Derek Bailey <derekbailey@google.com>
Co-authored-by: Paulo Pinheiro <paulovictor.pinheiro@gmail.com>
This commit is contained in:
Florian Wagner
2023-01-06 05:16:31 +01:00
committed by GitHub
parent 74b5195089
commit e61b00359b
3 changed files with 49 additions and 10 deletions

View File

@@ -68,10 +68,14 @@ class Monster : Table() {
false
}
}
val name : String?
val name : String
get() {
val o = __offset(10)
return if (o != 0) __string(o + bb_pos) else null
return if (o != 0) {
__string(o + bb_pos)
} else {
throw AssertionError("No value for (required) field name")
}
}
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(10, 1)
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 10, 1)

View File

@@ -31,7 +31,11 @@ class Stat : Table() {
val id : String?
get() {
val o = __offset(4)
return if (o != 0) __string(o + bb_pos) else null
return if (o != 0) {
__string(o + bb_pos)
} else {
null
}
}
val idAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
fun idInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)