jeudi 23 juin 2016

Get a lambda argument from annotation

Assume we have an annotation:

@scala.annotation.meta.field
class MyAnnotation(param: String => String) extends StaticAnnotation

According to Remi T's answer here, if param was just a String, we could extract it this way:

a.tree.children.tail.collect({ case Literal(Constant(id: String)) => id }).headOption

But how can we extract and use a lambda expression? It is a Function(params, body) where params is an arguments list and body is a Tree representing function's body.

It's possible to convert the whole function's Tree to String and then use an interpreter, but it is SO ugly solution (and I couldn't do even this due to some problems with classpath during instantiating the interpreter, none of advices I found worked).





Aucun commentaire:

Enregistrer un commentaire