You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ability to configure static import sorting to match behaviour of IntelliJ IDEA #879
@sbilello that's a separate issue but yeah that would probably be ideal for us if it were possible. I believe we were waiting on JetBrains breaking out their reformatting code into a library so that it could be used for that?
So I wrote the tests. The test for default ordering passes, the test for wildcardsLast fails. Good, so then I wrote all the code to get that wildcardsLast value into ImportSorterImpl and am trying to figure out where in the code it's actually doing the ordering of wildcard vs. non-wildcard.
I see filterMatchingImports receives the list in unsorted order and ultimately sets allImportOrderItems to a set with one element, "static ", and notMatching to a list with the same.
Then I've been stepping through and I get into mergeMatchingItems(), by which point template has already been sorted, but I didn't see when that happened.
I guess I expected to see a comparator somewhere in the code, but I don't see one at all, so there is no obvious place to change the comparison logic. I can only guess it's implicitly using the default natural string ordering somewhere.
Never mind, I just found the two calls to Collections.sort, here's where the change will go.
Activity
nedtwigg commentedon Jun 16, 2021
PR welcome :) https://github.com/diffplug/spotless/blob/main/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java
Maybe add a
boolean wildcardsLast = false, which can be set to true in order to get the IntellIJ behavior? Related #200sbilello commentedon Sep 30, 2021
Is there a way to use the same java style used by intellij in spotless? https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
hakanai commentedon Oct 1, 2021
@sbilello that's a separate issue but yeah that would probably be ideal for us if it were possible. I believe we were waiting on JetBrains breaking out their reformatting code into a library so that it could be used for that?
hakanai commentedon Oct 1, 2021
I'm having a look at this at the moment.
I think I have sorted out the way it would work in the DSL:
So I wrote the tests. The test for default ordering passes, the test for
wildcardsLastfails. Good, so then I wrote all the code to get thatwildcardsLastvalue intoImportSorterImpland am trying to figure out where in the code it's actually doing the ordering of wildcard vs. non-wildcard.I see
filterMatchingImportsreceives the list in unsorted order and ultimately setsallImportOrderItemsto a set with one element,"static ", andnotMatchingto a list with the same.Then I've been stepping through and I get into
mergeMatchingItems(), by which pointtemplatehas already been sorted, but I didn't see when that happened.I guess I expected to see a comparator somewhere in the code, but I don't see one at all, so there is no obvious place to change the comparison logic. I can only guess it's implicitly using the default natural string ordering somewhere.Never mind, I just found the two calls to
Collections.sort, here's where the change will go.Java importOrder support for sorting wildcards last
Java importOrder support for sorting wildcards last (#954 fixes #879)
nedtwigg commentedon Oct 2, 2021
Fixed in
plugin-gradle 5.16.0.