changeset 52144:f53671e05660

8210683: Search result display order reversed for overloaded entries Reviewed-by: jjg
author hannesw
date Tue, 16 Oct 2018 15:05:03 +0200
parents ad6384355aa3
children 032c1c1379ab
files src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Tue Oct 16 14:17:19 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Tue Oct 16 15:05:03 2018 +0200
@@ -30,6 +30,8 @@
 import java.net.URI;
 import java.text.CollationKey;
 import java.text.Collator;
+import java.text.ParseException;
+import java.text.RuleBasedCollator;
 import java.util.*;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.Map.Entry;
@@ -1588,7 +1590,7 @@
         private final Collator instance;
         private final int MAX_SIZE = 1000;
         private DocCollator(Locale locale, int strength) {
-            instance = Collator.getInstance(locale);
+            instance = createCollator(locale);
             instance.setStrength(strength);
 
             keys = new LinkedHashMap<String, CollationKey>(MAX_SIZE + 1, 0.75f, true) {
@@ -1607,6 +1609,21 @@
         public int compare(String s1, String s2) {
             return getKey(s1).compareTo(getKey(s2));
         }
+
+        private Collator createCollator(Locale locale) {
+            Collator baseCollator = Collator.getInstance(locale);
+            if (baseCollator instanceof RuleBasedCollator) {
+                // Extend collator to sort signatures with additional args and var-args in a well-defined order:
+                // () < (int) < (int, int) < (int...)
+                try {
+                    return new RuleBasedCollator(((RuleBasedCollator) baseCollator).getRules()
+                            + "& ')' < ',' < '.','['");
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            return baseCollator;
+        }
     }
 
     private Comparator<Element> moduleComparator = null;