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