diff options
Diffstat (limited to 'src/main/scala/hbt/StaticContext.scala')
-rw-r--r-- | src/main/scala/hbt/StaticContext.scala | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/scala/hbt/StaticContext.scala b/src/main/scala/hbt/StaticContext.scala new file mode 100644 index 00000000..7eb4fa8d --- /dev/null +++ b/src/main/scala/hbt/StaticContext.scala @@ -0,0 +1,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)") + } +} |