例如,要获取可在宏的调用站点访问的所有值及其类型?
或者至少只是当前类的值?例如。:
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()
}
}
我查看了上下文和宇宙,但找不到好的方法。
到目前为止我找到的唯一解决方案是获取宏的封闭类/方法(通过上下文),并搜索树。
最佳答案
Only solution I found so far is to get the macro's enclosing class/method (via the Context), and search the tree
我有一种感觉,您的意思是您实际上是在检查 AST 本身以提取声明的字段。你不必那样做。
如
c
是你的 Context
值(value),你可以这样做:c.enclosingClass.symbol.typeSignature.members
关于scala - 是否可以在宏中访问符号表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15373336/