langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
changeset 43570 c7b68caf3ab4
parent 43261 d377e97291d8
child 43868 cdf2965de35b
--- 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;
                 }