TestPrivateClasses.java revision 3233:b5d08bc0d224
11541Srgrimes/*
21541Srgrimes * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41541Srgrimes *
51541Srgrimes * This code is free software; you can redistribute it and/or modify it
61541Srgrimes * under the terms of the GNU General Public License version 2 only, as
71541Srgrimes * published by the Free Software Foundation.
81541Srgrimes *
91541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131541Srgrimes * accompanied this code).
141541Srgrimes *
151541Srgrimes * You should have received a copy of the GNU General Public License version
161541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181541Srgrimes *
191541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201541Srgrimes * or visit www.oracle.com if you need additional information or have any
211541Srgrimes * questions.
221541Srgrimes */
231541Srgrimes
241541Srgrimes/*
251541Srgrimes * @test
261541Srgrimes * @bug      4780441 4874845 4978816 8014017 8016328 8025633 8026567
271541Srgrimes * @summary  Make sure that when the -private flag is not used, members
281541Srgrimes *           inherited from package private class are documented in the child.
291541Srgrimes *
301541Srgrimes *           Make sure that when a method inherits documentation from a method
311541Srgrimes *           in a non-public class/interface, the non-public class/interface
321541Srgrimes *           is not mentioned anywhere (not even in the signature or tree).
331541Srgrimes *
34116189Sobrien *           Make sure that when a private interface method with generic parameters
35116189Sobrien *           is implemented, the comments can be inherited properly.
36116189Sobrien *
3770949Sbenno *           Make sure when no modifier appear in the class signature, the
381541Srgrimes *           signature is displayed correctly without extra space at the beginning.
391541Srgrimes * @author   jamieh
401541Srgrimes * @library  ../lib
411541Srgrimes * @modules jdk.javadoc
421541Srgrimes * @build    JavadocTester
431541Srgrimes * @run main TestPrivateClasses
441541Srgrimes */
451541Srgrimes
461541Srgrimespublic class TestPrivateClasses extends JavadocTester {
471541Srgrimes
481541Srgrimes    public static void main(String... args) throws Exception {
491541Srgrimes        TestPrivateClasses tester = new TestPrivateClasses();
501541Srgrimes        tester.runTests();
511541Srgrimes    }
521541Srgrimes
531541Srgrimes    @Test
541541Srgrimes    void testDefault() {
551541Srgrimes        javadoc("-d", "out-default",
561541Srgrimes                "-sourcepath", testSrc,
571541Srgrimes                "pkg", "pkg2");
581541Srgrimes        checkExit(Exit.OK);
591541Srgrimes
601541Srgrimes        checkOutput("pkg/PublicChild.html", true,
611541Srgrimes                // Field inheritence from non-public superclass.
62255939Sandrew                "<a href=\"../pkg/PublicChild.html#fieldInheritedFromParent\">"
63255939Sandrew                + "fieldInheritedFromParent</a>",
64255939Sandrew                // Method inheritance from non-public superclass.
65255939Sandrew                "<a href=\"../pkg/PublicChild.html#methodInheritedFromParent-int-\">"
66255939Sandrew                + "methodInheritedFromParent</a>",
67255939Sandrew                // private class does not show up in tree
68255939Sandrew                "<ul class=\"inheritance\">\n"
69255939Sandrew                + "<li>java.lang.Object</li>\n"
70255939Sandrew                + "<li>\n"
71255939Sandrew                + "<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&nbsp;void&nbsp;methodInheritedFromParent(int&nbsp;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&nbsp;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&nbsp;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&nbsp;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&nbsp;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>&nbsp;in class&nbsp;<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>&nbsp;in interface&nbsp;<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&nbsp;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&nbsp;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:&nbsp;<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                + "&nbsp;in interface&nbsp;<code>"
224                + "<a href=\"../pkg2/I.html\" title=\"interface in pkg2\">I</a>"
225                + "&lt;java.lang.String&gt;</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}
236