I wonder if I could use the compiler to process co...
# compiler
f
I wonder if I could use the compiler to process code and: • find calls to a certain function • infer types My use case is this, I need to find calls like this:
Copy code
registerNodeFactory(Ref_pathContext::class) { pt: Ref_pathContext, t: ASTTransformer ->
            var ast: PSSExpression
            ...
        }
And to infer the return type of the lambda. I would then use that information to generate some code. Would that be feasible?
Could I use the compiler as a library for this, or should I create a compiler plugin?
t
Yes, it is quite possible. An example below which does almost what you want. It finds calls to functions annotated with a specific annotation. Then transforms those calls. I use a cache to decide if the function called is annotated to speed thing up a bit. https://github.com/spxbhuhb/z2-schematic/blob/2276929941f1b87f8070e1c3e6e7d346470b[…]exion/z2/schematic/kotlin/ir/access/SchematicAccessTransform.kt
I think you need to write a plugin for that.
f
Thank you, I will look into that!