changeset 55316:85ccac8a8c13

8219060: -linksource broken with modules Reviewed-by: jjg
author hannesw
date Mon, 13 May 2019 16:43:47 +0200
parents fcf83b204c27
children f542a3a135bd
files src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java test/langtools/jdk/javadoc/doclet/testModules/TestModules.java test/langtools/jdk/javadoc/doclet/testOptions/TestOptions.java
diffstat 4 files changed, 97 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java	Fri Apr 05 11:52:32 2019 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java	Mon May 13 16:43:47 2019 +0200
@@ -31,6 +31,7 @@
 import java.util.List;
 
 import javax.lang.model.element.Element;
+import javax.lang.model.element.ModuleElement;
 import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
 import javax.tools.FileObject;
@@ -121,6 +122,12 @@
         if (docEnv == null || outputdir == null) {
             return;
         }
+        for (ModuleElement mdl : configuration.getSpecifiedModuleElements()) {
+            // If -nodeprecated option is set and the module is marked as deprecated,
+            // do not convert the module files to HTML.
+            if (!(configuration.nodeprecated && utils.isDeprecated(mdl)))
+                convertModule(mdl, outputdir);
+        }
         for (PackageElement pkg : configuration.getSpecifiedPackageElements()) {
             // If -nodeprecated option is set and the package is marked as deprecated,
             // do not convert the package files to HTML.
@@ -161,6 +168,27 @@
     }
 
     /**
+     * Convert the documented packages contained in the given module to an HTML representation.
+     *
+     * @param mdl the module to convert.
+     * @param outputdir the name of the directory to output to.
+     * @throws DocFileIOException if there is a problem generating an output file
+     * @throws SimpleDocletException if there is a problem reading a source file
+     */
+    public void convertModule(ModuleElement mdl, DocPath outputdir)
+            throws DocFileIOException, SimpleDocletException {
+        if (mdl == null) {
+            return;
+        }
+        for (Element elem : mdl.getEnclosedElements()) {
+            if (elem instanceof PackageElement && configuration.docEnv.isIncluded(elem)
+                    && !(configuration.nodeprecated && utils.isDeprecated(elem))) {
+                convertPackage((PackageElement) elem, outputdir);
+            }
+        }
+    }
+
+    /**
      * Convert the given Class to an HTML.
      *
      * @param te the class to convert.
--- a/test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java	Fri Apr 05 11:52:32 2019 +0200
+++ b/test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java	Mon May 13 16:43:47 2019 +0200
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8218998 8219946
+ * @bug 8218998 8219946 8219060
  * @summary Add metadata to generated API documentation files
  * @library /tools/lib ../../lib
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -72,9 +72,7 @@
                      args.add("-d");
                      args.add(String.format("out-%s-%s", s, i));
                      args.add("-use");
-                     if (s != Source.MODULES) {
-                         args.add("-linksource"); // broken, with modules: JDK-8219060
-                     }
+                     args.add("-linksource");
                      if (i == Index.SPLIT) {
                          args.add("-splitIndex");
                      }
--- a/test/langtools/jdk/javadoc/doclet/testModules/TestModules.java	Fri Apr 05 11:52:32 2019 +0200
+++ b/test/langtools/jdk/javadoc/doclet/testModules/TestModules.java	Mon May 13 16:43:47 2019 +0200
@@ -27,7 +27,7 @@
  *      8168766 8168688 8162674 8160196 8175799 8174974 8176778 8177562 8175218
  *      8175823 8166306 8178043 8181622 8183511 8169819 8074407 8183037 8191464
         8164407 8192007 8182765 8196200 8196201 8196202 8196202 8205593 8202462
-        8184205
+        8184205 8219060
  * @summary Test modules support in javadoc.
  * @author bpatel
  * @library ../../lib
@@ -423,6 +423,39 @@
         checkLinkOffline();
     }
 
+    /**
+     * Test -linksource option.
+     */
+    @Test
+    public void testLinkSource() {
+        javadoc("-d", "out-linksource",
+                "-use",
+                "-linksource",
+                "-Xdoclint:none",
+                "--module-source-path", testSrc,
+                "--module", "moduleA,moduleB");
+        checkExit(Exit.OK);
+        checkLinks();
+        checkLinkSource(false);
+    }
+
+    /**
+     * Test -linksource option combined with -private.
+     */
+    @Test
+    public void testLinkSourcePrivate() {
+        javadoc("-d", "out-linksource-private",
+                "-use",
+                "-private",
+                "-linksource",
+                "-Xdoclint:none",
+                "--module-source-path", testSrc,
+                "--module", "moduleA,moduleB");
+        checkExit(Exit.OK);
+        checkLinks();
+        checkLinkSource(true);
+    }
+
     void checkDescription(boolean found) {
         checkOutput("moduleA/module-summary.html", found,
                 "<!-- ============ MODULE DESCRIPTION =========== -->\n"
@@ -1239,7 +1272,38 @@
         checkOutput("moduleB/testpkg3mdlB/package-summary.html", true,
                 "<a href=\"https://docs.oracle.com/javase/9/docs/api/java.base/module-summary.html?is-external=true\" "
                 + "class=\"externalLink\"><code>Link to java.base module</code></a>");
-}
+    }
+
+    void checkLinkSource(boolean includePrivate) {
+        checkOutput("moduleA/module-summary.html", !includePrivate,
+                "<table>\n<caption><span>Exports</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
+                + "<thead>\n<tr>\n<th class=\"colFirst\" scope=\"col\">Package</th>\n"
+                + "<th class=\"colLast\" scope=\"col\">Description</th>\n</tr>\n</thead>\n"
+                + "<tbody>\n<tr class=\"altColor\" id=\"i0\">\n"
+                + "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdlA/package-summary.html\">testpkgmdlA</a></th>\n"
+                + "<td class=\"colLast\">&nbsp;</td>\n</tr>\n</tbody>\n</table>");
+        checkOutput("moduleA/testpkgmdlA/TestClassInModuleA.html", true,
+                "<section class=\"description\">\n<hr>\n"
+                + "<pre>public class <a href=\"../../src-html/moduleA/testpkgmdlA/TestClassInModuleA.html#line.25\">"
+                + "TestClassInModuleA</a>\nextends java.lang.Object</pre>\n</section>");
+        checkOutput("src-html/moduleA/testpkgmdlA/TestClassInModuleA.html", true,
+                "<span class=\"sourceLineNo\">019</span><a id=\"line.19\"> * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA</a>\n"
+                + "<span class=\"sourceLineNo\">020</span><a id=\"line.20\"> * or visit www.oracle.com if you need additional information or have any</a>\n"
+                + "<span class=\"sourceLineNo\">021</span><a id=\"line.21\"> * questions.</a>\n"
+                + "<span class=\"sourceLineNo\">022</span><a id=\"line.22\"> */</a>\n"
+                + "<span class=\"sourceLineNo\">023</span><a id=\"line.23\">package testpkgmdlA;</a>\n"
+                + "<span class=\"sourceLineNo\">024</span><a id=\"line.24\"></a>\n"
+                + "<span class=\"sourceLineNo\">025</span><a id=\"line.25\">public class TestClassInModuleA {</a>\n"
+                + "<span class=\"sourceLineNo\">026</span><a id=\"line.26\">}</a>");
+        if (includePrivate) {
+            checkOutput("src-html/moduleA/concealedpkgmdlA/ConcealedClassInModuleA.html", true,
+                    "<span class=\"sourceLineNo\">024</span><a id=\"line.24\">package concealedpkgmdlA;</a>\n"
+                    + "<span class=\"sourceLineNo\">025</span><a id=\"line.25\"></a>\n"
+                    + "<span class=\"sourceLineNo\">026</span><a id=\"line.26\">public class ConcealedClassInModuleA {</a>\n"
+                    + "<span class=\"sourceLineNo\">027</span><a id=\"line.27\">    public void testMethodConcealedClass() { }</a>\n"
+                    + "<span class=\"sourceLineNo\">028</span><a id=\"line.28\">}</a>");
+        }
+    }
 
     void checkAllPkgsAllClasses(boolean found) {
         checkOutput("allclasses-index.html", true,
--- a/test/langtools/jdk/javadoc/doclet/testOptions/TestOptions.java	Fri Apr 05 11:52:32 2019 +0200
+++ b/test/langtools/jdk/javadoc/doclet/testOptions/TestOptions.java	Mon May 13 16:43:47 2019 +0200
@@ -188,7 +188,7 @@
                 "-package",
                 "linksource");
         checkExit(Exit.OK);
-
+        checkLinks();
         checkOutput("linksource/AnnotationTypeField.html", true,
                 "<pre>@Documented\npublic @interface <a href="
                 + "\"../src-html/linksource/AnnotationTypeField.html#line.31\">"