/* * Copyright (c) 2022, 2024, 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. */ /* * @test * @bug 8298405 * @summary Markdown support in the standard doclet * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * @build toolbox.ToolBox javadoc.tester.* * @run main TestMarkdownFirstSentence */ import javadoc.tester.JavadocTester; import toolbox.ToolBox; import java.nio.file.Path; import java.util.List; public class TestMarkdownFirstSentence extends JavadocTester { public static void main(String... args) throws Exception { var tester = new TestMarkdownFirstSentence(); tester.runTests(); } ToolBox tb = new ToolBox(); @Test public void testFirstSentence(Path base) throws Exception { Path src = base.resolve("src"); tb.writeJavaFiles(src, """ package p; public class C { /// This is the _first_ sentence. /// This is the _second_ sentence. public void m() { } } """); javadoc("-d", base.resolve("api").toString(), "-Xdoclint:none", "--source-path", src.toString(), "p"); checkOrder("p/C.html", """
""", """
This is the first sentence.
""", """
""", """
This is the first sentence. This is the second sentence.
"""); } // Test the ability to put links in the first sentence of a description. // Note that user-defined reference links cannot be used in the first // sentence, and so in that case we verify the behavior is "as expected". @Test public void testFirstSentenceLinks(Path base) throws Exception { Path src = base.resolve("src"); // Apart from the (control) case, the other cases exercise // various kinds of links in the first sentence of a description. // Note the last case is an explicit test of a link that is // _not_ currently supported, since the link reference definition // is not part of the first sentence. tb.writeJavaFiles(src, """ package p; import q.MyObject; public class C { /// First sentence. /// Control: [MyObject] public void m1() { } /// Simple autoref in first sentence [MyObject]. /// More. public void m2() { } /// Qualified autoref in first sentence [q.MyObject]. /// More. public void m3() { } /// Standard link with periods [example.com](http://example.com). /// More. public void m4() { } /// Manual ref link [foo]. /// More. /// /// [foo]: http:example.com public void m5() { } }""", // use a simple class in a different package, to avoid platform links to system classes """ package q; public class MyObject { }"""); javadoc("-d", base.resolve("api").toString(), "-Xdoclint:none", "--source-path", src.toString(), "p", "q"); checkExit(Exit.OK); // use checkOrder and the delimiter comments to ensure that // we check the strings in the method summary table, and not // subsequently in the method details section. checkOrder("p/C.html", "", """
Simple autoref in first sentence MyObject.
""", """
Qualified autoref in first sentence MyObject.
""", """
Standard link with periods \ example.com.
""", // The following is a test of the regrettably expected behavior, // because the link reference definition is not carried into // the first sentence. """
Manual ref link [foo].
""", "" ); } // Test that periods within certain constructs do not prematurely terminate // the first sentence. @Test public void testFirstSentencePeriods(Path base) throws Exception { testFirstSentencePeriods(base.resolve("no-bi"), false); testFirstSentencePeriods(base.resolve("bi"), true); } void testFirstSentencePeriods(Path base, boolean useBreakIterator) throws Exception { Path src = base.resolve("src"); tb.writeJavaFiles(src, """ package p; public class C { /// Code span `1.0` end. /// More. public void m1() { } /// Complex code span ``` `1.0` ``` end. /// More. public void m2() { } /// Period space `1. 2. 3.` end. /// More. public void m3() { } /// Link [example.com](http://example.com) end. /// More. public void m4() { } } """); javadoc("-d", base.resolve("api").toString(), "-Xdoclint:none", (useBreakIterator ? "-breakiterator" : "-XDdummy"), "--source-path", src.toString(), "p"); checkExit(Exit.OK); // use checkOrder and the delimiter comments to ensure that // we check the strings in the method summary table, and not // subsequently in the method details section. checkOrder("p/C.html", "", """
Code span 1.0 end.
""", """
Complex code span `1.0` end.
""", """
Period space 1. 2. 3. end.
""", """
Link example.com end.
""", "" ); } @Test public void testIndentedInlineReturn(Path base) throws Exception { //this is a Markdown-specific test, because leading whitespace is ignored in HTML comments Path src = base.resolve("src"); tb.writeJavaFiles(src, """ package p; /// Class description. public class C { /// {@return an int} /// More description. public int m() { return 0; } } """); javadoc("-d", base.resolve("api").toString(), "--source-path", src.toString(), "p"); checkOutput("p/C.html", true, """

m

public int m()
Returns an int. More description.
Returns:
an int
"""); } @Test public void testExtraPara(Path base) throws Exception { Path src = base.resolve("src"); tb.writeJavaFiles(src, """ package p; /// This is the class description. /// /// # Heading /// Lorem ipsum public class C { } """); javadoc("-d", base.resolve("api").toString(), "--no-platform-links", "--source-path", src.toString(), "p"); checkOutput("p/package-summary.html", true, """
This is the class description.
"""); checkOutput("p/C.html", true, """ C extends java.lang.Object

This is the class description.

Heading

Lorem ipsum

"""); } }