Hello! I am exploring KSP to write a compiler plug...
# ksp
a
Hello! I am exploring KSP to write a compiler plugin, something like Parcelize, so it would implement a predefined interface for annotated classes. Like you have a data class that implements the interface but you don't write the actual implementation code. And then you annotate the class with a marker annotation and the plugin should add the implementation. Is it a doable task for KSP?
j
No. You cannot modify existing source files. Only generate new ones.
a
Thanks, that is what I expected, just wanted to confirm.
t
If it’s acceptable, an alternate approach is to annotate an interface or abstract class and generate an implementation & a builder for the implementation.
Or if you can get away with it, generate extension functions defined for the annotated class that perform your logic. This depends on not needing to fulfill some interface.
a
Thanks, I will think about it.