To get the list of annotations of the constructor of the case class you can use:
import scala.reflect.runtime.universe._
symbolOf[Test].asClass.primaryConstructor.typeSignature.paramLists.head.map(s => (s -> s.annotations))
However the annotations in the parameter list will not automatically be added to the corresponding class member. So you would have to match the annotated parameter y
that you get with the above call to the generated field y
by name.
Alternatively you could annotated the annotation in your case class like this
import scala.annotation.meta._
case class Test(x: String, @(Anno @field)(min = 5, max = 10) y: String)
and then use
val it = symbolOf[Test].toType.members
.filter(_.annotations.exists(a => a.tree.tpe <:< typeOf[Anno]))
to get an iterable of the fields with the Anno
annotation.
For a found field and an instance of Test
you get the value as follows
val yField = it.iterator.next
val o = Test("123", "abc")
universe.runtimeMirror(o.getClass.getClassLoader).reflect(o)
.reflectField(yField.asTerm).get