Is it possible, from a compiler plugin, to get the...
# compiler
b
Is it possible, from a compiler plugin, to get the original source code for the call site of a function? Is this something being considered/possible for the new IR compiler plugins? I've been poking around in the Kotlin repository trying to figure out if an idea I have for a plugin is even possible. I found
org.jetbrains.kotlin.ir.SourceManager
but I'm not sure if that can be used to read the source file given an
IrCall
.
The specific idea I have is a compiler plugin to enable power assertions similar to Groovy: https://groovy-lang.org/testing.html#_power_assertions There seemed to be some discussion on this a few years ago but I haven't really seen anything since: https://discuss.kotlinlang.org/t/support-for-groovy-style-power-assertion-in-kotlin/427
f
Maybe you could use https://github.com/arrow-kt/arrow-meta and rewrite the source code of your assert function
z
Woah, that’s super cool
s
@bnorm A little bit late to the party, but you can use
IrDeclaration.descriptor.findPsi()
to get psi, which contains all the text with offsets.