mirror of https://github.com/sbt/sbt.git
split out KeyMacro.enclosingTrees
This commit is contained in:
parent
8400b992af
commit
a8d0af9464
|
|
@ -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])
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue