summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
blob: 2a4a22f81cd60de5ee8c5e7d3592ffa3bd337c47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package scala.reflect.macros
package runtime

trait Enclosures {
  self: Context =>

  import universe._
  import mirror._

  private def site       = callsiteTyper.context
  private def enclTrees  = site.enclosingContextChain map (_.tree)
  private def enclPoses  = enclosingMacros map (_.macroApplication.pos) filterNot (_ eq NoPosition)

  // vals are eager to simplify debugging
  // after all we wouldn't save that much time by making them lazy
  val macroApplication: Tree                      = expandee
  val enclosingClass: Tree                        = enclTrees collectFirst { case x: ImplDef => x } getOrElse EmptyTree
  val enclosingImplicits: List[ImplicitCandidate] = site.openImplicits.map(_.toImplicitCandidate)
  val enclosingMacros: List[Context]              = this :: universe.analyzer.openMacros // include self
  val enclosingMethod: Tree                       = site.enclMethod.tree
  val enclosingPosition: Position                 = if (enclPoses.isEmpty) NoPosition else enclPoses.head.pos
  val enclosingUnit: CompilationUnit              = universe.currentRun.currentUnit
  val enclosingRun: Run                           = universe.currentRun
}