save-cli icon indicating copy to clipboard operation
save-cli copied to clipboard

Codegen and compiler plugin: Generate methods for data class merging

Open petertrr opened this issue 4 years ago • 2 comments
trafficstars

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 { ... }

petertrr avatar May 26 '21 12:05 petertrr

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

kgevorkyan avatar May 26 '21 13:05 kgevorkyan

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

orchestr7 avatar Apr 21 '22 13:04 orchestr7