2

@specialized(Int) のような注釈を複製したいとしましょう。何かのようなもの:

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

注釈の引数 (例では Int) にアクセスする方法はありますか?

4

2 に答える 2

6

をご覧くださいc.prefix。に対応するツリーが含まれますnew expand(Int)

別のオプションはc.macroApplication、どちらになるか new expand(Int).macroTransform(...)です。

于 2013-09-09T06:18:52.340 に答える
0

次のようにして偽造できるようです。

class expandArgs(args: Any*) extends Annotation with StaticAnnotation

def foo[@expand @expandArgs(Int) T] = 4
于 2013-09-09T03:26:58.297 に答える