blob: 42478cb988e774b7460e9ed5da4a304b3b878c44 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import scala.reflect.macros.BlackboxContext
import language.experimental.macros
class ann extends scala.annotation.StaticAnnotation
object Macros {
def impl(c: BlackboxContext) = {
import c.universe._
// val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), Ident(newTypeName("Int")))
val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), TypeTree(weakTypeOf[Int]))
c.Expr[Unit](Block(
List(ValDef(Modifiers(), newTermName("x"), tpt, Literal(Constant(42)))),
Apply(Ident(newTermName("println")), List(Ident(newTermName("x"))))))
}
def foo = macro impl
}
|