Is there a way to create a Kotlin compiler plugin that can modify the code being written?
I don't want to create separate generated code but actually modify the code itself.
For example, given this source:
Original
@Composable
fun MyScreen() {
Surface {
Button(onClick = {
println("Clicked")
})
}
}
I want to change the output code to be this:
Modified by plugin
@Composable
fun MyScreen() {
Surface {
Button(onClick =
track("MyScreen", "Surface", "Button") {
println("Clicked")
}
)
}
}
Or even just change the import:
Original
import androidx.compose.material.Button
@Composable
fun MyScreen() {
...
}
Modified by plugin
import com.mycompany.project.wrappers.Button
@Composable
fun MyScreen() {
...
}