From 5ec2199c4966404d462eb866533dc0589fe7f239 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 10 May 2013 13:00:12 +0200 Subject: Added locator for untyped trees. --- src/dotty/tools/dotc/core/UntypedTrees.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/dotty/tools/dotc/core/UntypedTrees.scala b/src/dotty/tools/dotc/core/UntypedTrees.scala index 82a160ab0..8cd857f95 100644 --- a/src/dotty/tools/dotc/core/UntypedTrees.scala +++ b/src/dotty/tools/dotc/core/UntypedTrees.scala @@ -74,5 +74,18 @@ object UntypedTrees { def ugen(implicit ctx: Context) = new UGen + + implicit class UntypedTreeDecorator(val self: Tree) extends AnyVal { + def locateEnclosing(base: List[Tree], pos: Position): List[Tree] = { + def encloses(elem: Any) = elem match { + case t: Tree => t.envelope contains pos + case _ => false + } + base.productIterator find encloses match { + case Some(tree: Tree) => locateEnclosing(tree :: base, pos) + case none => base + } + } + } } -- cgit v1.2.3