Kotlin compiler plugin, adding annotations to instance field of kotlin objects


#1

Hey,

I was looking into writing a kotlin compiler plugin that could add custom annotations to the INSTANCE field of singleton classes in kotlin (aka kotlin objects).
As I couldn’t find any information on the complete API with javadoc and what methods I need to extend/implement in general to achieve this, I wanted to reach out here to get some help.

I am fairly new to bytecode manipulation. I did some small amount in Java using ASM.
Any hints on how to actually intercept any object compilation (which files do I need to implement) would be a good hint! later on I would love to move it to a gradle plugin so it gets automatically called during compilation. Not sure if this is possible by default or if there is already a library that can do that.
I did dig around kotlin’s allopen gradle compiler plugin but I coudln’t find any code that actually changed the modifier to open.

Thanks for your help!


#2

Kotlin compiler plugins are currently unsupported. The code is open-source, but there is no documentation and we’re not able to provide any assistance or help with the implementation.

It also looks like your task can be accomplished through simple .class file rewriting using ASM; you don’t actually need to write a compiler plugin.