final val
has special significance for constants and means inline them.
Your ordinary val looks like:
scala> q"{ val i = 42 ; i }"
res0: reflect.runtime.universe.Tree =
{
val i = 42;
i
}
scala> showRaw(res0)
res1: String = Block(List(ValDef(Modifiers(), TermName("i"), TypeTree(), Literal(Constant(42)))), Ident(TermName("i")))
I think Travis Brown's Metaplasm blog, i.e., things you shouldn't try at home with macros, includes examining the surrounding context for a def.
In this case, consulting the enclosing context on a statement basis would discover the def of the i
you want, and you could examine its RHS.
Their macro philosophy is to think local and expand local. I just made that up. They also offer macro annotations for less-local things like companions.
But wait, they do offer an eval
facility on Context
. Is that sufficient for your use case?