Вот решение с использованием Java отражения.
Для @(Foo @field)(index = 3) age: Int
до
println(classOf[Person].getDeclaredFields.map(_.getDeclaredAnnotationsByType(classOf[Foo]).map(_.index)).deep)
//Array(Array(), Array(3))
Для @(Foo @getter)(index = 3) age: Int
до
println(classOf[Person].getDeclaredMethods.map(_.getDeclaredAnnotationsByType(classOf[Foo]).map(_.index)).deep)
//Array(Array(), Array(), Array(3), Array(), Array(), Array(), Array(), Array(), Array(), Array(), Array(), Array(), Array())
Для @(Foo @param)(index = 3) age: Int
или просто @Foo(index = 3) age: Int
do
println(classOf[Person].getDeclaredConstructors.map(_.getParameters.map(_.getDeclaredAnnotationsByType(classOf[Foo]).map(_.index))).deep)
//Array(Array(Array(), Array(3)))
Вы можете комбинировать метааннотации @field
, @getter
, @param
.
Я думаю, что подобное можно сделать с помощью Scala отражение.