/* * Copyright (c) 2003, 2018, 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 4780441 4874845 4978816 8014017 8016328 8025633 8026567 8175200 8182765 * @summary Make sure that when the -private flag is not used, members * inherited from package private class are documented in the child. * * Make sure that when a method inherits documentation from a method * in a non-public class/interface, the non-public class/interface * is not mentioned anywhere (not even in the signature or tree). * * Make sure that when a private interface method with generic parameters * is implemented, the comments can be inherited properly. * * Make sure when no modifier appear in the class signature, the * signature is displayed correctly without extra space at the beginning. * @author jamieh * @library ../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * @build JavadocTester * @run main TestPrivateClasses */ public class TestPrivateClasses extends JavadocTester { public static void main(String... args) throws Exception { TestPrivateClasses tester = new TestPrivateClasses(); tester.runTests(); } @Test void testDefault() { javadoc("-d", "out-default", "-sourcepath", testSrc, "pkg", "pkg2"); checkExit(Exit.OK); checkOutput("pkg/PublicChild.html", true, // Field inheritence from non-public superclass. "" + "fieldInheritedFromParent", // Method inheritance from non-public superclass. "" + "methodInheritedFromParent", // private class does not show up in tree "", // Method is documented as though it is declared in the inheriting method. "
public void methodInheritedFromParent​(int p1)",
                "
\n" + "
All Implemented Interfaces:
\n" + "
" + "PublicInterface
\n" + "
"); checkOutput("pkg/PublicChild.html", false, // Should not document that a method overrides method from private class. "Overrides:", // Should not document that a method specified by private interface. "Specified by:", // Should not mention that any documentation was copied. "Description copied from", // Don't extend private classes or interfaces "PrivateParent", "PrivateInterface"); checkOutput("pkg/PublicChild.html", false, // Should not document comments from private inherited interfaces "" + "" + "methodInterface​(int p1)\n" + "
Comment from interface.
\n", // and similarly one more "" + "" + "methodInterface2​(int p1)\n" + "
Comment from interface.
\n" ); checkOutput("pkg/PublicInterface.html", true, // Field inheritance from non-public superinterface. "" + "fieldInheritedFromInterface", // Method inheritance from non-public superinterface. "" + "methodInterface", //Make sure implemented interfaces from private superclass are inherited "
\n" + "
All Known Implementing Classes:
\n" + "
" + "PublicChild
\n" + "
"); checkOutput("pkg/PublicInterface.html", false, "Specified by:", "Description copied from", "PrivateInterface", "All Superinterfaces"); checkOutput("pkg2/C.html", false, //Generic interface method test. "This comment should get copied to the implementing class"); checkOutput("pkg2/C.html", false, //Do not inherit private interface method with generic parameters. //This method has been implemented. "hello"); checkOutput("constant-values.html", false, // Make inherited constant are documented correctly. "PrivateInterface"); } @Test void testDefault_html4() { javadoc("-d", "out-default-html4", "-html4", "-sourcepath", testSrc, "pkg", "pkg2"); checkExit(Exit.OK); checkOutput("pkg/PublicChild.html", true, // Method inheritance from non-public superclass. ""); checkOutput("pkg/PublicChild.html", false, // Should not document comments from private inherited interfaces "" + "" + "methodInterface​(int p1)\n" + "
Comment from interface.
\n", // and similarly one more "" + "" + "methodInterface2​(int p1)\n" + "
Comment from interface.
\n" ); checkOutput("pkg/PublicInterface.html", true, // Method inheritance from non-public superinterface. "" + "methodInterface"); checkOutput("pkg2/C.html", false, //Do not inherit private interface method with generic parameters. //This method has been implemented. "hello"); } @Test void testPrivate() { javadoc("-d", "out-private", "-sourcepath", testSrc, "-private", "pkg", "pkg2"); checkExit(Exit.OK); checkOutput("pkg/PublicChild.html", true, // Field inheritence from non-public superclass. "Fields inherited from class pkg." + "" + "PrivateParent", "" + "fieldInheritedFromParent", // Method inheritence from non-public superclass. "Methods inherited from class pkg." + "" + "PrivateParent", "" + "methodInheritedFromParent", // Should document that a method overrides method from private class. "
Overrides:
\n" + "
" + "methodOverridenFromParent in class " + "" + "PrivateParent
", // Should document that a method is specified by private interface. "
Specified by:
\n" + "
" + "methodInterface in interface " + "" + "PrivateInterface
", // Should mention that any documentation was copied. "Description copied from", // Extend documented private classes or interfaces "extends", "
\n" + "
All Implemented Interfaces:
\n" + "
" + "PrivateInterface, " + "" + "PublicInterface
\n" + "
", "
public class PublicChild");

        checkOutput("pkg/PublicInterface.html", true,
                // Field inheritence from non-public superinterface.
                "Fields inherited from interface pkg."
                + ""
                + "PrivateInterface",
                ""
                + "fieldInheritedFromInterface",
                // Method inheritance from non-public superinterface.
                "Methods inherited from interface pkg."
                + ""
                + "PrivateInterface",
                // Extend documented private classes or interfaces
                "extends",
                "All Superinterfaces",
                //Make sure implemented interfaces from private superclass are inherited
                "
\n" + "
All Known Implementing Classes:
\n" + "
" + "PrivateParent, " + "PublicChild" + "
\n" + "
"); checkOutput("pkg/PrivateInterface.html", true, "" + "methodInterface" ); checkOutput("pkg2/C.html", true, //Since private flag is used, we can document that private interface method //with generic parameters has been implemented. "Description copied from interface: " + "I", "
Specified by:
\n" + "
hello" + " in interface " + "I" + "<java.lang.String>
"); checkOutput("pkg/PrivateParent.html", true, //Make sure when no modifier appear in the class signature, the //signature is displayed correctly without extra space at the beginning. "
class PrivateParent");

        checkOutput("pkg/PrivateParent.html", false,
                "
 class PrivateParent");
    }

    @Test
    void testPrivate_html4() {
        javadoc("-d", "out-private-html4",
                "-html4",
                "-sourcepath", testSrc,
                "-private",
                "pkg", "pkg2");
        checkExit(Exit.OK);

        checkOutput("pkg/PublicChild.html", true,
                ""
                + "methodInheritedFromParent",
                // Should document that a method overrides method from private class.
                "
Overrides:
\n" + "
" + "methodOverridenFromParent in class " + "" + "PrivateParent
", // Should document that a method is specified by private interface. "
Specified by:
\n" + "
" + "methodInterface in interface " + "" + "PrivateInterface
"); checkOutput("pkg/PrivateInterface.html", true, "" + "methodInterface" ); checkOutput("pkg2/C.html", true, //Since private flag is used, we can document that private interface method //with generic parameters has been implemented. "Description copied from interface: " + "I", "
Specified by:
\n" + "
hello" + " in interface " + "I" + "<java.lang.String>
"); } }