appmattus
03/29/2023, 4:57 PMsomeFunction
in this example, to automagically specify a missing parameter, as an example:
class MyClass : ViewModel() {
val result = viewModelScope.someFunction()
}
fun CoroutineScope.someFunction(value: String? = null) {
println(value)
}
With the idea being I can populate the value in someFunction
based on something else in the class - for example the class name.
Intercepting the IrCall
seems easy enough as well as adding the additional argument to the call:
private val Meta.somePlugin: CliPlugin
get() = "Some Plugin" {
meta(
irCall { irCall ->
if (irCall.symbol.owner.kotlinFqName.asString() == "someFunction") {
// do the magic argument adding
}
}
)
The problem I’m having though is there seems no obvious way to figure out the parent of an `IrCall`; unlike IrFunction
there is no parentClassOrNull
Is there a better approach for being able to figure out where the IrCall
came from or performing the transformation?
I’m assuming I should be looking at using transformChildren
although just not 100% sure what type of IrElement
I should apply that to!raulraja
03/29/2023, 5:11 PMirCall
you could intercept irDeclaration
(the parent) and the on each intercepted declaration search inside for callsappmattus
03/29/2023, 8:04 PMirDeclaration
but noticed the IrCall
was found twice, once for the property and the other for the backing field of the property.
now i’m specifically using transformChildren
on irProperty
. it’s great to see the class file transformed 🙂
meta has certainly made the process of creating a compiler plugin seem pretty trivial, great workraulraja
03/30/2023, 7:22 AM