1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/*
* Copyright (c) 2003, 2022, 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 {
var 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 inheritance from non-public superclass.
"""
<a href="#fieldInheritedFromParent" class="member-name-link">fieldInheritedFromParent</a>""",
// Method inheritance from non-public superclass.
"""
<a href="#methodInheritedFromParent(int)" class="member-name-link">methodInheritedFromParent</a>""",
// private class does not show up in tree
"""
<div class="inheritance" title="Inheritance Tree">java.lang.Object
<div class="inheritance">pkg.PublicChild</div>
</div>""",
// Method is documented as though it is declared in the inheriting method.
"""
<div class="member-signature"><span class="modifiers">public</span> <span c\
lass="return-type">void</span> <span class="element-name">methodInheritedFr\
omParent</span><wbr><span class="parameters">(int p1)</span>
throws <span class="exceptions">java.lang.Exception</span></div>""",
"""
<dl class="notes">
<dt>All Implemented Interfaces:</dt>
<dd><code><a href="PublicInterface.html" title="interface in pkg">PublicInterface</a></code></dd>
</dl>""");
checkOutput("pkg/PublicChild.html", false,
// Should not document that a method overrides method from private class.
"""
<span class="overrideSpecifyLabel">Overrides:</span>""",
// Should not document that a method specified by private interface.
"""
<span class="overrideSpecifyLabel">Specified by:</span>""",
// 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
"""
<td class="col-last"><code><span class="member-name-link"><a href="#methodInterf\
ace(int)">methodInterface</a></span><wbr>(int p1)</code>
<div class="block">Comment from interface.</div>
</td>""",
// and similarly one more
"""
<td class="col-last"><code><span class="member-name-link"><a href="#methodInterf\
ace2(int)">methodInterface2</a></span><wbr>(int p1)</code>
<div class="block">Comment from interface.</div>
</td>"""
);
checkOutput("pkg/PublicInterface.html", true,
// Field inheritance from non-public superinterface.
"""
<a href="#fieldInheritedFromInterface" class="member-name-link">fieldInheritedFromInterface</a>""",
// Method inheritance from non-public superinterface.
"""
<a href="#methodInterface(int)" class="member-name-link">methodInterface</a>""",
//Make sure implemented interfaces from private superclass are inherited
"""
<dl class="notes">
<dt>All Known Implementing Classes:</dt>
<dd><code><a href="PublicChild.html" title="class in pkg">PublicChild</a></code></dd>
</dl>""");
checkOutput("pkg/PublicInterface.html", false,
"""
<span class="overrideSpecifyLabel">Specified by:</span>""",
"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.
"""
<span class="member-name-link"><a href="I.html#hello(T)">hello</a></span>""");
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 inheritance from non-public superclass.
"""
Fields inherited from class pkg.<a href="PrivateParent.html" title="class in pkg">PrivateParent</a>""",
"""
<a href="PrivateParent.html#fieldInheritedFromParent">fieldInheritedFromParent</a>""",
// Method inheritance from non-public superclass.
"""
Methods inherited from class pkg.<a href="PrivateParent.html" title="class in pkg">PrivateParent</a>""",
"""
<a href="PrivateParent.html#methodInheritedFromParent(int)">methodInheritedFromParent</a>""",
// Should document that a method overrides method from private class.
"""
<dt>Overrides:</dt>
<dd><code><a href="PrivateParent.html#methodOverriddenFromParent(char%5B%5D,int,\
T,V,java.util.List)">methodOverriddenFromParent</a></code> in class <c\
ode><a href="PrivateParent.html" title="class in pkg">PrivateParent</a></code></\
dd>""",
// Should document that a method is specified by private interface.
"""
<dt>Specified by:</dt>
<dd><code><a href="PrivateInterface.html#methodInterface(int)">methodInterface</\
a></code> in interface <code><a href="PrivateInterface.html" title="in\
terface in pkg">PrivateInterface</a></code></dd>""",
// Should mention that any documentation was copied.
"Description copied from",
// Extend documented private classes or interfaces
"extends",
"""
<dl class="notes">
<dt>All Implemented Interfaces:</dt>
<dd><code><a href="PrivateInterface.html" title="interface in pkg">PrivateInterf\
ace</a></code>, <code><a href="PublicInterface.html" title="interface in pkg">Pu\
blicInterface</a></code></dd>
</dl>""",
"""
<div class="type-signature"><span class="modifiers">public class </span><span cl\
ass="element-name type-name-label">PublicChild</span>""");
checkOutput("pkg/PublicInterface.html", true,
// Field inheritance from non-public superinterface.
"""
Fields inherited from interface pkg.<a href="PrivateInterface.html" title="interface in pkg">PrivateInterface</a>""",
"""
<a href="PrivateInterface.html#fieldInheritedFromInterface">fieldInheritedFromInterface</a>""",
// Method inheritance from non-public superinterface.
"""
Methods inherited from interface pkg.<a href="PrivateInterface.html" title="interface in pkg">PrivateInterface</a>""",
// Extend documented private classes or interfaces
"extends",
"All Superinterfaces",
//Make sure implemented interfaces from private superclass are inherited
"""
<dl class="notes">
<dt>All Known Implementing Classes:</dt>
<dd><code><a href="PrivateParent.html" title="class in pkg">PrivateParent</a></c\
ode>, <code><a href="PublicChild.html" title="class in pkg">PublicChild</a></cod\
e></dd>
</dl>""");
checkOutput("pkg/PrivateInterface.html", true,
"""
<a href="#methodInterface(int)" class="member-name-link">methodInterface</a>"""
);
checkOutput("pkg2/C.html", true,
//Since private flag is used, we can document that private interface method
//with generic parameters has been implemented.
"""
<span class="description-from-type-label">Description copied from interface: <code><\
a href="I.html#hello(T)">I</a></code></span>""",
"""
<dt>Specified by:</dt>
<dd><code><a href="I.html#hello(T)">hello</a></code> in interface <cod\
e><a href="I.html" title="interface in pkg2">I</a><java.lang.String></code\
></dd>""");
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.
"""
<div class="type-signature"><span class="modifiers">class </span><span class="el\
ement-name type-name-label">PrivateParent</span>""");
checkOutput("pkg/PrivateParent.html", false,
"""
<div class="type-signature"><span class="modifiers"> class </span><span class="el\
ement-name type-name-label">PrivateParent</span>""");
}
}
|