samedi 16 mai 2015

Reflect on annotation class from within scala macro annotation?

Is there a way to access the constructor declaration of a macro annotation from within the macro implementation by reflection? For example, when I define this macro annotation:

class Component(x: String, y: Int = 0) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro ComponentMacro.impl
}

is it possible to reflect on the Component from within the macro implementation? When I use something like:

class ComponentMacro(val c: whitebox.Context) {
  import c.universe._

  def impl(annottees: c.Expr[Any]*) = {
    /* ... */
    val t = typeOf[Component] // throws exception
  }
}

the compiler throws an error during macro expansion.





Aucun commentaire:

Enregistrer un commentaire