split out KeyMacro.enclosingTrees

This commit is contained in:
Mark Harrah 2012-12-02 03:17:20 -05:00
parent 8400b992af
commit a8d0af9464
1 changed files with 3 additions and 2 deletions

View File

@ -32,12 +32,13 @@ object KeyMacro
{ {
import c.universe.{Apply=>ApplyTree,_} import c.universe.{Apply=>ApplyTree,_}
val methodName = c.macroApplication.symbol.name.decoded val methodName = c.macroApplication.symbol.name.decoded
val enclosingTrees = c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.context.enclosingContextChain.map(_.tree.asInstanceOf[Tree]) enclosingTrees(c) match {
enclosingTrees match {
case vd @ ValDef(_, name, _, _) :: ts => name.decoded case vd @ ValDef(_, name, _, _) :: ts => name.decoded
case _ => case _ =>
c.error(c.enclosingPosition, s"""$methodName must be directly assigned to a val, such as `val x = $methodName[Int]("description")`.""") c.error(c.enclosingPosition, s"""$methodName must be directly assigned to a val, such as `val x = $methodName[Int]("description")`.""")
"<error>" "<error>"
} }
} }
def enclosingTrees(c: Context): Seq[c.Tree] =
c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.context.enclosingContextChain.map(_.tree.asInstanceOf[c.Tree])
} }