summaryrefslogtreecommitdiff
path: root/src/main/scala/hbt/StaticContext.scala
blob: 7eb4fa8d2412abe25d366b3ea730e817bfc35dbb (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
package hbt


import scala.language.experimental.macros
import scala.reflect.macros._

case class StaticContext(value: Boolean)
object StaticContext {
  implicit def apply: StaticContext = macro applyImpl
  def rec(c: Context)(expr: c.Symbol): Boolean = {
    import c.universe._
    // Classes and traits and such
    if(!expr.isModuleClass && expr.isClass) false
    // Method contents
    else if(expr.isMethod) false
    else if(expr.owner == NoSymbol) true
    else rec(c)(expr.owner)
  }

  def applyImpl(c: Context): c.Expr[StaticContext] = {
    import c.universe._
    val staticContext = rec(c)(c.internal.enclosingOwner)
    c.Expr[StaticContext](q"hbt.StaticContext($staticContext)")
  }
}