@@ -421,30 +421,19 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
421
421
* Pre: `sym` must have a position.
422
422
*/
423
423
def defPath (sym : Symbol , root : Tree )(implicit ctx : Context ): List [Tree ] = ctx.debugTraceIndented(s " defpath( $sym with position ${sym.pos}, ${root.show}) " ) {
424
- def show (from : Any ): String = from match {
425
- case tree : Trees .Tree [_] => s " ${tree.show} with attachments ${tree.allAttachments}"
426
- case x : printing.Showable => x.show
427
- case x => x.toString
428
- }
429
-
430
- def search (from : Any ): List [Tree ] = ctx.debugTraceIndented(s " search( ${show(from)}) " ) {
431
- from match {
432
- case tree : Tree => // Dotty problem: cannot write Tree @ unchecked, this currently gives a syntax error
433
- if (definedSym(tree) == sym) tree :: Nil
434
- else if (tree.envelope.contains(sym.pos)) {
435
- val p = search(tree.productIterator)
436
- if (p.isEmpty) p else tree :: p
437
- } else Nil
438
- case xs : Iterable [_] =>
439
- search(xs.iterator)
440
- case xs : Iterator [_] =>
441
- xs.map(search).find(_.nonEmpty).getOrElse(Nil )
442
- case _ =>
443
- Nil
424
+ require(sym.pos.exists)
425
+ object accum extends TreeAccumulator [List [Tree ]] {
426
+ def apply (x : List [Tree ], tree : Tree ): List [Tree ] = {
427
+ if (tree.envelope.contains(sym.pos))
428
+ if (definedSym(tree) == sym) tree :: x
429
+ else {
430
+ val x1 = foldOver(x, tree)
431
+ if (x1 ne x) tree :: x1 else x1
432
+ }
433
+ else x
444
434
}
445
435
}
446
- require(sym.pos.exists)
447
- search(root)
436
+ accum(Nil , root)
448
437
}
449
438
450
439
/** The statement sequence that contains a definition of `sym`, or Nil
0 commit comments