/* * Copyright (c) 2017, 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 8157000 8192850 8182765 8223607 8261976 8281376 8313204 8345777 8350920 * @summary test the behavior of --override-methods option * @library ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * @build javadoc.tester.* * @run main TestOverrideMethods */ import javadoc.tester.JavadocTester; public class TestOverrideMethods extends JavadocTester { public static void main(String... args) throws Exception { var tester = new TestOverrideMethods(); tester.runTests(); } @Test public void testInvalidOption() { // Make sure an invalid argument fails javadoc("-d", "out-bad-option", "-sourcepath", testSrc, "-javafx", "--disable-javafx-strict-checks", "--override-methods=nonsense", "pkg5"); checkExit(Exit.CMDERR); } @Test public void testDetail() { // Make sure the option works javadoc("-d", "out-detail", "-sourcepath", testSrc, "-javafx", "--disable-javafx-strict-checks", "--override-methods=detail", "pkg5"); checkExit(Exit.OK); } @Test public void testSummary() { javadoc("-d", "out-summary", "-sourcepath", testSrc, "--no-platform-links", "-javafx", "--disable-javafx-strict-checks", "--override-methods=summary", "pkg5", "pkg6"); checkExit(Exit.OK); checkOrder("pkg5/Classes.C.html", // Check nested classes "Nested classes/interfaces declared in class ", "Classes.P.html#nested-class-summary", "Classes.P.PN.html", "K", "V", // Check summary table for inherited nested classes "summary-table three-column-summary", "Modifier and Type", "Class", "Description", "class ", "Classes.P.PN.html", "Classes.P.PN.html#type-param-K", "Classes.P.PN.html#type-param-V", "A nested class in parent", // Check properties """ Properties declared in class rate""", // Check summary table for inherited properties "summary-table three-column-summary", "Type", "Property", "Description", "Classes.DoubleProperty", "Classes.P.html#rateProperty", "rate", // Check fields """ Fields declared in class field0", // Check summary table for inherited fields "summary-table three-column-summary", "Modifier and Type", "Field", "Description", "int", "Classes.P.html#field0", "field0", // Check method summary "Method Summary", "void", "#m1()\" class=\"member-name-link\">m1", "A modified method", "void", """ #m4(java.lang.String,java.lang.String)" class="member-name-link">m4""", "java.lang.String k,", "java.lang.String", " v)", // Check footnotes """ Methods declared in class m0""", // Check summary table for inherited methods "summary-table three-column-summary", "Modifier and Type", "Method", "Description", "void", "Classes.GP.html#m0()", "m0", "m0 in grand parent", // Check methods from java.lang.Object """

Methods declared in clas\ s java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,\ wait, wait, wait """, // Check method details for override """
Overrides:""", "Classes.GP.html#m7()\">m7", "in class", "Classes.GP.html", "Classes.GP" ); checkOrder("pkg5/Classes.C.html", // Check footnotes 2 """ Methods declared in class getRate""", """ Classes.P.html#m2()" title="m2()">m2""", """ Classes.P.html#m3()" title="m3()">m3""", """ Classes.P.html#m4(K,V)" title="m4(Object, Object)">m4""", """ Classes.P.html#rateProperty()" title="rateProperty()">rateProperty""", """ Classes.P.html#setRate(double)" title="setRate(double)">setRate""", // Check @link """ A test of links to the methods in this class.

""", "Classes.GP.html#m0()", "Classes.GP.m0()", "#m1()", "m1()", "Classes.P.html#m2()", "Classes.P.m2()", "Classes.P.html#m3()", "Classes.P.m3()", "m4(java.lang.String,java.lang.String)", "Classes.P.html#m5()", "Classes.P.m5()", "#m6()", "m6()", "#m7()", "m7()", "End of links", // Check @see "See Also:", "Classes.GP.html#m0()", "Classes.GP.m0()", "#m1()", "m1()", "Classes.P.html#m2()", "Classes.P.m2()", "Classes.P.html#m3()", "Classes.P.m3()", "#m4(java.lang.String,java.lang.String)", "m4(String k, String v)", """ Classes.P.html#m5()">Classes.P.m5()""", "#m6()\">m6()", "#m7()\">m7()" ); checkOrder("pkg5/Classes.P.html", // Check table of contents for inherited members """

  • Nested Class Summary
  • Property Summary
  • Field Summary
  • Constructor Summary
  • Method Summary
    1. Method\ s declared in class Classes.GP
    2. Metho\ ds declared in class java.lang.Object
    """); // Tests for interfaces // Make sure the static methods in the super interface // do not make it to this interface checkOutput("pkg5/Interfaces.D.html", false, "msd", "msn"); checkOrder("pkg5/Interfaces.D.html", "Start of links

    ", """ Interfaces.A.html#m0()">Interfaces.A.m0()""", """ Interfaces.A.html#m1()">Interfaces.A.m1()""", """ Interfaces.A.html#m2()">Interfaces.A.m2()""", """ Interfaces.A.html#m3()">Interfaces.A.m3()""", "#m()\">m()", "#n()\">n()", """ Interfaces.C.html#o()">Interfaces.C.o()""", "End of links", // Check @see links "See Also:", """ Interfaces.A.html#m0()">Interfaces.A.m0()""", """ Interfaces.A.html#m1()">Interfaces.A.m1()""", """ Interfaces.A.html#m2()">Interfaces.A.m2()""", """ Interfaces.A.html#m3()">Interfaces.A.m3()""", "#m()\">m()", "#n()\">n()", """ Interfaces.C.html#o()">Interfaces.C.o()""", // Check nested classes "Nested classes/interfaces declared in interface ", "Interfaces.A", "Interfaces.A.AA.html", "Interfaces.A.AA", // Check properties """ Properties declared in interface Interfaces.A""", // Check Fields """ Fields declared in interface QUOTE", "Interfaces.A.html#rate\">rate", // Check Method Summary "Method Summary", "#m()\" class=\"member-name-link\">m", "#n()\" class=\"member-name-link\">n", // Check footnotes """ Methods declared in interface getRate""", """ Interfaces.A.html#rateProperty()" title="rateProperty()">rateProperty""", """ Interfaces.A.html#setRate(double)" title="setRate(double)">setRate""", """ Methods declared in interface m1""", """ Interfaces.B.html#m3()" title="m3()">m3""", """ Methods declared in interface o""" ); // Test synthetic values and valuesof of an enum. checkOrder("index-all.html", """

    M

    """, """ m()""", """ m()""", """ m0()""", """ m0()""", """ m1()""", """ m1()""", """ m1()""", """ m1()""", """ m2()""", """ m2()""", """ m3()""", """ m3()""", """ m3()""", """ m4(String, String)""", """ m4(K, V)""", """ m5()""", """ m6()""", """ m6()""", """ m7()""", """ m7()""", "Returns the enum constant of this class with the specified name.", """ Returns an array containing the constants of this enum class, in the order they are declared.""" ); // Check methods with covariant return types, changes in modifiers or thrown exceptions. // Only those should be shown in summary; m1, m3, m9 should listed as declared in Base checkOutput("pkg6/Sub.html", true, """
    Modifier and Type
    Method
    Description
    java.lang.String
    This is Base::m2.
    void
    This is Base::m4.
    java.lang.Object
    This is Base::m5.
    final java.lang.Object
    This is Base::m6.
    java.lang.Object
    This is Base::m7.
    abstract java.lang.Object
    This is Base::m8.
    """, """

    Methods declared in class <\ a href="Base.html#method-summary" title="class in pkg6">Base

    m1, m3, m9
    Modifier and Type
    Method
    Description
    java.lang.Object
    m1()
    This is Base::m1.
    m3()
    This is Base::m3.
    abstract java.lang.Object
    m9()
    This is Base::m9.
    """); } @Test public void testSummaryAnnotations() { javadoc("-d", "out-summary-annotations", "-sourcepath", testSrc, "--no-platform-links", "-javafx", "--disable-javafx-strict-checks", "--override-methods=summary", "-private", "pkg7"); checkExit(Exit.OK); checkOutput("pkg7/AnnotatedSub1.html", true, """

    Methods declared in int\ erface AnnotatedBase

    m1
    Modifier and Type
    Method
    Description
    java.lang.Iterable<java.lang\ .String>
    m1(java.lang.Class<\ ? extends java.lang.CharSequence> p1, int[] p2)
    This is AnnotatedBase::m1.
    """); checkOutput("pkg7/AnnotatedSub2.html", true, """
    @A @A java.lang.Iterable<java.lang.String> m1(java.lang.Class<? ext\ ends java.lang.CharSequence> p1, int[] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); checkOutput("pkg7/AnnotatedSub3.html", true, """
    @A @A java.lang.Iterable<java.lang.String> m1(java.lang.Class<? ext\ ends java.lang.CharSequence> p1, int[] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); checkOutput("pkg7/AnnotatedSub4.html", true, """
    java.lang.Iterable<@A java.lang.String><\ /span> m1(j\ ava.lang.Class<? extends java.lang.CharSequence> p1, int[] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); checkOutput("pkg7/AnnotatedSub5.html", true, """
    java.lang.Iterable<ja\ va.lang.String> m1(@A @A java.lang.Class<\ ;? extends java.lang.CharSequence> p1, int[] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); checkOutput("pkg7/AnnotatedSub6.html", true, """
    java.lang.Iterable<ja\ va.lang.String> m1(java.lang.Class<@A ? extends java.lang.CharSequence> p1, int[] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); checkOutput("pkg7/AnnotatedSub7.html", true, """
    java.lang.Iterable<ja\ va.lang.String> m1(java.lang.Class<? extends @A java.lang.CharSequence> p1, int[] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); checkOutput("pkg7/AnnotatedSub8.html", true, """
    java.lang.Iterable<ja\ va.lang.String> m1(java.lang.Class<? extends java.lang.CharSequence> p1, int @A [] p2)
    Description copied from inte\ rface: Ann\ otatedBase
    This is AnnotatedBase::m1.
    Specified by:
    m1 in interface AnnotatedBase
    Parameters:
    p1 - first parameter
    p2 - second parameter
    Returns:
    something
    """); } @Test public void testPolymorphicDetail() { javadoc("-d", "out-polymorphic-detail", "-sourcepath", testSrc, "--override-methods=detail", "pkg8"); checkExit(Exit.OK); checkOutput("pkg8/C.html", true, """
    Overrides:
    m1 in class \ P
    """); checkOutput("pkg8/C.html", true, """
    Overrides:
    m2 in class \ P
    """); checkOutput("pkg8/C.html", true, """
    Overrides:
    m3 in class \ P
    """); } @Test // results should be the same as that of "detail" public void testPolymorphicDefault() { javadoc("-d", "out-polymorphic-default", "-sourcepath", testSrc, "pkg8"); checkExit(Exit.OK); checkOutput("pkg8/C.html", true, """
    Overrides:
    m1 in class \ P
    """); checkOutput("pkg8/C.html", true, """
    Overrides:
    m2 in class \ P
    """); checkOutput("pkg8/C.html", true, """
    Overrides:
    m3 in class \ P
    """); } @Test public void testPolymorphicSummary() { javadoc("-d", "out-polymorphic-summary", "-sourcepath", testSrc, "--override-methods=summary", "pkg8"); checkExit(Exit.OK); checkOutput("pkg8/C.html", true, """
    Overrides:
    m1 in class \ GP
    """); checkOutput("pkg8/C.html", true, """
    Overrides:
    m2 in class \ GP
    """); checkOutput("pkg8/C.html", true, """
    Overrides:
    m3 in class \ GP
    """); checkOutput("pkg8/C.html", false, """
    Overrides:
    m1 in class \ P
    """); } }