I’m working on a proof-of-concept of a Kotlin compiler plugin (IR only) that generates new classes.
I haven’t been able to figure out how to “register” these new classes to the compilation. I can
add them to the IrFile, but it seems that it has no effect.
For example, what do I have to do to reach the point when IrPluginContext.referencedClass finds these new classes.
The only possibility I’ve found so far is IrPluginContext.symbolTable but it is marked as obsolated.
I’ve been successful in adding at least new methods into an IrFile. Is the plugin maybe open source? Also, if it is purely proof-of-concept, you could generate those classes in FIR and then fill the bodies in IR. I’d also recommend you check out the #compiler channel in the Kotlin Slack.
In my plugin, I use a “template” function declared in my own library (which I automatically as a dependency include using the gradle plugin) and I call updateFrom(templateFunction) inside of factory.buildFun { }
Interestingly, I’ve found out that the class code is actually generated by the compiler.
But IDEA does not show it for some strange reason. (Class in question is RuiText.class, I’ve tried Reload From Disk, haven’t tried invalidate caches yet, that’s a bit slow):