@@ -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
@@ -41,10 +42,7 @@ object Interactive {
41
42
/** Include trees whose symbol is overridden by `sym` */
42
43
val overridden : Set = Set (1 << 0 )
43
44
44
- /**
45
- * Include trees whose symbol overrides `sym` (but for performance only in same source
46
- * file)
47
- */
45
+ /** Include trees whose symbol overrides `sym` */
48
46
val overriding : Set = Set (1 << 1 )
49
47
50
48
/** Include references */
@@ -473,33 +471,44 @@ object Interactive {
473
471
path.find(_.isInstanceOf [DefTree ]).getOrElse(EmptyTree )
474
472
475
473
/**
476
- * Find the definitions of the symbol at the end of `path`.
474
+ * Find the definitions of the symbol at the end of `path`. In the case of an import node,
475
+ * all imported symbols will be considered.
477
476
*
478
477
* @param path The path to the symbol for which we want the definitions.
479
478
* @param driver The driver responsible for `path`.
480
479
* @return The definitions for the symbol at the end of `path`.
481
480
*/
482
- def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver )(implicit ctx : Context ): List [SourceTree ] = {
483
- enclosingSourceSymbols(path, pos).flatMap { sym =>
484
- val enclTree = enclosingTree(path)
485
-
486
- val (trees, include) =
487
- if (enclTree.isInstanceOf [MemberDef ])
488
- (driver.allTreesContaining(sym.name.sourceModuleName.toString),
489
- Include .definitions | Include .overriding | Include .overridden)
490
- else sym.topLevelClass match {
491
- case cls : ClassSymbol =>
492
- val trees = Option (cls.sourceFile).flatMap(InteractiveDriver .toUriOption) match {
493
- case Some (uri) if driver.openedTrees.contains(uri) =>
494
- driver.openedTrees(uri)
495
- case _ => // Symbol comes from the classpath
496
- SourceTree .fromSymbol(cls).toList
497
- }
498
- (trees, Include .definitions | Include .overriding)
499
- case _ =>
500
- (Nil , Include .empty)
501
- }
481
+ def findDefinitions (path : List [Tree ], pos : SourcePosition , driver : InteractiveDriver ): List [SourceTree ] = {
482
+ implicit val ctx = driver.currentCtx
483
+ val enclTree = enclosingTree(path)
484
+ val includeOverridden = enclTree.isInstanceOf [MemberDef ]
485
+ val symbols = enclosingSourceSymbols(path, pos)
486
+ val includeExternal = symbols.exists(! _.isLocal)
487
+ findDefinitions(symbols, driver, includeOverridden, includeExternal)
488
+ }
502
489
490
+ /**
491
+ * Find the definitions of `symbols`.
492
+ *
493
+ * @param symbols The list of symbols for which to find a definition.
494
+ * @param driver The driver responsible for the given symbols.
495
+ * @param includeOverridden If true, also include the symbols overridden by any of `symbols`.
496
+ * @param includeExternal If true, also look for definitions on the classpath.
497
+ * @return The definitions for the symbols in `symbols`, and if `includeOverridden` is set, the
498
+ * definitions for the symbols that they override.
499
+ */
500
+ def findDefinitions (symbols : List [Symbol ],
501
+ driver : InteractiveDriver ,
502
+ includeOverridden : Boolean ,
503
+ includeExternal : Boolean ): List [SourceTree ] = {
504
+ implicit val ctx = driver.currentCtx
505
+ val include = Include .definitions | Include .overriding |
506
+ (if (includeOverridden) Include .overridden else Include .empty)
507
+ symbols.flatMap { sym =>
508
+ val name = sym.name.sourceModuleName.toString
509
+ val trees =
510
+ if (includeExternal) driver.allTreesContaining(name)
511
+ else driver.sourceTreesContaining(name)
503
512
findTreesMatching(trees, include, sym)
504
513
}
505
514
}
0 commit comments