Package Explorer now does natural sorting#2464
Package Explorer now does natural sorting#2464katrina-l-hill wants to merge 2 commits intoeclipse-jdt:masterfrom
Conversation
|
This pull request changes some projects for the first time in this development cycle. An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch. Git patchFurther information are available in Common Build Issues - Missing version increments. |
bd1c6d8 to
22e9423
Compare
|
I have moved the NumericalComparator into the public class that calls it to avoid adding a public API and requiring a version bump. In the future, it can be exposed if another class needs to use it. |
|
@katrina-l-hill The code works great for java files - I tried adding a bunch to a package; however, I have noted that it does not seem to work for some jar files in a test plug-in in my workspace. I have org.eclipse.jdt.ui.tests plugin (from eclipse-jdt/eclipse.jdt.ui) checked out into my Eclpse and there is a folder in the project called testResources. When this folder is opened under PackageExplorer all the entries are correct except that rtstubs9.jar is sorted after rtstubs18.jar. |
|
@jjohnstn Thanks for reviewing this PR. I'll work on another fix for the sorting issue and get back with you. |
@jjohnstn I'm not able to reproduce this. Can you post a video to demonstrate the issue? Thank you! |
Element Comparator
- remove need for version bump or exposing API
6b28627 to
3557dc3
Compare
|
@katrina-l-hill Will try again with everything updated and will post scenario or video if problem still exists. |
| return offset + MEMBERSOFFSET; | ||
| } | ||
|
|
||
| static class NumericalStringComparator { |
There was a problem hiding this comment.
- Why it is a class at all? It can be just a static function.
- The comparator function needs tests. Without tests it is a no go.
- The code change affects any Java related UI, not only Package Explorer as advertised in the PR. Either fix PR description or the code.
- If it is supposed to be used by any UI related to Java, why does it apply only to types and not to methods / fields? They also could contain numbers.
- The comparator function creates lot of substrings, but that is expensive. Ideally the code should be rewritten to avoid using substrings and use indexes.
Beside this, if Eclipse views should provide natural sort order, ideally there should be an implementation of that algorithm provided somewhere in platform which could be used by all interested parties (Project Explorer, Outline view etc).
Therefore I believe JDT UI is a wrong place to introduce it.
This addresses issue #2295
What it does
This solution addresses the issue of alphanumerical sorting of file names with numbers in the Package Explorer instead of in a natural sort order. For example, previously the files were sorted "File1", "File10", and "File2", instead of like "File1", "File2", and "File10".
How to test
To test, add a new project with file names with numbers and run the configuration.
Before:

After:

Author checklist