changeset 43570:c7b68caf3ab4

8169813: The index pages are sorted in a confusing manner Reviewed-by: jjg, ksrini
author bpatel
date Wed, 01 Feb 2017 15:16:49 -0800
parents 717da20a1807
children a153580d1741
files langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java langtools/test/jdk/javadoc/doclet/testOrdering/TestOrdering.java
diffstat 2 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Wed Feb 01 14:38:45 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Wed Feb 01 15:16:49 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1773,14 +1773,14 @@
     /**
      * Returns a Comparator for index file presentations, and are sorted as follows.
      *  If comparing modules then simply compare the simple names,
-     *  comparing packages then simply compare the qualified names, otherwise
-     *  1. if equal, then compare the ElementKind ex: Module, Package, Interface etc.
-     *  2. sort on simple names of entities
-     *  3a. if equal and if the type is of ExecutableElement(Constructor, Methods),
+     *  comparing packages then simply compare the qualified names, if comparing a package with a
+     *  module/type/member then compare the FullyQualifiedName of the package
+     *  with the SimpleName of the entity, otherwise
+     *  1. compare the ElementKind ex: Module, Package, Interface etc.
+     *  2a. if equal and if the type is of ExecutableElement(Constructor, Methods),
      *      a case insensitive comparison of parameter the type signatures
-     *  3b. if equal, case sensitive comparison of the type signatures
-     *  4. finally, if equal, compare the FQNs of the entities
-     * Iff comparing packages then simply sort on qualified names.
+     *  2b. if equal, case sensitive comparison of the type signatures
+     *  3. finally, if equal, compare the FQNs of the entities
      * @return a comparator for index file use
      */
     public Comparator<Element> makeIndexUseComparator() {
@@ -1788,8 +1788,10 @@
             /**
              * Compare two given elements, if comparing two modules, return the
              * comparison of SimpleName, if comparing two packages, return the
-             * comparison of FullyQualifiedName, first sort on kinds, then on the
-             * names, then on the parameters only if the type is an ExecutableElement,
+             * comparison of FullyQualifiedName, if comparing a package with a
+             * module/type/member then compare the FullyQualifiedName of the package
+             * with the SimpleName of the entity, then sort on the kinds, then on
+             * the parameters only if the type is an ExecutableElement,
              * the parameters are compared and finally the qualified names.
              *
              * @param e1 - an element.
@@ -1806,11 +1808,17 @@
                 if (isPackage(e1) && isPackage(e2)) {
                     return compareFullyQualifiedNames(e1, e2);
                 }
-                result = compareElementTypeKinds(e1, e2);
+                if (isPackage(e1) || isPackage(e2)) {
+                    result = (isPackage(e1))
+                            ? compareStrings(getFullyQualifiedName(e1), getSimpleName(e2))
+                            : compareStrings(getSimpleName(e1), getFullyQualifiedName(e2));
+                } else {
+                    result = compareNames(e1, e2);
+                }
                 if (result != 0) {
                     return result;
                 }
-                result = compareNames(e1, e2);
+                result = compareElementTypeKinds(e1, e2);
                 if (result != 0) {
                     return result;
                 }
--- a/langtools/test/jdk/javadoc/doclet/testOrdering/TestOrdering.java	Wed Feb 01 14:38:45 2017 -0800
+++ b/langtools/test/jdk/javadoc/doclet/testOrdering/TestOrdering.java	Wed Feb 01 15:16:49 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8039410 8042601 8042829 8049393 8050031 8155061 8155995 8167967
+ * @bug 8039410 8042601 8042829 8049393 8050031 8155061 8155995 8167967 8169813
  * @summary test to determine if members are ordered correctly
  * @library ../lib/
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -494,23 +494,23 @@
         String[] composeTestVectors() {
             List<String> testList = new ArrayList<>();
 
-            testList.addAll(Arrays.asList(expectedPackageOrdering));
             for (String x : expectedEnumOrdering) {
                 testList.add(x.replace("REPLACE_ME", "&lt;Unnamed&gt;"));
-                for (int i = 0; i < MAX_PACKAGES; i++) {
-                    String wpkg = "add" + i;
-                    testList.add(wpkg + "/" + x.replace("REPLACE_ME",
-                            wpkg));
-                    String dpkg = wpkg;
-                    for (int j = 1; j < MAX_SUBPACKAGES_DEPTH; j++) {
-                        dpkg = dpkg + "/" + "add";
+            }
+            for (int i = 0; i < MAX_PACKAGES; i++) {
+                String wpkg = "add" + i;
+                for (String x : expectedEnumOrdering) {
+                    testList.add(wpkg + "/" + x.replace("REPLACE_ME", wpkg));
+                }
+                String dpkg = wpkg;
+                for (int j = 1; j < MAX_SUBPACKAGES_DEPTH; j++) {
+                    dpkg = dpkg + "/" + "add";
+                    for (String x : expectedEnumOrdering) {
                         testList.add(dpkg + "/" + x.replace("REPLACE_ME", pathToPackage(dpkg)));
                     }
                 }
             }
 
-            testList.addAll(Arrays.asList(expectedFieldOrdering));
-
             for (String x : expectedMethodOrdering) {
                 testList.add(x);
                 for (int i = 0; i < MAX_PACKAGES; i++) {
@@ -523,6 +523,8 @@
                     }
                 }
             }
+            testList.addAll(Arrays.asList(expectedPackageOrdering));
+            testList.addAll(Arrays.asList(expectedFieldOrdering));
 
             return testList.toArray(new String[testList.size()]);
         }