Gamadril
09/19/2021, 12:53 PMraulraja
09/19/2021, 2:20 PMclassDeclaration
or similar in meta’s in the quote system. Unfortunately that part will be removed when FIR and a compiler plugin api becomes stable since it depends on the KtElements and descriptors API. If you use that you would intercept all class declarations and replace them for versions that include the annotations. Something along the lines of:
val Meta.autoSerialize: CliPlugin get() =
"AutoSerialize" {
meta(
classDeclaration(this, { element.isNotSerializableOrWhateverElseyouWanttoCheck() }) { (c, _) ->
Transform.replace(
replacing = c,
newDeclaration = """|@kotlinx.serializable.Serializable
|$c
|""".class(descriptor)
)
}
)
}
raulraja
09/19/2021, 2:26 PMGamadril
09/19/2021, 2:58 PMval Meta.patchSerializable: CliPlugin
get() = "Patch classes" {
meta(
classDeclaration(this, { element.name == "NewMultipleSource" }) { (c, descriptor) ->
Transform.replace(
replacing = c,
newDeclaration = """|@kotlinx.serializable.Serializable
|$c
|""".class(descriptor)
)
}
)
}
but .class(descriptor) does not compile. "``class``.syntheticScope" (seen somewhere else without really knowing how it works...) compiles, but use-plugin project throws an error on build step