Use Collator when sorting Eclipse JDT members#2920
Open
aKandzior wants to merge 2 commits intodiffplug:mainfrom
Open
Use Collator when sorting Eclipse JDT members#2920aKandzior wants to merge 2 commits intodiffplug:mainfrom
aKandzior wants to merge 2 commits intodiffplug:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This updates the Eclipse JDT member sorting comparator to use
java.text.Collatorwhen 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
CollatorinDefaultJavaElementComparator.Test