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