@@ -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
}
@@ -327,23 +332,29 @@ object Interactive {
327
332
328
333
def traverser (source : SourceFile ) = {
329
334
new untpd.TreeTraverser {
335
+ private def handle (utree : untpd.NameTree ): Unit = {
336
+ val tree = utree.asInstanceOf [tpd.NameTree ]
337
+ if (tree.symbol.exists
338
+ && ! tree.symbol.is(Synthetic )
339
+ && ! tree.symbol.isPrimaryConstructor
340
+ && tree.pos.exists
341
+ && ! tree.pos.isZeroExtent
342
+ && (include.isReferences || isDefinition(tree))
343
+ && treePredicate(tree))
344
+ buf += SourceTree (tree, source)
345
+ }
330
346
override def traverse (tree : untpd.Tree )(implicit ctx : Context ) = {
331
347
tree match {
332
348
case imp : untpd.Import if include.isImports && tree.hasType =>
333
349
val tree = imp.asInstanceOf [tpd.Import ]
334
350
val selections = tpd.importSelections(tree)
335
351
traverse(imp.expr)
336
352
selections.foreach(traverse)
353
+ case utree : untpd.ValOrDefDef if tree.hasType =>
354
+ handle(utree)
355
+ if (include.isLocal) traverseChildren(tree)
337
356
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)
357
+ handle(utree)
347
358
traverseChildren(tree)
348
359
case tree : untpd.Inlined =>
349
360
traverse(tree.call)
@@ -474,6 +485,7 @@ object Interactive {
474
485
def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver )(implicit ctx : Context ): List [SourceTree ] = {
475
486
enclosingSourceSymbols(path, pos).flatMap { sym =>
476
487
val enclTree = enclosingTree(path)
488
+ val includeLocal = if (sym.exists && sym.isLocal) Include .local else Include .empty
477
489
478
490
val (trees, include) =
479
491
if (enclTree.isInstanceOf [MemberDef ])
@@ -492,7 +504,7 @@ object Interactive {
492
504
(Nil , Include .empty)
493
505
}
494
506
495
- findTreesMatching(trees, include, sym)
507
+ findTreesMatching(trees, include | includeLocal , sym)
496
508
}
497
509
}
498
510
0 commit comments