Skip to content

Use Collator when sorting Eclipse JDT members#2920

Open
aKandzior wants to merge 2 commits intodiffplug:mainfrom
aKandzior:fix-jdt-member-sort-collator
Open

Use Collator when sorting Eclipse JDT members#2920
aKandzior wants to merge 2 commits intodiffplug:mainfrom
aKandzior:fix-jdt-member-sort-collator

Conversation

@aKandzior
Copy link
Copy Markdown

Summary

This updates the Eclipse JDT member sorting comparator to use java.text.Collator when comparing member names and parameter type signatures.

The Eclipse JDT UI implementation uses a collator for these comparisons. Spotless used String.compareTo, which can produce a different member order than Eclipse save actions for names that differ by case or locale-sensitive collation.

Motivation

Our team primarily works with Eclipse, but some developers now use VS Code for smaller edits. We use Spotless to make the command line and non-Eclipse editing workflow follow the same formatting rules as Eclipse save actions.

Without this patch, member sorting can differ deterministically between Eclipse and Spotless in edge cases. That creates a "ping pong" scenario where method positions shift depending on which editor or formatter was used last.

Using the same collator-based comparison as Eclipse avoids that difference and makes Spotless member sorting match Eclipse more closely.

Changes

  • Use Collator in DefaultJavaElementComparator.
  • Apply it to method name comparison.
  • Apply it to parameter type signature comparison.
  • Add a regression fixture that exposes the ordering difference.

Test

./gradlew :lib-extra:test --tests com.diffplug.spotless.extra.java.EclipseJdtFormatterStepSpecialCaseTest --no-daemon --no-configuration-cache --console=plain

aKandzior added 2 commits May 8, 2026 14:24
The Eclipse JDT member sorter compares method names and parameter type signatures with a java.text.Collator. Spotless' DefaultJavaElementComparator used String.compareTo instead, which can produce a different member order than Eclipse save actions for names that differ by case or locale-sensitive collation.

Update DefaultJavaElementComparator to use Collator for member name comparison and parameter type signature comparison so Spotless matches Eclipse JDT behavior more closely.

Adds a regression fixture which exposes the case-sensitive ordering difference.

Test: ./gradlew :lib-extra:test --tests com.diffplug.spotless.extra.java.EclipseJdtFormatterStepSpecialCaseTest --no-daemon --no-configuration-cache --console=plain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant