Compiler plugin: register newly generated classes


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.

Any pointers?

Thank you for your help,

1 Like

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 { }

Yes, it is open source. The code in question:

Here I use the addChild of IrFile, but tried other ways too.

The goal of the plugin is to provide a Svelte-like UI. I have it mostly planned out and started to work on the implementation.

It is a proof-of-concept stage and changing heavily.

The template concept is interesting, thank you for the idea. I’ll try it out.

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):

I think I can live with this, I can store the class internally and resolve references by myself.

@kyay Oh, the #compiler channel was a great tip, thanks. I checked slack, but haven’t noticed that such a channel exists.

1 Like