@@ -322,20 +322,23 @@ object Interactive {
322322
323323 def traverser (source : SourceFile ) = {
324324 new untpd.TreeTraverser {
325- private def handleImport (imported : List [Symbol ],
326- uexpr : untpd.Tree ,
327- id : untpd.Ident ,
328- rename : Option [untpd.Ident ]): Unit = {
329- val expr = uexpr.asInstanceOf [tpd.Tree ]
325+ private def handleImport (imp : tpd.Import ): Unit = {
326+ val imported =
327+ imp.selectors.flatMap {
328+ case id : untpd.Ident =>
329+ importedSymbols(imp.expr, id.name).map((_, id, None ))
330+ case Thicket ((id : untpd.Ident ) :: (newName : untpd.Ident ) :: Nil ) =>
331+ importedSymbols(imp.expr, id.name).map((_, id, Some (newName)))
332+ }
330333 imported match {
331334 case Nil =>
332- traverse(expr)
335+ traverse(imp. expr)
333336 case syms =>
334- syms.foreach { sym =>
335- val tree = tpd.Select (expr, sym.name).withPos(id .pos)
337+ syms.foreach { case ( sym, name, rename) =>
338+ val tree = tpd.Select (imp. expr, sym.name).withPos(name .pos)
336339 val renameTree = rename.map { r =>
337340 val name = if (sym.name.isTypeName) r.name.toTypeName else r.name
338- RenameTree (name, tpd.Select (expr, sym.name)).withPos(r.pos)
341+ RenameTree (name, tpd.Select (imp. expr, sym.name)).withPos(r.pos)
339342 }
340343 renameTree.foreach(traverse)
341344 traverse(tree)
@@ -344,12 +347,8 @@ object Interactive {
344347 }
345348 override def traverse (tree : untpd.Tree )(implicit ctx : Context ) = {
346349 tree match {
347- case imp @ Import (uexpr, (id : untpd.Ident ) :: Nil ) if includeImports =>
348- val imported = importedSymbols(imp.asInstanceOf [tpd.Import ])
349- handleImport(imported, uexpr, id, None )
350- case imp @ Import (uexpr, Thicket ((id : untpd.Ident ) :: (rename : untpd.Ident ) :: Nil ) :: Nil ) if includeImports =>
351- val imported = importedSymbols(imp.asInstanceOf [tpd.Import ])
352- handleImport(imported, uexpr, id, Some (rename))
350+ case imp : untpd.Import if includeImports =>
351+ handleImport(imp.asInstanceOf [tpd.Import ])
353352 case utree : untpd.NameTree if tree.hasType =>
354353 val tree = utree.asInstanceOf [tpd.NameTree ]
355354 if (tree.symbol.exists
@@ -573,25 +572,33 @@ object Interactive {
573572 private def importedSymbols (imp : tpd.Import ,
574573 selectorPredicate : untpd.Tree => Boolean = util.common.alwaysTrue)
575574 (implicit ctx : Context ): List [Symbol ] = {
576- def lookup0 (name : Name ): Symbol = imp.expr.tpe.member(name).symbol
577- def lookup (name : Name ): List [Symbol ] = {
578- lookup0(name.toTermName) ::
579- lookup0(name.toTypeName) ::
580- lookup0(name.moduleClassName) ::
581- lookup0(name.sourceModuleName) :: Nil
582- }
583-
584575 val symbols = imp.selectors.find(selectorPredicate) match {
585576 case Some (id : untpd.Ident ) =>
586- lookup( id.name)
577+ importedSymbols(imp.expr, id.name)
587578 case Some (Thicket ((id : untpd.Ident ) :: (_ : untpd.Ident ) :: Nil )) =>
588- lookup(id.name)
589- case _ => Nil
579+ importedSymbols(imp.expr, id.name)
580+ case _ =>
581+ Nil
590582 }
591583
592584 symbols.map(sourceSymbol).filter(_.exists).distinct
593585 }
594586
587+ /**
588+ * The symbols that are imported with `expr.name`
589+ *
590+ * @param expr The base of the import statement
591+ * @param name The name that is being imported.
592+ * @return All the symbols that would be imported with `expr.name`.
593+ */
594+ private def importedSymbols (expr : tpd.Tree , name : Name )(implicit ctx : Context ): List [Symbol ] = {
595+ def lookup (name : Name ): Symbol = expr.tpe.member(name).symbol
596+ lookup(name.toTermName) ::
597+ lookup(name.toTypeName) ::
598+ lookup(name.moduleClassName) ::
599+ lookup(name.sourceModuleName) :: Nil
600+ }
601+
595602 /**
596603 * Used to represent a renaming import `{foo => bar}`.
597604 * We need this because the name of the tree must be the new name, but the
0 commit comments