Hello :simple_smile: I’m thinking of building a c...
# compiler
c
Hello simple smile I’m thinking of building a compiler plugin for a small library I’m working work on, but I’d like to understand if what I want to do is feasible . Essentially I would want to find all the callsites of a particular function, say.
Example.foo(x: Any)
Then for every given different type of x, I would need to add an implementation for a interface to that type. The interface basically encodes the type to and from a hashmap by iterating all of the properties in the class recursively, turning the object into a HashMap<String, String> For example if you called:
Example.foo(user: User)
and
data class User(
private val name: String,
private val age: Int
)
I would generate
data class User(
private val name: String,
private val age: Int
) : Adapter {
fun fromHashmap() {
...
}
fun toHashmap() {
...
}
}
Is this possible? Any help would be greatly appreciated!
n
I have limited knowledge but it should be possible as long as the types that you want to modify are declared in the module being compiled. You can’t add supertypes to String or CoroutineScope for example
p
Sounds like you actually want to implement custom annotation processor
c
It would be fine if I was just generating code, but I also need to change a function body. I guess I could use KSP for the adapter gen and just use a compiler plugin for the last bit 🤔