For example, to get all values, and their types, accessible at the macro's call site? Or at least just the values from the current class? E.g.:
class A {
val v1 = 10
var v2 = "2"
def m {
val m3 = true
// Here I would like to get information that v1: Int, v2: String and
// v3: Boolean are available
macroInvocation()
}
}
I looked in the Context and Universe, but couldn't find good methods.
Only solution I found so far is to get the macro's enclosing class/method (via the Context), and search the tree.
Only solution I found so far is to get the macro's enclosing class/method (via the Context), and search the tree
I have the feeling that you mean that you are actually inspecting the AST itself in order to extract the declared fields. You don't have to do that.
If c
is your Context
value, you can just do:
c.enclosingClass.symbol.typeSignature.members
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With