@@ -8,6 +8,7 @@ import scala.collection._
8
8
import ast .{NavigateAST , Trees , tpd , untpd }
9
9
import core ._ , core .Decorators .{sourcePos => _ , _ }
10
10
import Contexts ._ , Flags ._ , Names ._ , NameOps ._ , Symbols ._ , Trees ._ , Types ._
11
+ import transform .SymUtils .decorateSymbol
11
12
import util .Positions ._ , util .SourceFile , util .SourcePosition
12
13
import core .Denotations .SingleDenotation
13
14
import NameKinds .SimpleNameKind
@@ -33,6 +34,7 @@ object Interactive {
33
34
def isDefinitions : Boolean = (bits & definitions.bits) != 0
34
35
def isLinkedClass : Boolean = (bits & linkedClass.bits) != 0
35
36
def isImports : Boolean = (bits & imports.bits) != 0
37
+ def isLocal : Boolean = (bits & local.bits) != 0
36
38
}
37
39
38
40
/** The empty set */
@@ -59,6 +61,9 @@ object Interactive {
59
61
/** Include imports in the results */
60
62
val imports : Set = Set (1 << 5 )
61
63
64
+ /** Include local symbols, inspect local trees */
65
+ val local : Set = Set (1 << 6 )
66
+
62
67
/** All the flags */
63
68
val all : Set = Set (~ 0 )
64
69
}
@@ -321,29 +326,37 @@ object Interactive {
321
326
*
322
327
* @param includeReferences If true, include references and not just definitions
323
328
*/
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 {
326
333
val buf = new mutable.ListBuffer [SourceTree ]
327
334
328
335
def traverser (source : SourceFile ) = {
329
336
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
+ }
330
348
override def traverse (tree : untpd.Tree )(implicit ctx : Context ) = {
331
349
tree match {
332
350
case imp : untpd.Import if include.isImports && tree.hasType =>
333
351
val tree = imp.asInstanceOf [tpd.Import ]
334
352
val selections = tpd.importSelections(tree)
335
353
traverse(imp.expr)
336
354
selections.foreach(traverse)
355
+ case utree : untpd.ValOrDefDef if tree.hasType =>
356
+ handle(utree)
357
+ if (include.isLocal) traverseChildren(tree)
337
358
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)
347
360
traverseChildren(tree)
348
361
case tree : untpd.Inlined =>
349
362
traverse(tree.call)
@@ -474,6 +487,7 @@ object Interactive {
474
487
def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver )(implicit ctx : Context ): List [SourceTree ] = {
475
488
enclosingSourceSymbols(path, pos).flatMap { sym =>
476
489
val enclTree = enclosingTree(path)
490
+ val includeLocal = if (sym.exists && sym.isLocal) Include .local else Include .empty
477
491
478
492
val (trees, include) =
479
493
if (enclTree.isInstanceOf [MemberDef ])
@@ -492,7 +506,7 @@ object Interactive {
492
506
(Nil , Include .empty)
493
507
}
494
508
495
- findTreesMatching(trees, include, sym)
509
+ findTreesMatching(trees, include | includeLocal , sym)
496
510
}
497
511
}
498
512
0 commit comments