summaryrefslogtreecommitdiff
path: root/test/files/run/t7617a/Macros_1.scala
blob: d19f112bf478ff4cfe1868e099371bfdf39e48b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import scala.reflect.macros.BlackboxContext
import language.experimental.macros

object Macros {
  def getValueImpl[T](c: BlackboxContext): c.Expr[T] = {
    import c.universe._
    c.Expr[T](Apply(Select(c.prefix.tree, newTermName("getVal")), Nil))
  }
  def setValueImpl[T](c: BlackboxContext)(value: c.Expr[T]): c.Expr[Unit] = {
    import c.universe._
    c.Expr[Unit](Apply(Select(c.prefix.tree, newTermName("setVal")), List(value.tree)))
  }
}

object Module {
  private var _val: String = "hello"
  def setVal(value: String): Unit = this._val = value
  def getVal(): String = this._val

  def value: String = macro Macros.getValueImpl[String]
  def value_=(value: String): Unit = macro Macros.setValueImpl[String]
}