This can be done using TypeTag by filtering through the members your input type:
import reflect.runtime.universe._ def listProperties[T: TypeTag]: List[(TermSymbol, Annotation)] = {
Then:
scala> class A { @MyProperty("") val a = 1 ; @MyProperty("a") var b = 2 ; var c: Long = 1L } defined class A scala> listProperties[A] res15: List[(reflect.runtime.universe.TermSymbol, reflect.runtime.universe.Annotation)] = List((variable b,MyProperty("a")), (value a,MyProperty("")))
This does not directly give you MyProperty , but universe.Annotation . It has a scalaArgs method that gives you access to its tree-like arguments if you need to do something with it.
source share