Skip to content

Commit ff38088

Browse files
committed
fixup! Introduce semantics-aware Java import ordering. (fixes #522)
1 parent 10610f8 commit ff38088

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ public int compare(String string1, String string2) {
291291
* Ordering uses semantics of the import string by splitting it into package,
292292
* class name(s) and static member (for static imports) and then comparing by
293293
* each of those three substrings in sequence.
294-
*
294+
*
295295
* When comparing static imports, the last segment in the dot-separated string
296296
* is considered to be the member (field, method, type) name.
297-
*
297+
*
298298
* The first segment starting with an upper case letter is considered to be the
299299
* (first) class name. Since this comparator has no actual type information,
300300
* this auto-detection will fail for upper case package names and lower case
@@ -359,7 +359,7 @@ private String[] splitFqcnAndMember(String importString) {
359359
member = null;
360360
}
361361

362-
return new String[] { fqcn, member };
362+
return new String[]{fqcn, member};
363363
}
364364

365365
/**
@@ -406,7 +406,7 @@ private String[] splitPackageAndClasses(String fqcn) {
406406
classNames = fqcn.substring(i + 1);
407407
}
408408

409-
return new String[] { packageNames, classNames };
409+
return new String[]{packageNames, classNames};
410410
}
411411

412412
/**

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ public ImportOrderConfig treatAsPackage(Collection<String> treatAsPackage) {
127127
public ImportOrderConfig treatAsClass(String... treatAsClass) {
128128
return treatAsClass(Arrays.asList(treatAsClass));
129129
}
130-
130+
131131
public ImportOrderConfig treatAsClass(Collection<String> treatAsClass) {
132132
this.treatAsClass = new HashSet<>(treatAsClass);
133133
replaceStep(createStep());
134134
return this;
135135
}
136-
136+
137137
private FormatterStep createStep() {
138138
ImportOrderStep importOrderStep = ImportOrderStep.forJava();
139139

plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616
package com.diffplug.spotless.java;
1717

18+
import java.util.Set;
19+
1820
import org.junit.jupiter.api.Test;
1921

2022
import com.diffplug.spotless.FormatterStep;
2123
import com.diffplug.spotless.ResourceHarness;
2224
import com.diffplug.spotless.SerializableEqualityTester;
2325
import com.diffplug.spotless.StepHarness;
24-
import java.util.Set;
2526

2627
class ImportOrderStepTest extends ResourceHarness {
2728
@Test

0 commit comments

Comments
 (0)