From 1297d87d5e5bfa25022568b6e20fbd92f6d6c40a Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 25 Apr 2012 15:39:18 -0700 Subject: More style tips for team macros. --- .../scala/reflect/makro/runtime/Enclosures.scala | 39 ++++++++-------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/makro/runtime/Enclosures.scala b/src/compiler/scala/reflect/makro/runtime/Enclosures.scala index 72e9e568c0..ab38fc024d 100644 --- a/src/compiler/scala/reflect/makro/runtime/Enclosures.scala +++ b/src/compiler/scala/reflect/makro/runtime/Enclosures.scala @@ -6,31 +6,18 @@ trait Enclosures { 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 enclosingMacros: List[Context] = this :: mirror.analyzer.openMacros // include self - - 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 -} \ No newline at end of file + val macroApplication: Tree = expandee + val enclosingApplication: Tree = enclTrees collectFirst { case t: Apply => t } getOrElse EmptyTree + val enclosingClass: Tree = site.enclClass.tree + val enclosingImplicits: List[(Type, Tree)] = site.openImplicits + val enclosingMacros: List[Context] = this :: mirror.analyzer.openMacros // include self + val enclosingMethod: Tree = site.enclMethod.tree + val enclosingPosition: Position = if (enclPoses.isEmpty) NoPosition else enclPoses.head.pos + val enclosingUnit: CompilationUnit = currentRun.currentUnit +} -- cgit v1.2.3