Marcello Lelio Albano
06/17/2021, 11:17 PMPatrick Louis
06/18/2021, 5:30 AMTransform.replace
. You can reference all elements of the original KtNamedFunction in the newDeclaration
while also injecting additional code.
This should work as inspiration for what you're trying to do.raulraja
06/18/2021, 7:39 AMTransform.newSources
has also disadvantages as whatever declaration you introduce won’t be visible to the IDEA plugin.
For example if you intercept
fun foo() {
val x = 1
}
and replace it for
fun foo() {
val x = 2
}
There is no visual indication in the IDE that X was replaced by a compiler plugin or instrumented in any way and it becomes confusing to the end user. We had the alternative to push our own IDE plugin as well but that also requires all users of metaprogramming create IDE plugins extending the Kotlin plugin and it becomes extremely complex very quick for any simple feature. We hope FIR addresses these issues and then the Quote system will be based on FIR instead of PSI+compiler descriptors.Marcello Lelio Albano
06/19/2021, 4:50 PMarrow
without touching the function signature (i.e. keeping same arguments, annotations, generics, etc) ? I think it's ok there is no visual indication right now but I may want to revisit this in future.raulraja
06/20/2021, 9:25 AMval Meta.myPlugin: CliPlugin
get() =
"Intercepts functions and replaces their body" {
meta(
irFunction {
it.body...
}
)
}
raulraja
06/20/2021, 9:25 AMraulraja
06/20/2021, 9:26 AMirCall
or whatever node you are after to identify the transformation. Returning null
from that lambda is a no op.raulraja
06/20/2021, 9:26 AMMarcello Lelio Albano
06/21/2021, 5:20 PMMarcello Lelio Albano
06/21/2021, 7:23 PMMarcello Lelio Albano
06/22/2021, 2:16 AM