8192933: Wrong generic type parameter in serialized form javadoc
authorksrini
Wed, 06 Dec 2017 15:14:13 -0800
changeset 48087 f5d7096cfdc0
parent 48086 50ddd5e1ede1
child 48196 5ee29f4ec472
8192933: Wrong generic type parameter in serialized form javadoc Reviewed-by: jjg
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialFieldWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java
test/langtools/jdk/javadoc/doclet/testSerializedForm/TestSerializedForm.java
test/langtools/jdk/javadoc/doclet/testSerializedForm/pkg2/Fields.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialFieldWriter.java	Wed Dec 06 14:39:15 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialFieldWriter.java	Wed Dec 06 15:14:13 2017 -0800
@@ -29,6 +29,7 @@
 
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeMirror;
 
 import com.sun.source.doctree.DocTree;
 
@@ -115,18 +116,10 @@
         return li;
     }
 
-    /**
-     * Add the member header.
-     *
-     * @param fieldType the class document to be listed
-     * @param fieldTypeStr the string for the field type to be documented
-     * @param fieldDimensions the dimensions of the field string to be added
-     * @param fieldName name of the field to be added
-     * @param contentTree the content tree to which the member header will be added
-     */
+    @Override
     public void addMemberHeader(TypeElement fieldType, String fieldTypeStr,
             String fieldDimensions, String fieldName, Content contentTree) {
-        Content nameContent = new RawHtml(fieldName);
+        Content nameContent = new StringContent(fieldName);
         Content heading = HtmlTree.HEADING(HtmlConstants.MEMBER_HEADING, nameContent);
         contentTree.addContent(heading);
         Content pre = new HtmlTree(HtmlTag.PRE);
@@ -142,6 +135,20 @@
         contentTree.addContent(pre);
     }
 
+    @Override
+    public void addMemberHeader(TypeMirror fieldType, String fieldName, Content contentTree) {
+        Content nameContent = new StringContent(fieldName);
+        Content heading = HtmlTree.HEADING(HtmlConstants.MEMBER_HEADING, nameContent);
+        contentTree.addContent(heading);
+        Content pre = new HtmlTree(HtmlTag.PRE);
+        Content fieldContent = writer.getLink(new LinkInfoImpl(
+                configuration, LinkInfoImpl.Kind.SERIAL_MEMBER, fieldType));
+        pre.addContent(fieldContent);
+        pre.addContent(" ");
+        pre.addContent(fieldName);
+        contentTree.addContent(pre);
+    }
+
     /**
      * Add the deprecated information for this member.
      *
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java	Wed Dec 06 14:39:15 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java	Wed Dec 06 15:14:13 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -28,6 +28,7 @@
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeMirror;
 
 import com.sun.source.doctree.DocTree;
 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
@@ -227,8 +228,8 @@
          * Adds the member header.
          *
          * @param fieldType the type of the field
-         * @param fieldTypeStr the type of the field in string format.  We will
-         * print this out if we can't link to the type
+         * @param fieldTypeStr the type of the field in string format, used
+         *                     only if the type cannot be linked
          * @param fieldDimensions the dimensions of the field
          * @param fieldName the name of the field
          * @param contentTree content tree to which the member header will be added
@@ -237,6 +238,15 @@
             String fieldDimensions, String fieldName, Content contentTree);
 
         /**
+         * Adds the member header.
+         *
+         * @param fieldType the type of the field
+         * @param fieldName the name of the field
+         * @param contentTree content tree to which the member header will be added
+         */
+        public void addMemberHeader(TypeMirror fieldType, String fieldName, Content contentTree);
+
+        /**
          * Check to see if overview details should be printed. If
          * nocomment option set or if there is no text to be printed
          * for deprecation info, inline comment or tags,
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java	Wed Dec 06 14:39:15 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java	Wed Dec 06 15:14:13 2017 -0800
@@ -450,8 +450,7 @@
     protected void buildFieldSubHeader(Content fieldsContentTree) {
         if (!utils.definesSerializableFields(currentTypeElement)) {
             VariableElement field = (VariableElement) currentMember;
-            fieldWriter.addMemberHeader(utils.asTypeElement(field.asType()),
-                    utils.getTypeName(field.asType(), false), utils.getDimension(field.asType()),
+            fieldWriter.addMemberHeader(field.asType(),
                     utils.getSimpleName(field),
                     fieldsContentTree);
         }
--- a/test/langtools/jdk/javadoc/doclet/testSerializedForm/TestSerializedForm.java	Wed Dec 06 14:39:15 2017 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testSerializedForm/TestSerializedForm.java	Wed Dec 06 15:14:13 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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 4341304 4485668 4966728 8032066 8071982
+ * @bug 4341304 4485668 4966728 8032066 8071982 8192933
  * @summary Test that methods readResolve and writeReplace show
  * up in serialized-form.html the same way that readObject and writeObject do.
  * If the doclet includes readResolve and writeReplace in the serialized-form
@@ -114,4 +114,21 @@
                 + "title=\"class in pkg1\">pkg1.PublicExcludeInnerClass.PubInnerClass</a> "
                 + "extends java.lang.Object implements Serializable</h3>");
     }
+
+    @Test
+    void test2() {
+        javadoc("-private",
+                "-d", "out-2",
+                "-sourcepath", testSrc,
+                "pkg2");
+        checkExit(Exit.OK);
+
+        checkOrder("serialized-form.html",
+                "int[] a1",
+                "int[][] a2",
+                "<a href=\"pkg2/Fields.html\" title=\"class in pkg2\">Fields</a>[][] doubleArray",
+                "<a href=\"pkg2/Fields.html\" title=\"class in pkg2\">Fields</a>[] singleArray",
+                "java.lang.Class&lt;<a href=\"pkg2/Fields.html\" "
+                + "title=\"type parameter in Fields\">E</a>&gt; someClass");
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testSerializedForm/pkg2/Fields.java	Wed Dec 06 15:14:13 2017 -0800
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg2;
+
+public class Fields<E> implements java.io.Serializable {
+    /** Some doc. */
+    public Class<E> someClass;
+
+    /** a primitive array */
+    private int[] a1;
+
+    /** a two dimensional primitive array */
+    private int[][] a2;
+
+    /** a single object array */
+    private Fields[] singleArray;
+
+    /** a double object array */
+    private Fields[][] doubleArray;
+
+}