Created
March 25, 2014 22:28
-
-
Save quintona/9772837 to your computer and use it in GitHub Desktop.
Trait expansion macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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