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 "<div class=\"memberSignature\"><span class=\"modifiers\">public</span> " 74 + "<span class=\"returnType\">void</span> <span class=\"memberName\">" 75 + "methodInheritedFromParent</span>(<span class=\"arguments\">int p1)</span>\n" 76 + " throws <span class=\"exceptions\">java.lang.Exception</span></div>", 77 "<dl>\n" 78 + "<dt>All Implemented Interfaces:</dt>\n" 79 + "<dd><code><a href=\"PublicInterface.html\" title=\"interface in pkg\">" 80 + "PublicInterface</a></code></dd>\n" 81 + "</dl>"); 82 83 checkOutput("pkg/PublicChild.html", false, 84 // Should not document that a method overrides method from private class. 85 "<span class=\"overrideSpecifyLabel\">Overrides:</span>", 86 // Should not document that a method specified by private interface. 87 "<span class=\"overrideSpecifyLabel\">Specified by:</span>", 88 // Should not mention that any documentation was copied. 89 "Description copied from", 90 // Don't extend private classes or interfaces 91 "PrivateParent", 92 "PrivateInterface"); 93 94 checkOutput("pkg/PublicChild.html", false, 95 // Should not document comments from private inherited interfaces 96 "<td class=\"colLast\"><code><span class=\"memberNameLink\">" 97 + "<a href=\"#methodInterface(int)\">" 98 + "methodInterface</a></span>(int p1)</code>\n" 99 + "<div class=\"block\">Comment from interface.</div>\n</td>", 100 // and similarly one more 101 "<td class=\"colLast\"><code><span class=\"memberNameLink\">" 102 + "<a href=\"#methodInterface2(int)\">" 103 + "methodInterface2</a></span>(int p1)</code>\n" 104 + "<div class=\"block\">Comment from interface.</div>\n</td>" 105 ); 106 107 checkOutput("pkg/PublicInterface.html", true, 108 // Field inheritance from non-public superinterface. 109 "<a href=\"#fieldInheritedFromInterface\">" 110 + "fieldInheritedFromInterface</a>", 111 // Method inheritance from non-public superinterface. 112 "<a href=\"#methodInterface(int)\">" 113 + "methodInterface</a>", 114 //Make sure implemented interfaces from private superclass are inherited 115 "<dl>\n" 116 + "<dt>All Known Implementing Classes:</dt>\n" 117 + "<dd><code><a href=\"PublicChild.html\" title=\"class in pkg\">" 118 + "PublicChild</a></code></dd>\n" 119 + "</dl>"); 120 121 checkOutput("pkg/PublicInterface.html", false, 122 "<span class=\"overrideSpecifyLabel\">Specified by:</span>", 123 "Description copied from", 124 "PrivateInterface", 125 "All Superinterfaces"); 126 127 checkOutput("pkg2/C.html", false, 128 //Generic interface method test. 129 "This comment should get copied to the implementing class"); 130 131 checkOutput("pkg2/C.html", false, 132 //Do not inherit private interface method with generic parameters. 133 //This method has been implemented. 134 "<span class=\"memberNameLink\"><a href=\"I.html#hello(T)\">hello</a></span>"); 135 136 checkOutput("constant-values.html", false, 137 // Make inherited constant are documented correctly. 138 "PrivateInterface"); 139 } 140 141 @Test 142 public void testPrivate() { 143 javadoc("-d", "out-private", 144 "-sourcepath", testSrc, 145 "-private", 146 "pkg", "pkg2"); 147 checkExit(Exit.OK); 148 149 checkOutput("pkg/PublicChild.html", true, 150 // Field inheritence from non-public superclass. 151 "Fields inherited from class pkg." 152 + "<a href=\"PrivateParent.html\" title=\"class in pkg\">" 153 + "PrivateParent</a>", 154 "<a href=\"PrivateParent.html#fieldInheritedFromParent\">" 155 + "fieldInheritedFromParent</a>", 156 // Method inheritence from non-public superclass. 157 "Methods inherited from class pkg." 158 + "<a href=\"PrivateParent.html\" title=\"class in pkg\">" 159 + "PrivateParent</a>", 160 "<a href=\"PrivateParent.html#methodInheritedFromParent(int)\">" 161 + "methodInheritedFromParent</a>", 162 // Should document that a method overrides method from private class. 163 "<dt><span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" 164 + "<dd><code><a href=\"PrivateParent.html#methodOverridenFromParent(char%5B%5D,int,T,V,java.util.List)\">" 165 + "methodOverridenFromParent</a></code> in class <code>" 166 + "<a href=\"PrivateParent.html\" title=\"class in pkg\">" 167 + "PrivateParent</a></code></dd>", 168 // Should document that a method is specified by private interface. 169 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n" 170 + "<dd><code><a href=\"PrivateInterface.html#methodInterface(int)\">" 171 + "methodInterface</a></code> in interface <code>" 172 + "<a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 173 + "PrivateInterface</a></code></dd>", 174 // Should mention that any documentation was copied. 175 "Description copied from", 176 // Extend documented private classes or interfaces 177 "extends", 178 "<dl>\n" 179 + "<dt>All Implemented Interfaces:</dt>\n" 180 + "<dd><code><a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 181 + "PrivateInterface</a></code>, " 182 + "<code><a href=\"PublicInterface.html\" title=\"interface in pkg\">" 183 + "PublicInterface</a></code></dd>\n" 184 + "</dl>", 185 "<pre>public class <span class=\"typeNameLabel\">PublicChild</span>"); 186 187 checkOutput("pkg/PublicInterface.html", true, 188 // Field inheritence from non-public superinterface. 189 "Fields inherited from interface pkg." 190 + "<a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 191 + "PrivateInterface</a>", 192 "<a href=\"PrivateInterface.html#fieldInheritedFromInterface\">" 193 + "fieldInheritedFromInterface</a>", 194 // Method inheritance from non-public superinterface. 195 "Methods inherited from interface pkg." 196 + "<a href=\"PrivateInterface.html\" title=\"interface in pkg\">" 197 + "PrivateInterface</a>", 198 // Extend documented private classes or interfaces 199 "extends", 200 "All Superinterfaces", 201 //Make sure implemented interfaces from private superclass are inherited 202 "<dl>\n" 203 + "<dt>All Known Implementing Classes:</dt>\n" 204 + "<dd><code><a href=\"PrivateParent.html\" title=\"class in pkg\">" 205 + "PrivateParent</a></code>, " 206 + "<code><a href=\"PublicChild.html\" title=\"class in pkg\">PublicChild" 207 + "</a></code></dd>\n" 208 + "</dl>"); 209 210 checkOutput("pkg/PrivateInterface.html", true, 211 "<a href=\"#methodInterface(int)\">" 212 + "methodInterface</a>" 213 ); 214 215 checkOutput("pkg2/C.html", true, 216 //Since private flag is used, we can document that private interface method 217 //with generic parameters has been implemented. 218 "<span class=\"descfrmTypeLabel\">Description copied from interface: <code>" 219 + "<a href=\"I.html#hello(T)\">I</a></code></span>", 220 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n" 221 + "<dd><code><a href=\"I.html#hello(T)\">hello</a></code>" 222 + " in interface <code>" 223 + "<a href=\"I.html\" title=\"interface in pkg2\">I</a>" 224 + "<java.lang.String></code></dd>"); 225 226 checkOutput("pkg/PrivateParent.html", true, 227 //Make sure when no modifier appear in the class signature, the 228 //signature is displayed correctly without extra space at the beginning. 229 "<pre>class <span class=\"typeNameLabel\">PrivateParent</span>"); 230 231 checkOutput("pkg/PrivateParent.html", false, 232 "<pre> class <span class=\"typeNameLabel\">PrivateParent</span>"); 233 } 234 }