@@ -97,29 +97,9 @@ object Interactive {
97
97
List (enclosingTree(path).symbol)
98
98
}
99
99
100
- syms.map(Interactive .sourceSymbol).filter(_.exists)
100
+ syms.map(_ .sourceSymbol).filter(_.exists)
101
101
}
102
102
103
- /** A symbol related to `sym` that is defined in source code.
104
- *
105
- * @see enclosingSourceSymbols
106
- */
107
- @ tailrec def sourceSymbol (sym : Symbol )(implicit ctx : Context ): Symbol =
108
- if (! sym.exists)
109
- sym
110
- else if (sym.is(ModuleVal ))
111
- sourceSymbol(sym.moduleClass) // The module val always has a zero-extent position
112
- else if (sym.is(Synthetic )) {
113
- val linked = sym.linkedClass
114
- if (linked.exists && ! linked.is(Synthetic ))
115
- linked
116
- else
117
- sourceSymbol(sym.owner)
118
- }
119
- else if (sym.isPrimaryConstructor)
120
- sourceSymbol(sym.owner)
121
- else sym
122
-
123
103
/** Check if `tree` matches `sym`.
124
104
* This is the case if the symbol defined by `tree` equals `sym`,
125
105
* or the source symbol of tree equals sym,
@@ -132,7 +112,7 @@ object Interactive {
132
112
sym1.owner.derivesFrom(sym2.owner) && sym1.overriddenSymbol(sym2.owner.asClass) == sym2
133
113
134
114
( sym == tree.symbol
135
- || sym.exists && sym == sourceSymbol( tree.symbol)
115
+ || sym.exists && sym == tree.symbol.sourceSymbol
136
116
|| include != 0 && sym.name == tree.symbol.name && sym.maybeOwner != tree.symbol.maybeOwner
137
117
&& ( (include & Include .overridden) != 0 && overrides(sym, tree.symbol)
138
118
|| (include & Include .overriding) != 0 && overrides(tree.symbol, sym)
@@ -327,37 +307,12 @@ object Interactive {
327
307
328
308
def traverser (source : SourceFile ) = {
329
309
new untpd.TreeTraverser {
330
- private def handleImport (imp : tpd.Import ): Unit = {
331
- val imported =
332
- imp.selectors.flatMap {
333
- case id : untpd.Ident =>
334
- importedSymbols(imp.expr, id.name).map((_, id, None ))
335
- case Thicket ((id : untpd.Ident ) :: (newName : untpd.Ident ) :: Nil ) =>
336
- val renaming = if (includeRenamingImports) Some (newName) else None
337
- importedSymbols(imp.expr, id.name).map((_, id, renaming))
338
- }
339
- imported match {
340
- case Nil =>
341
- traverse(imp.expr)
342
- case syms =>
343
- syms.foreach { case (sym, name, rename) =>
344
- val tree = tpd.Select (imp.expr, sym.name).withPos(name.pos)
345
- val renameTree = rename.map { r =>
346
- // Get the type of the symbol that is actually selected, and construct a select
347
- // node with the new name and the type of the real symbol.
348
- val name = if (sym.name.isTypeName) r.name.toTypeName else r.name
349
- val actual = tpd.Select (imp.expr, sym.name)
350
- tpd.Select (imp.expr, name).withPos(r.pos).withType(actual.tpe)
351
- }
352
- renameTree.foreach(traverse)
353
- traverse(tree)
354
- }
355
- }
356
- }
357
310
override def traverse (tree : untpd.Tree )(implicit ctx : Context ) = {
358
311
tree match {
359
- case imp : untpd.Import if includeImports =>
360
- handleImport(imp.asInstanceOf [tpd.Import ])
312
+ case imp : untpd.Import if includeImports && tree.hasType =>
313
+ val tree = imp.asInstanceOf [tpd.Import ]
314
+ val selections = tpd.importSelections(tree)
315
+ selections.foreach(traverse)
361
316
case utree : untpd.NameTree if tree.hasType =>
362
317
val tree = utree.asInstanceOf [tpd.NameTree ]
363
318
if (tree.symbol.exists
@@ -572,44 +527,6 @@ object Interactive {
572
527
}
573
528
}
574
529
575
- /**
576
- * All the symbols that are imported by import statement `imp`, if it matches
577
- * the predicate `selectorPredicate`.
578
- *
579
- * @param imp The import statement to analyze
580
- * @param selectorPredicate A test to find the selector to use.
581
- * @return The symbols imported.
582
- */
583
- private def importedSymbols (imp : tpd.Import ,
584
- selectorPredicate : untpd.Tree => Boolean = util.common.alwaysTrue)
585
- (implicit ctx : Context ): List [Symbol ] = {
586
- val symbols = imp.selectors.find(selectorPredicate) match {
587
- case Some (id : untpd.Ident ) =>
588
- importedSymbols(imp.expr, id.name)
589
- case Some (Thicket ((id : untpd.Ident ) :: (_ : untpd.Ident ) :: Nil )) =>
590
- importedSymbols(imp.expr, id.name)
591
- case _ =>
592
- Nil
593
- }
594
-
595
- symbols.map(sourceSymbol).filter(_.exists).distinct
596
- }
597
-
598
- /**
599
- * The symbols that are imported with `expr.name`
600
- *
601
- * @param expr The base of the import statement
602
- * @param name The name that is being imported.
603
- * @return All the symbols that would be imported with `expr.name`.
604
- */
605
- private def importedSymbols (expr : tpd.Tree , name : Name )(implicit ctx : Context ): List [Symbol ] = {
606
- def lookup (name : Name ): Symbol = expr.tpe.member(name).symbol
607
- List (lookup(name.toTermName),
608
- lookup(name.toTypeName),
609
- lookup(name.moduleClassName),
610
- lookup(name.sourceModuleName))
611
- }
612
-
613
530
/**
614
531
* Is this tree using a renaming introduced by an import statement?
615
532
*
0 commit comments