/*
* Copyright (c) 2003, 2020, 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.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestPrivateClasses
*/
import javadoc.tester.JavadocTester;
public class TestPrivateClasses extends JavadocTester {
public static void main(String... args) throws Exception {
TestPrivateClasses tester = new TestPrivateClasses();
tester.runTests();
}
@Test
public void testDefault() {
javadoc("-d", "out-default",
"-sourcepath", testSrc,
"--no-platform-links",
"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
"""
java.lang.Object
pkg.PublicChild
""",
// Method is documented as though it is declared in the inheriting method.
"""
public void methodInheritedFromParent\
(int p1)
throws java.lang.Exception
""",
"""
- All Implemented Interfaces:
PublicInterface
""");
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)
Comment from interface.
| """,
// and similarly one more
"""
methodInterface2(int p1)
Comment from interface.
| """
);
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
"""
- All Known Implementing Classes:
PublicChild
""");
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
public void testPrivate() {
javadoc("-d", "out-private",
"-sourcepath", testSrc,
"--no-platform-links",
"-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:
methodOverriddenFromParent
in class PrivateParent\
dd>""",
// Should document that a method is specified by private interface.
"""
Specified by:
methodInterface\
a>
in interface PrivateInterface
""",
// Should mention that any documentation was copied.
"Description copied from",
// Extend documented private classes or interfaces
"extends",
"""
- All Implemented Interfaces:
PrivateInterf\
ace
, Pu\
blicInterface
""",
"""
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
"""
- All Known Implementing Classes:
PrivateParent, PublicChild
""");
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: <\
a href="I.html#hello(T)">I
""",
"""
Specified by:
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""");
}
}