Replace more than N imports from same package by wildcard import
eamelink opened this issue · 3 comments
I'm interested in implementing a refactoring that allows to change individual imports from a single package by a wildcard. Twitter's 'Effective Scala' for example suggests to do this when there are more than six imports from a given package.
I see the need to make exceptions for certain packages that would export too much. I think that can be handled similarly to the "always use wildcard imports when importing from these packages" feature in Scala IDE.
More problematic however is that changing imports to a wildcard might break compilation, if it causes duplicate names being imported. I think the easiest solution to that is to just not perform the operation if that happens. Is that feasible and can you from the top of your head recommend a strategy on how to this?
Work will start tomorrow evening during the first Amsterdam Scala Hackathon!
Awesome!
Regarding the duplicate names, you could look at all the (wildcard?) imports and then check what names they import. Off the top of my head, you can look at the type of the package (tpe of the Import expr) and then check if its members contains one of the names you plan to replace with a wildcard import. That should take care of the following case, where you want to replace import b.X with a wildcard:
package a {
class X
}
package b {
class X
}
import a._
import b.X
object Main extends X {
}
Are there more situations that could cause compilation failures?
Looking forward to your pull request :-)
👍 did this ever get implemented?
Moved to Assembla: https://www.assembla.com/spaces/scala-ide/tickets/1002570#/activity/ticket: