@@ -8,6 +8,7 @@ import scala.collection._
88import ast .{NavigateAST , Trees , tpd , untpd }
99import core ._ , core .Decorators .{sourcePos => _ , _ }
1010import Contexts ._ , Flags ._ , Names ._ , NameOps ._ , Symbols ._ , Trees ._ , Types ._
11+ import transform .SymUtils .decorateSymbol
1112import util .Positions ._ , util .SourceFile , util .SourcePosition
1213import core .Denotations .SingleDenotation
1314import NameKinds .SimpleNameKind
@@ -33,6 +34,7 @@ object Interactive {
3334 def isDefinitions : Boolean = (bits & definitions.bits) != 0
3435 def isLinkedClass : Boolean = (bits & linkedClass.bits) != 0
3536 def isImports : Boolean = (bits & imports.bits) != 0
37+ def isLocal : Boolean = (bits & local.bits) != 0
3638 }
3739
3840 /** The empty set */
@@ -59,6 +61,9 @@ object Interactive {
5961 /** Include imports in the results */
6062 val imports : Set = Set (1 << 5 )
6163
64+ /** Include local symbols, inspect local trees */
65+ val local : Set = Set (1 << 6 )
66+
6267 /** All the flags */
6368 val all : Set = Set (~ 0 )
6469 }
@@ -321,29 +326,37 @@ object Interactive {
321326 *
322327 * @param includeReferences If true, include references and not just definitions
323328 */
324- def namedTrees (trees : List [SourceTree ], include : Include .Set , treePredicate : NameTree => Boolean )
325- (implicit ctx : Context ): List [SourceTree ] = safely {
329+ def namedTrees (trees : List [SourceTree ],
330+ include : Include .Set ,
331+ treePredicate : NameTree => Boolean = util.common.alwaysTrue
332+ )(implicit ctx : Context ): List [SourceTree ] = safely {
326333 val buf = new mutable.ListBuffer [SourceTree ]
327334
328335 def traverser (source : SourceFile ) = {
329336 new untpd.TreeTraverser {
337+ private def handle (utree : untpd.NameTree ): Unit = {
338+ val tree = utree.asInstanceOf [tpd.NameTree ]
339+ if (tree.symbol.exists
340+ && ! tree.symbol.is(Synthetic )
341+ && ! tree.symbol.isPrimaryConstructor
342+ && tree.pos.exists
343+ && ! tree.pos.isZeroExtent
344+ && (include.isReferences || isDefinition(tree))
345+ && treePredicate(tree))
346+ buf += SourceTree (tree, source)
347+ }
330348 override def traverse (tree : untpd.Tree )(implicit ctx : Context ) = {
331349 tree match {
332350 case imp : untpd.Import if include.isImports && tree.hasType =>
333351 val tree = imp.asInstanceOf [tpd.Import ]
334352 val selections = tpd.importSelections(tree)
335353 traverse(imp.expr)
336354 selections.foreach(traverse)
355+ case utree : untpd.ValOrDefDef if tree.hasType =>
356+ handle(utree)
357+ if (include.isLocal) traverseChildren(tree)
337358 case utree : untpd.NameTree if tree.hasType =>
338- val tree = utree.asInstanceOf [tpd.NameTree ]
339- if (tree.symbol.exists
340- && ! tree.symbol.is(Synthetic )
341- && ! tree.symbol.isPrimaryConstructor
342- && tree.pos.exists
343- && ! tree.pos.isZeroExtent
344- && (include.isReferences || isDefinition(tree))
345- && treePredicate(tree))
346- buf += SourceTree (tree, source)
359+ handle(utree)
347360 traverseChildren(tree)
348361 case tree : untpd.Inlined =>
349362 traverse(tree.call)
@@ -474,6 +487,7 @@ object Interactive {
474487 def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver )(implicit ctx : Context ): List [SourceTree ] = {
475488 enclosingSourceSymbols(path, pos).flatMap { sym =>
476489 val enclTree = enclosingTree(path)
490+ val includeLocal = if (sym.exists && sym.isLocal) Include .local else Include .empty
477491
478492 val (trees, include) =
479493 if (enclTree.isInstanceOf [MemberDef ])
@@ -492,7 +506,7 @@ object Interactive {
492506 (Nil , Include .empty)
493507 }
494508
495- findTreesMatching(trees, include, sym)
509+ findTreesMatching(trees, include | includeLocal , sym)
496510 }
497511 }
498512
0 commit comments