Lilly
10/12/2021, 5:02 PMCasey Brooks
10/12/2021, 5:09 PMLilly
10/12/2021, 5:17 PMephemient
10/12/2021, 5:28 PMCasey Brooks
10/12/2021, 5:32 PMLilly
10/12/2021, 5:36 PMCasey Brooks
10/12/2021, 5:37 PMCasey Brooks
10/12/2021, 5:40 PMLilly
10/12/2021, 5:40 PMYou could also go another route and generate code from a simpler format, such as JSON, YAML, or .properties.I guess that's not possible @Casey Brooks I already have a Excel file (400 lines) and the data structure is complex. Some columns are generated by excel's power query editor. It would be hard to convert this to JSON
Casey Brooks
10/12/2021, 5:42 PMLilly
10/12/2021, 5:42 PMLilly
10/12/2021, 5:46 PMephemient
10/12/2021, 5:48 PMCasey Brooks
10/12/2021, 5:49 PMpackage: com.my.big.record
className: MyBigRecord
fields:
- propertyName: field1
type: String
- propertyName: anotherField
type: Int
- propertyName: isChecked
type: Boolean
- ...
and your scripts produce the following code (which is mostly what you'd generate for KSP, too):
package com.my.big.record
data class MyBigRecord(
val field1: String,
val anotherField: Int,
val isChecked: Boolean,
)
object MyBigRecordParser {
fun parse(csv: CsvRecord) : MyBigRecord {
return MyBigRecord(
field1 = csv["field1"],
anotherField = csv["anotherField"],
isChecked = csv["isChecked"],
)
}
}
ephemient
10/12/2021, 5:50 PMephemient
10/12/2021, 5:51 PMCasey Brooks
10/12/2021, 5:56 PMephemient
10/12/2021, 6:01 PMLilly
10/12/2021, 6:01 PMephemient
10/12/2021, 6:02 PMephemient
10/12/2021, 6:03 PMLilly
10/12/2021, 6:05 PMephemient
10/12/2021, 6:06 PMephemient
10/12/2021, 6:08 PMephemient
10/12/2021, 6:09 PMCasey Brooks
10/12/2021, 6:13 PMephemient
10/12/2021, 6:15 PMLilly
10/12/2021, 6:17 PMLilly
10/12/2021, 6:21 PMCasey Brooks
10/12/2021, 6:21 PMobject MyBigRecordParser {
fun parse(csv: CsvRecord) : MyBigRecord {
return MyBigRecord(
field1 = csv["field1"],
anotherField = csv["anotherField"].toIntOrNull() ?: 0,
isChecked = csv["isChecked"].toBoolean(),
)
}
}
And of course, your code generators would have to know what types it supports, so it knows how to generate the proper "type conversion" for each field.Casey Brooks
10/12/2021, 6:22 PMLilly
10/12/2021, 6:22 PMCasey Brooks
10/12/2021, 6:24 PMephemient
10/12/2021, 6:26 PMLilly
10/12/2021, 6:50 PMpackage com.my.big.record
data class MyBigRecord(
val field1: String,
val anotherField: Int,
val isChecked: Boolean,
)
object MyBigRecordParser {
fun parse(csv: CsvRecord) : MyBigRecord {
return MyBigRecord(
field1 = csv["field1"],
anotherField = csv["anotherField"].toIntOrNull() ?: 0,
isChecked = csv["isChecked"].toBoolean(),
)
}
}
I have to write the code generation logic which would look almost identical, not? I mean since I need type conversation I would have to touch every single field or did I miss something?Lilly
10/12/2021, 6:54 PMephemient
10/12/2021, 6:54 PMephemient
10/12/2021, 6:55 PMLilly
10/12/2021, 6:56 PMephemient
10/12/2021, 7:12 PMLilly
10/12/2021, 9:30 PM