Hello all, I’m currently playing with KotlinPoet on a jvm desktop app and I’m wondering if its possible to actually edit a existent class with it.
usecase: I’m attempting to build an app to bootstrap code for one of our features and it involves editing some classes
z
Zach Klippenstein (he/him) [MOD]
02/26/2021, 6:46 PM
It doesn’t do any parsing, it just writes. You could use something like KSP to do some high-level parsing and then use kotlin poet to spit out auxiliary source code, or use a full-fledged compiler plugin to rewrite bytecode.
a
alex.tavella
02/26/2021, 7:00 PM
The problem with those alternatives is that it would change the way we code our feature. It is an option indeed.
Another option would be to call
toString()
from i.e. a TypeSpec and place it inside some file through IO apis, right?
w
wasyl
02/26/2021, 7:55 PM
Maybe something like what KtLint does would help? It has apis to modify the source, although they're pretty low-level
Edit: just read Jake's comment, it's basically PSI so the same thing