How to append a method to existing class using annotation processing in java / kotlin?
Here is a good example of Java Annotation Processing I recently worked with.
It's an implementation of @Immutable
annotation.
Check out ByteBuddy or Kotlin Poet to understand how additional code generation works.
For Kotlin you do almost the same, check this manual for Kotlin-specific steps.