/* * Copyright (c) 2022, 2025, 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 8200337 8307377 8306578 * @summary Generalize see and link tags for user-defined anchors * @library /tools/lib ../../lib * @modules * jdk.javadoc/jdk.javadoc.internal.tool * jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main * @build javadoc.tester.* * @run main TestSeeLinkAnchor */ import java.nio.file.Path; import java.nio.file.Paths; import builder.ClassBuilder; import builder.ClassBuilder.*; import toolbox.ModuleBuilder; import toolbox.ToolBox; import javadoc.tester.JavadocTester; public class TestSeeLinkAnchor extends JavadocTester { final ToolBox tb; private final Path src; public static void main(String... args) throws Exception { var tester = new TestSeeLinkAnchor(); tester.runTests(); } TestSeeLinkAnchor() throws Exception { tb = new ToolBox(); src = Paths.get("src"); generateModuleSources(); generatePackageSources(); generateInvalidLinkSource(); generateMissingLabelSource(); } @Test public void testPackage(Path base) throws Exception { Path out = base.resolve("out"); javadoc("-d", out.toString(), "-sourcepath", src.toString(), "--no-platform-links", "p1", "p2"); checkExit(Exit.OK); checkOrder("p1/Class1.html", """ Link to heading in package p2""", """ Plain link to heading in Class2""", """
  • unqualified link to heading above
  • qualified link to heading above
  • """, """
  • See main heading in p2.Class2
  • See heading in p2
  • """); checkOrder("p2/Class2.html", """ Link to local anchor""", """ Plain link to Class1."""); checkOrder("p2/package-summary.html", """
  • See sub heading in p2.Class2
  • local qualified link
  • local unqualified link
  • """); checkOrder("p2/doc-files/file.html", """ Plain link to heading in p1.ClassA.""", """
  • See main heading in p2.ClassB
  • package link
  • local anchor
  • """); } @Test public void testModule(Path base) throws Exception { Path out = base.resolve("out"); javadoc("-d", out.toString(), "--module-source-path", src.toString(), "--no-platform-links", "--module", "m1,m2", "m2/com.m2"); checkExit(Exit.OK); checkOrder("m1/module-summary.html", """ See main heading in Class2"""); checkOrder("m1/com/m1/package-summary.html", """
    Link to local anchor. """, """ package-anchor
    """, """ """); checkOrder("m1/com/m1/Class1.html", """ sub heading in Class2.""", """

    More links:

    """, """
    See Also:
    """); checkOrder("m2/module-summary.html", """ Plain link to local anchor."""); checkOrder("m2/com/m2/package-summary.html", """ Plain link to local anchor. """, """ """); checkOrder("m2/com/m2/Class2.html", """ Link to heading in module m1""", """ Plain link to sub heading above."""); checkOrder("m2/doc-files/file.html", """ Link to heading in Class2. Plain link to local anchor. """, """