I ended up making a general solution, but if all you're doing is simple modifications then pure AST stuff should be fine. Unfortunately I don't know if this would be practical in Kotlin since it doesn't use the Javac compiler. You may be able to compile your Kotlin code, include it in a Java project and use AST transformations to modify the pre-compiled Kotlin code.