ケース クラス パラメータによってステートメントを生成しようとしています。
case class f(a:String, b:String){
val statement = Macroses.st[f]
}
object MacrosTest {
def start() {
val result = f("1", "2").statement
}
}
結果は INSERT INTO tableName(a, b) VALUES ('1', '2'); でなければなりません。
これは私のマクロです
def st[T]:Insert = macro st_impl[T]
def st_impl[A : c.WeakTypeTag](c: Context): c.Expr[Insert] = {
import c.universe._
val methods: List[String] = c.weakTypeOf[A].typeSymbol.
typeSignature.decls.toList.filterNot(_.isMethod)
.map(_.name.toString)
c.Expr[Insert](q"""QueryBuilder.insertInto("tableName")${methods.map(v => s""".value("$v", $v)""").mkString}""")
}
私は例外を得ました:
c.universe.Name expected but c.universe.Tree found
この準引用符を使用すると、うまく機能します。
(q"""QueryBuilder.insertInto("tableName").value("a", a).value("b", b)""")