8048351: tidy errors for attribute href, name for langtools javadoc tests needs investigation
authorbpatel
Fri, 26 Sep 2014 13:51:43 -0700
changeset 26900 dccc7a72526d
parent 26786 f0c5e4b732da
child 26901 2c11dc81a5c8
8048351: tidy errors for attribute href, name for langtools javadoc tests needs investigation Reviewed-by: jjg
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java
langtools/test/com/sun/javadoc/testPackageDeprecation/TestPackageDeprecation.java
langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Wed Jul 05 20:02:40 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Fri Sep 26 13:51:43 2014 -0700
@@ -333,7 +333,7 @@
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
         ul.addStyle(HtmlStyle.blockList);
         for (PackageDoc pkg : pkgSet) {
-            Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(pkg.name()));
+            Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(getPackageAnchorName(pkg)));
             Content link = getResource("doclet.ClassUse_Uses.of.0.in.1",
                                        getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
                                                                 classdoc)),
@@ -355,7 +355,7 @@
      */
     protected void addPackageUse(PackageDoc pkg, Content contentTree) throws IOException {
         Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
-                getHyperLink(pkg.name(), new StringContent(utils.getPackageName(pkg))));
+                getHyperLink(getPackageAnchorName(pkg), new StringContent(utils.getPackageName(pkg))));
         contentTree.addContent(tdFirst);
         HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
         tdLast.addStyle(HtmlStyle.colLast);
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Jul 05 20:02:40 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri Sep 26 13:51:43 2014 -0700
@@ -992,6 +992,16 @@
     }
 
     /**
+     * Given a package, return the name to be used in HTML anchor tag.
+     * @param packageDoc the package.
+     * @return the name to be used in HTML anchor tag.
+     */
+    public String getPackageAnchorName(PackageDoc packageDoc) {
+        return packageDoc == null || packageDoc.name().length() == 0 ?
+            SectionName.UNNAMED_PACKAGE_ANCHOR.getName() : packageDoc.name();
+    }
+
+    /**
      * Return the link to the given package.
      *
      * @param pkg the package to link to.
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java	Wed Jul 05 20:02:40 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java	Fri Sep 26 13:51:43 2014 -0700
@@ -207,7 +207,7 @@
                 } else {
                     tr.addStyle(HtmlStyle.rowColor);
                 }
-                addClassRow(itc.next(), packageName, tr);
+                addClassRow(itc.next(), usingPackage, tr);
                 tbody.addContent(tr);
             }
             table.addContent(tbody);
@@ -220,15 +220,15 @@
      * Add a row for the class that uses the given package.
      *
      * @param usedClass the class that uses the given package
-     * @param packageName the name of the package to which the class belongs
+     * @param pkg the package to which the class belongs
      * @param contentTree the content tree to which the row will be added
      */
-    protected void addClassRow(ClassDoc usedClass, String packageName,
+    protected void addClassRow(ClassDoc usedClass, PackageDoc pkg,
             Content contentTree) {
         DocPath dp = pathString(usedClass,
                 DocPaths.CLASS_USE.resolve(DocPath.forName(usedClass)));
         Content td = HtmlTree.TD(HtmlStyle.colOne,
-                getHyperLink(dp.fragment(packageName), new StringContent(usedClass.name())));
+                getHyperLink(dp.fragment(getPackageAnchorName(pkg)), new StringContent(usedClass.name())));
         addIndexComment(usedClass, td);
         contentTree.addContent(td);
     }
--- a/langtools/test/com/sun/javadoc/testPackageDeprecation/TestPackageDeprecation.java	Wed Jul 05 20:02:40 2017 +0200
+++ b/langtools/test/com/sun/javadoc/testPackageDeprecation/TestPackageDeprecation.java	Fri Sep 26 13:51:43 2014 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      6492694 8026567
+ * @bug      6492694 8026567 8048351
  * @summary  Test package deprecation.
  * @author   bpatel
  * @library  ../lib/
@@ -70,6 +70,8 @@
                 "pkg1");
         checkOutput("allclasses-frame.html", false,
                 "FooDepr");
+        checkOutput("class-use/C2.ModalExclusionType.html", true,
+                "<td class=\"colFirst\"><a href=\"#unnamed.package\">&lt;Unnamed&gt;</a></td>");
 
         checkFiles(false,
                 "pkg1/package-summary.html",
--- a/langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java	Wed Jul 05 20:02:40 2017 +0200
+++ b/langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java	Fri Sep 26 13:51:43 2014 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4496290 4985072 7006178 7068595 8016328 8050031
+ * @bug 4496290 4985072 7006178 7068595 8016328 8050031 8048351
  * @summary A simple test to ensure class-use files are correct.
  * @author jamieh
  * @library ../lib
@@ -134,9 +134,12 @@
                 "Uses of <a href=\"../UsedInC.html\" title=\"class in &lt;Unnamed&gt;\">"
                 + "UsedInC</a> in <a href=\"../package-summary.html\">&lt;Unnamed&gt;</a>"
         );
+        checkOutput("class-use/UsedInC.html", true,
+                "<li class=\"blockList\"><a name=\"unnamed.package\">"
+        );
         checkOutput("package-use.html", true,
                 "<td class=\"colOne\">"
-                + "<a href=\"class-use/UsedInC.html#%3CUnnamed%3E\">UsedInC</a>&nbsp;</td>"
+                + "<a href=\"class-use/UsedInC.html#unnamed.package\">UsedInC</a>&nbsp;</td>"
         );
     }