Skip to content

Commit

Permalink
Fix semantics-aware sorting of static imports (fixes #522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frettman committed May 23, 2023
1 parent d107957 commit a8a94c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
17 changes: 6 additions & 11 deletions lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,13 @@ private int compareFullyQualifiedClassName(String fqcn1, String fqcn2) {
private String[] splitFqcnAndMember(String importString) {
String s = importString.substring(STATIC_KEYWORD.length()).trim();

String fqcn;
String member;

/*
* Static imports always contain a member or wildcard and it's always the last
* segment.
*/
int dot = s.lastIndexOf(".");
if (!Character.isUpperCase(s.charAt(dot + 1))) {
fqcn = s.substring(0, dot);
member = s.substring(dot + 1);
} else {
fqcn = s;
member = null;
}

String fqcn = s.substring(0, dot);
String member = s.substring(dot + 1);
return new String[]{fqcn, member};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import static com.example.Test.*;
import static com.example.Test.A_CONST;
import static com.example.Test.Nested.B_CONST;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import static com.example.Test.*;
import static com.example.Test.A_CONST;
import static com.example.Test.Nested.B_CONST;
import static com.example.Test.Z_CONST;
import static com.example.Test.Nested.B_CONST;

import com.example.Test;
import com.example.Test.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ import com.sun.jna.platform.win32.Guid.CLSID;
import com.example.a.A;
import com.example.b;
import com.example.c.C;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.when;

0 comments on commit a8a94c0

Please sign in to comment.