8042601: Javadoc sort fails
authorksrini
Thu, 08 May 2014 08:23:44 -0700
changeset 24394 74279778c307
parent 24393 381ade32a034
child 24395 5c541aef1350
8042601: Javadoc sort fails Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
langtools/test/com/sun/javadoc/testOrdering/TestOrdering.java
langtools/test/com/sun/javadoc/testOrdering/pkg1/UsedClass.java
langtools/test/com/sun/javadoc/testOrdering/pkg1/ZZTop.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Fri May 09 12:55:58 2014 +0200
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Thu May 08 08:23:44 2014 -0700
@@ -878,8 +878,9 @@
      */
     static abstract class DocComparator<T extends Doc> implements Comparator<Doc> {
         /**
-         * compares two parameter arrays by first comparing the length of the arrays, and
-         * then each Type of the parameter in the array.
+         * compares two parameter arrays by comparing each Type of the parameter in the array,
+         * as possible, if the matched strings are identical, and  have mismatched array lengths
+         * then compare the lengths.
          * @param params1 the first parameter array.
          * @param params2 the first parameter array.
          * @return a negative integer, zero, or a positive integer as the first
@@ -889,17 +890,14 @@
             if (params1.length == 0 && params2.length == 0) {
                 return 0;
             }
-            int result = Integer.compare(params1.length, params2.length);
-            if (result != 0) {
-                return result;
-            }
-            for (int i = 0; i < params1.length; i++) {
-                result = compareStrings(params1[i].typeName(), params2[i].typeName());
+            // try to compare as many as possible
+            for (int i = 0; i < params1.length && i < params2.length; i++) {
+                int result = compareStrings(params1[i].typeName(), params2[i].typeName());
                 if (result != 0) {
                     return result;
                 }
             }
-            return 0;
+            return Integer.compare(params1.length, params2.length);
         }
 
         /**
--- a/langtools/test/com/sun/javadoc/testOrdering/TestOrdering.java	Fri May 09 12:55:58 2014 +0200
+++ b/langtools/test/com/sun/javadoc/testOrdering/TestOrdering.java	Thu May 08 08:23:44 2014 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8039410
+ * @bug 8039410 8042601
  * @summary test to determine if members are ordered correctly
  * @author ksrini
  * @library ../lib/
@@ -108,19 +108,28 @@
 
     static void checkIndexPathOrdering(String indexPage) {
         String[] OrderedExpectedStrings = {
-            "pkg1/UsedClass.html#add-java.lang.Double",
-            "pkg1/ZZTop.html#add-double",
-            "pkg1/ZZTop.html#add-java.lang.Double",
-            "pkg1/UsedClass.html#add-float",
-            "pkg1/ZZTop.html#add-float",
-            "pkg1/UsedClass.html#add-int",
-            "pkg1/ZZTop.html#add-int",
-            "pkg1/UsedClass.html#add-java.lang.Integer",
-            "pkg1/ZZTop.html#add-java.lang.Integer",
-            "pkg1/UsedClass.html#add-double-double",
-            "pkg1/UsedClass.html#add-double-java.lang.Double",
-            "pkg1/ZZTop.html#add-double-double",
-            "pkg1/ZZTop.html#add-double-java.lang.Double"
+            "pkg1/UsedClass.html#add--",
+            "pkg1/ZZTop.html#add--",
+            "pkg1/UsedClass.html#add-double-",
+            "pkg1/UsedClass.html#add-java.lang.Double-",
+            "pkg1/ZZTop.html#add-double-",
+            "pkg1/ZZTop.html#add-java.lang.Double-",
+            "pkg1/UsedClass.html#add-double-byte-",
+            "pkg1/ZZTop.html#add-double-byte-",
+            "pkg1/UsedClass.html#add-double-double-",
+            "pkg1/UsedClass.html#add-double-java.lang.Double-",
+            "pkg1/ZZTop.html#add-double-double-",
+            "pkg1/ZZTop.html#add-double-java.lang.Double-",
+            "pkg1/UsedClass.html#add-float-",
+            "pkg1/ZZTop.html#add-float-",
+            "pkg1/UsedClass.html#add-float-int-",
+            "pkg1/ZZTop.html#add-float-int-",
+            "pkg1/UsedClass.html#add-int-",
+            "pkg1/ZZTop.html#add-int-",
+            "pkg1/UsedClass.html#add-int-float-",
+            "pkg1/ZZTop.html#add-int-float-",
+            "pkg1/UsedClass.html#add-java.lang.Integer-",
+            "pkg1/ZZTop.html#add-java.lang.Integer-"
         };
         int lastidx = 0;
         for (String x : OrderedExpectedStrings) {
--- a/langtools/test/com/sun/javadoc/testOrdering/pkg1/UsedClass.java	Fri May 09 12:55:58 2014 +0200
+++ b/langtools/test/com/sun/javadoc/testOrdering/pkg1/UsedClass.java	Thu May 08 08:23:44 2014 -0700
@@ -26,18 +26,11 @@
  * For index and class-use testing
  */
 public class UsedClass {
-    // This is the exact order we expect to see
 
     /**
-     * @param i param
+     * just an empty param method.
      */
-    public void   add(int i){}
-
-    /**
-     * @param i param
-     * @return double
-     */
-    public int    add(Integer i) {return 0;}
+    public void   add(){}
 
     /**
      * @param d param
@@ -45,18 +38,30 @@
     public void   add(double d){}
 
     /**
+     * @param i param
+     * @param f param
+     */
+    public void   add(int i, float f){}
+
+    /**
+     * @param f param
+     * @param i param
+     */
+    public void   add(float f, int i){}
+
+    /**
+     * @param d param
+     * @param b param
+     */
+    public void   add(double d, byte b){}
+
+    /**
      * @param d param
      * @return Double
      */
     public Double add(Double d) {return (double) 22/7;}
 
     /**
-     * @param f param
-     * @return Float
-     */
-    public Float  add(float f) {return (float) 22/7;}
-
-    /**
      * @param d1 param
      * @param d2 param
      * @return double
@@ -69,4 +74,21 @@
      * @return double
      */
     public double add(double d1, Double  d2) {return d1 + d2;}
+
+    /**
+     * @param f param
+     * @return Float
+     */
+    public Float  add(float f) {return (float) 22/7;}
+
+    /**
+     * @param i param
+     */
+    public void   add(int i){}
+
+    /**
+     * @param i param
+     * @return double
+     */
+    public int    add(Integer i) {return 0;}
 }
--- a/langtools/test/com/sun/javadoc/testOrdering/pkg1/ZZTop.java	Fri May 09 12:55:58 2014 +0200
+++ b/langtools/test/com/sun/javadoc/testOrdering/pkg1/ZZTop.java	Thu May 08 08:23:44 2014 -0700
@@ -26,18 +26,11 @@
  * For index testing only
  */
 public class ZZTop {
-    // This is the exact order we expect to see
 
     /**
-     * @param i param
+     * just an empty param method.
      */
-    public void   add(int i){}
-
-    /**
-     * @param i param
-     * @return double
-     */
-    public int    add(Integer i) {return 0;}
+    public void   add(){}
 
     /**
      * @param d param
@@ -45,17 +38,30 @@
     public void   add(double d){}
 
     /**
+     * @param i param
+     * @param f param
+     */
+    public void   add(int i, float f){}
+
+    /**
+     * @param f param
+     * @param i param
+     */
+    public void   add(float f, int i){}
+
+    /**
+     * @param d param
+     * @param b param
+     */
+    public void   add(double d, byte b){}
+
+    /**
      * @param d param
      * @return Double
      */
     public Double add(Double d) {return (double) 22/7;}
 
     /**
-     * @param f param
-     * @return Float
-     */
-    public Float  add(float f) {return (float) 22/7;}
-    /**
      * @param d1 param
      * @param d2 param
      * @return double
@@ -68,4 +74,21 @@
      * @return double
      */
     public double add(double d1, Double  d2) {return d1 + d2;}
+
+    /**
+     * @param f param
+     * @return Float
+     */
+    public Float  add(float f) {return (float) 22/7;}
+
+    /**
+     * @param i param
+     */
+    public void   add(int i){}
+
+    /**
+     * @param i param
+     * @return double
+     */
+    public int    add(Integer i) {return 0;}
 }