save-cli
save-cli copied to clipboard
Codegen and compiler plugin: Generate methods for data class merging
For these classes we can generate a 'raw' counterpart with nullable fields and merge(raw, raw) method to merge them with priority. We than can use usual classes throughout the code. For example,
data class A(val x: Int, val y: String)
will generate
data class RawA(val x: Int?, val y: String?)
fun merge(r1: RawA, r2: RawA): A { ... }
The idea comes from the situation, that on stage of toml parsing, we inevitably will have some of the fields nullable. However, after merging, we actually won't have nullable fields in almost all cases, and it will be inconvenient to drag through the entire code such fields.
But, we also should consider situation, when even after merging some field will be nullable - additional class can't help in this case
Can be achieved with a compiler plugin. We would like to research compile plugin functionality, so it can be very useful for us. Can be a separate project