Hi, I'm trying to play around with compiler plugin...
# compiler
v
Hi, I'm trying to play around with compiler plugins and cannot get past a problem. My goal is to find all Composable function calls and add something like
.testTag("...")
to the expression of each argument of type
Modifier
(I'm using another Modifier extension, but the idea is the same).
Copy code
Text("My Text") // transformed to: Text("My Text", modifier = Modifier.testTag("..."))
Text("My Second Text", modifier = Modifier.padding(5.dp)) // transformed to: Text("My Second Text", modifier = Modifier.padding(5.dp).testTag("..."))
The problem that I have is that my Modifier-extending plugin only works when the Modifier argument is already set (e.g.
Text("...", modifier = Modifier.padding(5.dp))
or even just
Text("...", modifier = Modifier)
), but not when none is specified:
Text("...")
. In the latter case, the default value of the parameter is used, even though I have set the
Modifier
argument to an
IrCallImpl
equivalent to
Modifier.testTag("...")
, using
argument[index]
. What am I missing here? For reference, this is how I do it.
s
It depends if you plugin runs before or after Compose I believe you don't have to do anything else if it runs before, otherwise you'll have to modify $default parameter to have the bit reset
v
That was it, thanks! Am I understanding it correctly that Compose handles default parameters on its own, as opposed to letting Kotlin do it?
👌 1