Skip to content

Package Explorer now does natural sorting#2464

Open
katrina-l-hill wants to merge 2 commits intoeclipse-jdt:masterfrom
katrina-l-hill:Issue2295PackageViewerNaturalSort
Open

Package Explorer now does natural sorting#2464
katrina-l-hill wants to merge 2 commits intoeclipse-jdt:masterfrom
katrina-l-hill:Issue2295PackageViewerNaturalSort

Conversation

@katrina-l-hill
Copy link

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:
Screenshot 2025-08-07 122036

After:
Screenshot 2025-08-06 153019

Author checklist

@eclipse-jdt-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

org.eclipse.jdt.ui/META-INF/MANIFEST.MF
org.eclipse.jdt.ui/pom.xml

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 patch
From 66f67b5828c6e86654dc828bea62279a10e695cd Mon Sep 17 00:00:00 2001
From: Eclipse JDT Bot <jdt-bot@eclipse.org>
Date: Wed, 3 Sep 2025 21:00:45 +0000
Subject: [PATCH] Version bump(s) for 4.38 stream


diff --git a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
index 53f1b0d306..a5dc720767 100644
--- a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.ui
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.ui; singleton:=true
-Bundle-Version: 3.35.100.qualifier
+Bundle-Version: 3.35.200.qualifier
 Bundle-Activator: org.eclipse.jdt.internal.ui.JavaPlugin
 Bundle-ActivationPolicy: lazy
 Bundle-Vendor: %providerName
diff --git a/org.eclipse.jdt.ui/pom.xml b/org.eclipse.jdt.ui/pom.xml
index e81c09a125..fa432d58f4 100644
--- a/org.eclipse.jdt.ui/pom.xml
+++ b/org.eclipse.jdt.ui/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.ui</artifactId>
-  <version>3.35.100-SNAPSHOT</version>
+  <version>3.35.200-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
 	<build>
-- 
2.51.0

Further information are available in Common Build Issues - Missing version increments.

@jjohnstn jjohnstn force-pushed the Issue2295PackageViewerNaturalSort branch 2 times, most recently from bd1c6d8 to 22e9423 Compare September 10, 2025 21:55
@jjohnstn
Copy link
Contributor

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.

@jjohnstn
Copy link
Contributor

@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.

@katrina-l-hill
Copy link
Author

@jjohnstn Thanks for reviewing this PR. I'll work on another fix for the sorting issue and get back with you.

@katrina-l-hill
Copy link
Author

@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 I'm not able to reproduce this. Can you post a video to demonstrate the issue? Thank you!

@jjohnstn jjohnstn force-pushed the Issue2295PackageViewerNaturalSort branch from 6b28627 to 3557dc3 Compare December 3, 2025 18:58
@jjohnstn
Copy link
Contributor

jjohnstn commented Dec 3, 2025

@katrina-l-hill Will try again with everything updated and will post scenario or video if problem still exists.

Copy link
Member

@iloveeclipse iloveeclipse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment.

return offset + MEMBERSOFFSET;
}

static class NumericalStringComparator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why it is a class at all? It can be just a static function.
  2. The comparator function needs tests. Without tests it is a no go.
  3. The code change affects any Java related UI, not only Package Explorer as advertised in the PR. Either fix PR description or the code.
  4. 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.
  5. 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.

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.

4 participants