Skip to content

Instantly share code, notes, and snippets.

@quintona
Created March 25, 2014 22:28
Show Gist options
  • Save quintona/9772837 to your computer and use it in GitHub Desktop.
Save quintona/9772837 to your computer and use it in GitHub Desktop.
Trait expansion macro
object helloMacro {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
import Flag._
val result = {
annottees.map(_.tree).toList match {
case q"trait $name extends ..$parents { ..$body }" :: Nil =>
q"""
trait $name extends ..$parents {
def hello = "hello"
..$body
}
"""
}
}
c.Expr[Any](result)
}
}
class hello extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro helloMacro.impl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment