1 /* 2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4780441 4874845 4978816 8014017 8016328 8025633 8026567 8175200 8182765 27 * @summary Make sure that when the -private flag is not used, members 28 * inherited from package private class are documented in the child. 29 * 30 * Make sure that when a method inherits documentation from a method 31 * in a non-public class/interface, the non-public class/interface 32 * is not mentioned anywhere (not even in the signature or tree). 33 * 34 * Make sure that when a private interface method with generic parameters 35 * is implemented, the comments can be inherited properly. 36 * 37 * Make sure when no modifier appear in the class signature, the 38 * signature is displayed correctly without extra space at the beginning. 39 * @author jamieh 40 * @library ../../lib 41 * @modules jdk.javadoc/jdk.javadoc.internal.tool 42 * @build javadoc.tester.* 43 * @run main TestPrivateClasses 44 */ 45 import javadoc.tester.JavadocTester; 46 47 public class TestPrivateClasses extends JavadocTester { 48 49 public static void main(String... args) throws Exception { 50 TestPrivateClasses tester = new TestPrivateClasses(); 51 tester.runTests(); 52 } 53 54 @Test 55 public void testDefault() { 56 javadoc("-d", "out-default", 57 "-sourcepath", testSrc, 58 "pkg", "pkg2"); 59 checkExit(Exit.OK); 60 61 checkOutput("pkg/PublicChild.html", true, 62 // Field inheritence from non-public superclass. 63 "<a href=\"#fieldInheritedFromParent\">" 64 + "fieldInheritedFromParent</a>", 65 // Method inheritance from non-public superclass. 66 "<a href=\"#methodInheritedFromParent(int)\">" 67 + "methodInheritedFromParent</a>", 68 // private class does not show up in tree 69 "<div class=\"inheritance\" title=\"Inheritance Tree\">java.lang.Object\n" 70 + "<div class=\"inheritance\">pkg.PublicChild</div>\n" 71 + "</div>", 72 // Method is documented as though it is declared in the inheriting method. 73 "<pre class=\"methodSignature\">public void methodInheritedFromParent(int p1)", 74 "<dl>\n" 75 + "<dt>All Implemented Interfaces:</dt>\n" 76 + "<dd><code><a href=\"PublicInterface.html\" title=\"interface in pkg\">" 77 + "PublicInterface</a></code></dd>\n" 78 + "</dl>"); 79 80 checkOutput("pkg/PublicChild.html", false, 81 // Should not document that a method overrides method from private class. 82 "<span class=\"overrideSpecifyLabel\">Overrides:</span>", 83 // Should not document that a method specified by private interface. 84 "<span class=\"overrideSpecifyLabel\">Specified by:</span>", 85 // Should not mention that any documentation was copied. 86 "Description copied from", 87 // Don't extend private classes or interfaces 88 "PrivateParent", 89 "PrivateInterface"); 90 91 checkOutput("pkg/PublicChild.html", false, 92 // Should not document comments from private inherited interfaces 93 "<td class=\"colLast\"><code><span class=\"memberNameLink\">" 94 + "<a href=\"#methodInterface(int)\">" 95 + "methodInterface</a></span>(int p1)</code>\n" 96 + "<div class=\"block\">Comment from interface.</div>\n</td>", 97 // and similarly one more 98 "<td class=\"colLast\"><code><span class=\"memberNameLink\">" 99 + "<a href=\"#methodInterface2(int)\">" 100 + "methodInterface2</a></span>(int p1)</code>\n" 101 + "<div class=\"block\">Comment from interface.</div>\n</td>" 102 ); 103 104 checkOutput("pkg/PublicInterface.html", true, 105 // Field inheritance from non-public superinterface. 106 "<a href=\"#fieldInheritedFromInterface\">" 107 + "fieldInheritedFromInterface</a>", 108 // Method inheritance from non-public superinterface. 109 "<a href=\"#methodInterface(int)\">" 110 + "methodInterface</a>", 111 //Make sure implemented interfaces from private superclass are inherited 112 "<dl>\n" 113 + "<dt>All Known Implementing Classes:</dt>\n" 114 + "<dd><code><a href=\"PublicChild.html\" title=\"class in pkg\">" 115 + "PublicChild</a></code></dd>\n" 116 + "</dl>"); 117 118 checkOutput("pkg/PublicInterface.html", false, 119 "<span class=\"overrideSpecifyLabel\">Specified by:</span>", 120 "Description copied from", 121 "PrivateInterface", 122 "All Superinterfaces"); 123 124 checkOutput("pkg2/C.html", false, 125 //Generic interface method test. 126 "This comment should get copied to the implementing class"); 127 128 checkOutput("pkg2/C.html", false, 129 //Do not inherit private interface method with generic parameters. 130 //This method has been implemented. 131 "<span class=\"memberNameLink\"><a href=\"I.html#hello(T)\">hello</a></span>"); 132 133 checkOutput("constant-values.html", false, 134 // Make inherited constant are documented correctly. 135 "PrivateInterface"); 136 } 137 138 @Test 139 public void testPrivate() { 140 javadoc("-d", "out-private", 141 "-sourcepath", testSrc, 142 "-private", 143 "pkg", "pkg2"); 144 checkExit(Exit.OK); 145 146 checkOutput("pkg/PublicChild.html", true, 147 // Field inheritence from non-public superclass. 148 "Fields inherited from class pkg." 149 + "<a href=\"PrivateParent.html\" title=\"class in pkg\">" 150 + "PrivateParent</a>", 151 "<a href=\"PrivateParent.html#fieldInheritedFromParent\">" 152 + "fieldInheritedFromParent</a>", 153 // Method inheritence from non-public superclass. 154 "Methods inherited from class pkg." 155 + "<a href=\"PrivateParent.html\" title=\"class in pkg\">" 156 + "PrivateParent</a>", 157 "<a href=\"PrivateParent.html#methodInheritedFromParent(int)\">" 158 + "methodInheritedFromParent</a>", 159 // Should document that a method overrides method from private class. 160 "<dt><span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" 161 + "<dd><code><a href=\"PrivateParent.html#methodOverridenFromParent(char%5B%5D,int,T,V,java.util.List)\">" 162 + "methodOverridenFromParent</a></code> in class <code>" 163 + "<a href=\"PrivateParent.html\" title=\"class in pkg\">" 164 + "PrivateParent</a></code></dd>", 165 // Should document that a method is specified by private interface. 166 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n" 167 + "<dd><code><a href=\"PrivateInterface.html#methodInterface(int)\">" 168 + "methodInterface</a></code> in interface <code>" 169 + "<a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 170 + "PrivateInterface</a></code></dd>", 171 // Should mention that any documentation was copied. 172 "Description copied from", 173 // Extend documented private classes or interfaces 174 "extends", 175 "<dl>\n" 176 + "<dt>All Implemented Interfaces:</dt>\n" 177 + "<dd><code><a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 178 + "PrivateInterface</a></code>, " 179 + "<code><a href=\"PublicInterface.html\" title=\"interface in pkg\">" 180 + "PublicInterface</a></code></dd>\n" 181 + "</dl>", 182 "<pre>public class <span class=\"typeNameLabel\">PublicChild</span>"); 183 184 checkOutput("pkg/PublicInterface.html", true, 185 // Field inheritence from non-public superinterface. 186 "Fields inherited from interface pkg." 187 + "<a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 188 + "PrivateInterface</a>", 189 "<a href=\"PrivateInterface.html#fieldInheritedFromInterface\">" 190 + "fieldInheritedFromInterface</a>", 191 // Method inheritance from non-public superinterface. 192 "Methods inherited from interface pkg." 193 + "<a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 194 + "PrivateInterface</a>", 195 // Extend documented private classes or interfaces 196 "extends", 197 "All Superinterfaces", 198 //Make sure implemented interfaces from private superclass are inherited 199 "<dl>\n" 200 + "<dt>All Known Implementing Classes:</dt>\n" 201 + "<dd><code><a href=\"PrivateParent.html\" title=\"class in pkg\">" 202 + "PrivateParent</a></code>, " 203 + "<code><a href=\"PublicChild.html\" title=\"class in pkg\">PublicChild" 204 + "</a></code></dd>\n" 205 + "</dl>"); 206 207 checkOutput("pkg/PrivateInterface.html", true, 208 "<a href=\"#methodInterface(int)\">" 209 + "methodInterface</a>" 210 ); 211 212 checkOutput("pkg2/C.html", true, 213 //Since private flag is used, we can document that private interface method 214 //with generic parameters has been implemented. 215 "<span class=\"descfrmTypeLabel\">Description copied from interface: <code>" 216 + "<a href=\"I.html#hello(T)\">I</a></code></span>", 217 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n" 218 + "<dd><code><a href=\"I.html#hello(T)\">hello</a></code>" 219 + " in interface <code>" 220 + "<a href=\"I.html\" title=\"interface in pkg2\">I</a>" 221 + "<java.lang.String></code></dd>"); 222 223 checkOutput("pkg/PrivateParent.html", true, 224 //Make sure when no modifier appear in the class signature, the 225 //signature is displayed correctly without extra space at the beginning. 226 "<pre>class <span class=\"typeNameLabel\">PrivateParent</span>"); 227 228 checkOutput("pkg/PrivateParent.html", false, 229 "<pre> class <span class=\"typeNameLabel\">PrivateParent</span>"); 230 } 231 }