In a compiler plugin, I want to generate new sourc...
# compiler
y
In a compiler plugin, I want to generate new source files by interpreting already-existing source files (basically exactly like an annotation processor would) but while getting access to the resolved descriptors coming in from external sources (e.g. if there's a KtCallExpression to
let
from the stdlib, I want to get the descriptor for that call). I do realise that I can get the
bindingContext
and use that to call
ktExpression.getResolvedCall
but obviously I don't have access to that inside of a
CollectAdditionalSourcesExtension
so what can I do here? I'm thinking maybe I can run analysis twice or something as in run it once inside of a
CollectAdditionalSourcresExtension
and generate the files and then let the compiler do its own analysis normally but is that the right approach?
r
Hi @Youssef Shoaib [MOD] I believe what you want can be currently done with
RetryWithAdditionalRoots
as analysis result in which you launch a new analysis with the new files you’ve generated but that is part of the api that may go away with FIR. @shikasd has a clean example 🙏 of that API here https://github.com/ShikaSD/kotlin-compiler-plugin-retry-with-additional-roots/blob/master/compiler-plugin/src/main/kotlin/Plugin.kt#L30
🙏 1