Auto generated extension functions & properties


#1

This question is inspired by Mapping immutable data class instance.

I’d like to generate my special functions like ‘copy’ or ‘componentN’ at data classes. Does Kotlin provides some official means to do that or to simplify such a task?

If not, please give me a hint, how it could be done in a best way.

Ideally I’ like to do that in such a way that for the programmer-user it looked like as just importing some package (and may be some annotation, but better without) and voila we have our classes extended.


#2

Probably the best way to go would be https://blog.jetbrains.com/kotlin/2015/06/better-annotation-processing-supporting-stubs-in-kapt/ . Overall it is not very well-documented, but should work fine. It doesn’t by itself provide extra help for processing the annotations though (there is an example of how to use it at https://github.com/yanex/kotlin-poc)