milis92 / Krang

Kotlin Compiler Plugin that gives you the ability to be notified every time annotated function is called
Apache License 2.0
35 stars 1 forks source link

Provide the listener with `this`, if any #53

Open oakkitten opened 4 months ago

oakkitten commented 4 months ago

This project seems to be well-suited for method call logging in debug builds. However, one of the drawbacks for this use case is that the listener is only provided with the function name and its arguments. While the fact that the function name is fully qualified helps with differentiating between different functions of the same name, without access to this:

I imagine that both of these problems could be solved with providing this to the listener. For instance, I could have an interface such as LoggerProvider { val logger: Logger }, that I could be slapping onto instances and companion objects, and in the listener I would be checking whether thisRef is LoggerProvider and act accordingly.

(I wonder if something similar could be done for file-level methods. Per-file loggers sounds like a great idea!)

(Maybe provide a list of this-es in case there are multiple?)