小编dlw*_*lwh的帖子

Scala Macro Paradise:如何使用宏注释获取注释的参数?

Let's say I wanted to replicate an annotation like @specialized(Int)--crazy I know--using macro annotations. Something like:

class expand(expanded: Any*) extends Annotation with StaticAnnotation {
  def macroTransform(annottees: Any*) = macro expand.expandImpl
}

object expand {
 def expandImpl(c: Context)(annottees: c.Expr[Any]*):c.Expr[Any] = {        
    // would like to be able to get access to the "expanded" args above.
    ???
  }
}

// Usage:
 def foo[@expand(Int) T] = 4
Run Code Online (Sandbox Code Playgroud)

Is there any way to get access to the arguments of the annotation (Int in the …

annotations scala scala-macros

2
推荐指数
1
解决办法
440
查看次数

标签 统计

annotations ×1

scala ×1

scala-macros ×1