Thanks to the answers to my previous question, I was able to create a function macro such that it returns a Map
that maps each field name to its value of a class, e
The annotation will be on the val
itself, not on the accessor. The easiest way to access the val
is through the accessed
method on MethodSymbol
:
def isTransient(m: MethodSymbol) = m.accessed.annotations.exists(
_.tpe =:= typeOf[scala.transient]
)
Now you can just write the following in your collect
:
case m: MethodSymbol if m.isAccessor && !isTransient(m) =>
Note that the version of isTransient
I've given here has to be defined in your macro, since it needs the imports from c.universe
, but you could factor it out by adding a Universe
argument if you're doing this kind of thing in several macros.