Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
- Add `javaparserVersion` option to the Cleanthat step, allowing callers to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903))
### Changes
- Use Eclipse JDT's collator-based comparison when sorting Java members to better match Eclipse save actions. ([#2920](https://github.com/diffplug/spotless/pull/2920))
- Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903))
- Bump default `eclipse-jdt` version from `4.35` to `4.39`. ([#2912](https://github.com/diffplug/spotless/pull/2912))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.diffplug.spotless.extra.glue.jdt;

import java.text.Collator;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
Expand Down Expand Up @@ -61,6 +62,7 @@ class DefaultJavaElementComparator implements Comparator<BodyDeclaration> {
private final int[] memberCategoryOffsets;
private final boolean sortByVisibility;
private final int[] visibilityOffsets;
private final Collator collator;

static DefaultJavaElementComparator of(
boolean doNotSortFields,
Expand Down Expand Up @@ -95,6 +97,7 @@ static DefaultJavaElementComparator of(
this.memberCategoryOffsets = memberCategoryOffsets;
this.sortByVisibility = sortByVisibility;
this.visibilityOffsets = visibilityOffsets;
this.collator = Collator.getInstance();
}

@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "we only accept valid tokens in the order string, otherwise we fall back to default value")
Expand Down Expand Up @@ -271,7 +274,7 @@ public int compare(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclara
String name2 = method2.getName().getIdentifier();

// method declarations (constructors) are sorted by name
int cmp = name1.compareTo(name2);
int cmp = collator.compare(name1, name2);
if (cmp != 0) {
return cmp;
}
Expand All @@ -286,7 +289,7 @@ public int compare(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclara
for (int i = 0; i < len; i++) {
SingleVariableDeclaration param1 = parameters1.get(i);
SingleVariableDeclaration param2 = parameters2.get(i);
cmp = buildSignature(param1.getType()).compareTo(buildSignature(param2.getType()));
cmp = collator.compare(buildSignature(param1.getType()), buildSignature(param2.getType()));
if (cmp != 0) {
return cmp;
}
Expand Down Expand Up @@ -377,7 +380,7 @@ private int preserveRelativeOrder(BodyDeclaration bodyDeclaration1, BodyDeclarat
}

private int compareNames(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclaration2, String name1, String name2) {
int cmp = name1.compareTo(name2);
int cmp = collator.compare(name1, name2);
if (cmp != 0) {
return cmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ void sort_members_local_enabled_true() {
StepHarness.forStep(builder.build())
.testResource("java/eclipse/SortExample.localEnabledTrue.test", "java/eclipse/SortExample.localEnabledTrue.clean");
}

@Test
void sort_members_uses_collator() {
EclipseJdtFormatterStep.Builder builder = EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral(), TestP2Provisioner.defaultProvisioner());
builder.sortMembersEnabled(true);
StepHarness.forStep(builder.build())
.testResource("java/eclipse/SortExample.collator.test", "java/eclipse/SortExample.collator.clean");
}
}
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
- Fix `tableTestFormatter` editorconfig cache not honoring `.editorconfig` changes across Gradle daemon runs due to a shared static `EditorConfigProvider`. ([#2893](https://github.com/diffplug/spotless/pull/2893))
### Changes
- Use Eclipse JDT's collator-based comparison when sorting Java members to better match Eclipse save actions. ([#2920](https://github.com/diffplug/spotless/pull/2920))
- Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903))
- Bump default `eclipse-jdt` version from `4.35` to `4.39`. ([#2912](https://github.com/diffplug/spotless/pull/2912))

Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
- Add `<javaparserVersion>` option to `<cleanthat>`, allowing users to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903))
### Changes
- Use Eclipse JDT's collator-based comparison when sorting Java members to better match Eclipse save actions. ([#2920](https://github.com/diffplug/spotless/pull/2920))
- Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903))
- Bump default `eclipse-jdt` version from `4.35` to `4.39`. ([#2912](https://github.com/diffplug/spotless/pull/2912))

Expand Down
15 changes: 15 additions & 0 deletions testlib/src/main/resources/java/eclipse/SortExample.collator.clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.diffplug.spotless.extra.glue.jdt;

public class SortExample {
private static void mab() {
}

private static void mAc() {
}

private static void mp(String a, String b, int a) {
}

private static void mp(String a, String b, String p) {
}
}
15 changes: 15 additions & 0 deletions testlib/src/main/resources/java/eclipse/SortExample.collator.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.diffplug.spotless.extra.glue.jdt;

public class SortExample {
private static void mAc() {
}

private static void mab() {
}

private static void mp(String a, String b, String p) {
}

private static void mp(String a, String b, int a) {
}
}
Loading