If the Scala>Editor>Organize Imports>sorting order preference includes a more-specific and less-specific package path prefix, for example "com" and "com.example", then import statements for certain packages will be duplicated when "Organize Imports" is run (twice for com.example..., in this example).
Leave a comment
on 2015-08-04 21:58 *
By John Thywissen
Description changed from If the _Scala>Editor>Organi... to If the _Scala>Editor>Organi...
Example to reproduce:
Now add
After invoking organize imports the result is:
If the sorting order is different, the result of the organize imports action is slightly different but still wrong.
package a.b
class X
package a.c
class Y
package a.p
import a.b.X
import a.c.Y
class Test {
val x: X = ???
val y: Y = ???
}
Now add
a.c
and a
(order is relevant) to the sorting order list.After invoking organize imports the result is:
package a.p
import a.c.Y
import a.b.X
import a.c.Y
class Test {
val x: X = ???
val y: Y = ???
}
If the sorting order is different, the result of the organize imports action is slightly different but still wrong.
Don't duplicate imports while grouping them
This commit reimplements the import grouping logic in a self contained, easily
testable function, and thereby fixes a bug, that led to the duplication of
imports if one import group was the prefix of another import group.
Note that the unit test that is added by this commit lives in exactly the same
package as the code it covers, since this allows us to access package private
APIs. We should consider doing the same for the rest of the tests, that
currently live under `scala.tools.refactoring.tests`.
Fixes #1002526
Branch: master
Commit: scala-ide:d4890f1e52
This commit reimplements the import grouping logic in a self contained, easily
testable function, and thereby fixes a bug, that led to the duplication of
imports if one import group was the prefix of another import group.
Note that the unit test that is added by this commit lives in exactly the same
package as the code it covers, since this allows us to access package private
APIs. We should consider doing the same for the rest of the tests, that
currently live under `scala.tools.refactoring.tests`.
Fixes #1002526
Branch: master
Commit: scala-ide:d4890f1e52
No file chosen
You have an empty file field. Please select or remove it.
Name | Size |
---|