I want to create a json file (based on an annotati...
# compiler
h
I want to create a json file (based on an annotation). Should I use the FIR or IR api? I am open to both. If I choose FIR (ideally with a DeclarationPredicate), will my plugin be executed inside the IDE, causing creating/overwriting the file over and over again?
j
As you don't need that json file to exist at "IDE time", you shouldn't do it with FIR.
I am open to both
That means -> Use IR always
h
So that's the "only" criteria to choose between FIR or IR?
j
I think so, if the user does not need to see anything on the IDE (new code to consume directly, checkers like warnings or errors, and so on), any thing you do with FIR will slow the load of that file on the IDE, providing no value for the user at the end but worse experience.
🙏 1
👍 1
j
You can run FIR outside of the IDE and regular compilation
We use FIR to produce a JSON file by just making our own task
h
And why did you choose FIR and not IR?
j
I mean we're just doing parsing. Isn't that what FIR is supposed to be for?
h
I just want to understand the reason 🙂
j
You can run FIR outside of the IDE and regular compilation
That is right, indeed if you don't use K2 on the IDE and you don't see your checkers, or you have compilation errors due to the codegen is not happening, the compilation will pass on CLI as K2 is used there. And any warning checker will be shown. Or if you have error checkers not shown on the IDE as they are disabled, the compilation will fail with them on CLI. But that file is not necessary on the IDE, so you can generate it on IR, you can get the same, and reduce the loading time of that file on the IDE.
j
We migrated from reflection to FIR. I didn't even really think IR was a choice.
j
I think the general purpose of using FIR is to show something on the IDE. That is the reason they are not providing "good" functions to create function bodies on FIR. You only need to create the functions without the body and add the body later on IR.
h
Jake, is your plugin open source? How do you handle the file? When do you create the file, do you use disposables?
We parse into a model and then serialize the model to JSON. The whole thing is wrapped in a CLI app, which we then invoke from a Gradle plugin that provides stuff like the classpath, sources, and JDK.
h
But you don't use this "plugin" in the IDE, do you?
j
Nope
h
So I followed the advice to create the file in IR but now ran into the problem of missing kdoc. When I switch to FIR, what would be the correct FirExtension to not generate the file during IDE all the time?