I'm writing a Scala macro and am traversing the tree to find non-private fields in classes.
Consider this code that the macro looks at:
class Foo {
val bar: String = "test"
}
I'm traversing this code and getting to bar
's ValDef
. It has only two flags in its modifiers: Flag.PRIVATE
and Flag.LOCAL
.
Using the private
modifier on bar
changes nothing. Using the protected
modifier only adds Flag.PROTECTED
to the list of flags.
What am I missing? How do I make the distinction between private and public fields?
Edit:
The following code:
val bar: String = "test"
Has neither Flag.PRIVATE
nor Flag.LOCAL
, which makes sense since it's a 'global' public val.
The context I'm working inside is writing a new wart for wartremover, which simply takes a Traverser
from the context's universe when expanding the macro and traverses over the block of code.
A
val
definition in Scala expands to aprivate[this]
field with an additional getter. Other than theValDef
you're seeing there should be an additionalDefDef
method definition with the same name which is the getter on the field.