Hi All, I want to modify Jetpack compose functions in my app source code. I am not sure where to sta...
s
Hi All, I want to modify Jetpack compose functions in my app source code. I am not sure where to start writing compiler plugin for that. What I want to achieve is, in @composable functions if any new object is created and Content() function is called immediately. I want to replace new object creation with remember block and call Content() method. From this
Copy code
@Composable
fun AllComposableFunctions() {
    TestWidget().Content()
}
To
Copy code
@Composable
fun AllComposableFunctions() {
    remember { TestWidget() }.Content()
}
Basically TestWidget is a flutter style stateful widget. Since compose functions will be called multiple times, first function new object each time function runs. Wrapping object creation with remember solves the problem. but I want to do it via compiler plugin, so that code looks elegant. Please advice where should i start and right materials to follow
x
Hi @Srikrishna! I haven’t tried to develop any compiler plugin by myself, but I highly recommend you to watch

this talk by Tadeas Kriz in the KotlinConf 2023

. It gets into a lot of details on how to write these types of plugins and has a lot of references for further reading. However, I wanted to highlight what he says about the APIs for developing custom plugins. These APIs are experimental and will keep on being for a long time. This makes the custom plugins hard to maintain over time, discouraging their development in most of the cases. I hope this information to be any useful for you
c
Also this question is better asked in #compiler or #compose
s
@xoangon & @Chrimaeon Thanks
❤️ 1