summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/makro/runtime/Enclosures.scala
blob: f9a6987e4884b6f4632d1304399b67b20461ef2f (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
25
26
27
28
29
30
31
32
33
34
35
36
package scala.reflect.makro
package runtime

trait Enclosures {
  self: Context =>

  import mirror._

  // vals are eager to simplify debugging
  // after all we wouldn't save that much time by making them lazy

  val macroApplication: Tree = expandee

  val enclosingMacros: List[Context] = this :: mirror.analyzer.openMacros

  val enclosingImplicits: List[(Type, Tree)] = callsiteTyper.context.openImplicits

  val enclosingPosition: Position = enclosingMacros.find(c => c.macroApplication.pos != NoPosition).map(_.macroApplication.pos).getOrElse(NoPosition)

  val enclosingApplication: Tree = {
    def loop(context: analyzer.Context): Tree = context match {
      case analyzer.NoContext => EmptyTree
      case context if context.tree.isInstanceOf[Apply] => context.tree
      case context => loop(context.outer)
    }

    val context = callsiteTyper.context
    loop(context)
  }

  val enclosingMethod: Tree = callsiteTyper.context.enclMethod.tree

  val enclosingClass: Tree = callsiteTyper.context.enclClass.tree

  val enclosingUnit: CompilationUnit = currentRun.currentUnit
}