TestInterface.java revision 3233:b5d08bc0d224
1/*
2 * Copyright (c) 2003, 2016, 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      4682448 4947464 5029946 8025633 8026567 8035473
27 * @summary  Verify that the public modifier does not show up in the
28 *           documentation for public methods, as recommended by the JLS.
29 *           If A implements I and B extends A, B should be in the list of
30 *           implementing classes in the documentation for I.
31 * @author   jamieh
32 * @library  ../lib
33 * @modules jdk.javadoc
34 * @build    JavadocTester
35 * @run main TestInterface
36 */
37
38/*
39 * TODO: make it Inteferface<PE> ie. fix all ParameterTypes, likely should get
40 * fixed when Doc is replace by j.l.m, but meanwhile this test has been adjusted
41 * take the current format this is better than @ignore because we can follow the
42 * differences as the work progress.
43 *
44 * The consensus is that we should have something as follows:
45 * In Child.html
46 *  Specified by:  method in interface<IE>
47 *  Overrides:     method in class Parent<PE>
48 * In otherwords the TypeParameter in scope should be used ex: Interface<IE>, Parent<PE>
49   and Child<CE>
50 */
51
52public class TestInterface extends JavadocTester {
53
54    public static void main(String... args) throws Exception {
55        TestInterface tester = new TestInterface();
56        tester.runTests();
57    }
58
59    @Test
60    void test() {
61        javadoc("-d", "out",
62                "-sourcepath", testSrc,
63                "pkg");
64        checkExit(Exit.OK);
65
66        checkOutput("pkg/Interface.html", true,
67                "<pre>int&nbsp;method()</pre>",
68                "<pre>static final&nbsp;int field</pre>",
69                // Make sure known implementing class list is correct and omits type parameters.
70                "<dl>\n"
71                + "<dt>All Known Implementing Classes:</dt>\n"
72                + "<dd><a href=\"../pkg/Child.html\" title=\"class in pkg\">Child"
73                + "</a>, <a href=\"../pkg/Parent.html\" title=\"class in pkg\">Parent"
74                + "</a></dd>\n"
75                + "</dl>");
76
77        checkOutput("pkg/Child.html", true,
78                // Make sure "All Implemented Interfaces": has substituted type parameters
79                "<dl>\n"
80                + "<dt>All Implemented Interfaces:</dt>\n"
81                + "<dd><a href=\"../pkg/Interface.html\" title=\"interface in pkg\">"
82                + "Interface</a>&lt;CE&gt;</dd>\n"
83                + "</dl>",
84                //Make sure Class Tree has substituted type parameters.
85                "<ul class=\"inheritance\">\n"
86                + "<li>java.lang.Object</li>\n"
87                + "<li>\n"
88                + "<ul class=\"inheritance\">\n"
89                + "<li><a href=\"../pkg/Parent.html\" title=\"class in pkg\">"
90                + "pkg.Parent</a>&lt;CE&gt;</li>\n"
91                + "<li>\n"
92                + "<ul class=\"inheritance\">\n"
93                + "<li>pkg.Child&lt;CE&gt;</li>\n"
94                + "</ul>\n"
95                + "</li>\n"
96                + "</ul>\n"
97                + "</li>\n"
98                + "</ul>",
99                //Make sure "Specified By" has substituted type parameters.
100                "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n"
101                + "<dd><code><a href=\"../pkg/Interface.html#method--\">method</a>"
102                + "</code>&nbsp;in interface&nbsp;<code>"
103                + "<a href=\"../pkg/Interface.html\" title=\"interface in pkg\">"
104                + "Interface</a>&lt;<a href=\"../pkg/Child.html\" title=\"type parameter in Child\">"
105                + "CE</a>&gt;</code></dd>",
106                //Make sure "Overrides" has substituted type parameters.
107                "<dt><span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n"
108                + "<dd><code><a href=\"../pkg/Parent.html#method--\">method</a>"
109                + "</code>&nbsp;in class&nbsp;<code><a href=\"../pkg/Parent.html\" "
110                + "title=\"class in pkg\">Parent</a>&lt;<a href=\"../pkg/Child.html\" "
111                + "title=\"type parameter in Child\">CE</a>&gt;</code></dd>");
112
113        checkOutput("pkg/Parent.html", true,
114                //Make sure "Direct Know Subclasses" omits type parameters
115                "<dl>\n"
116                + "<dt>Direct Known Subclasses:</dt>\n"
117                + "<dd><a href=\"../pkg/Child.html\" title=\"class in pkg\">Child"
118                + "</a></dd>\n"
119                + "</dl>");
120
121        checkOutput("pkg/Interface.html", false,
122                "public int&nbsp;method()",
123                "public static final&nbsp;int field");
124    }
125
126    @Test
127    void test1() {
128        javadoc("-d", "out-1",
129                "-sourcepath", testSrc,
130                "pkg1");
131        checkExit(Exit.OK);
132
133        checkOutput("pkg1/Child.html", true,
134            // Ensure the correct Overrides in the inheritance hierarchy is reported
135            "<span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" +
136            "<dd><code><a href=\"../pkg1/GrandParent.html#method1--\">method1</a></code>" +
137            "&nbsp;in class&nbsp;" +
138            "<code><a href=\"../pkg1/GrandParent.html\" title=\"class in pkg1\">GrandParent</a>" +
139            "&lt;<a href=\"../pkg1/Child.html\" title=\"type parameter in Child\">CE</a>&gt;</code>");
140    }
141
142    @Test
143    void test2() {
144        javadoc("-d", "out-2",
145                "-sourcepath", testSrc,
146                "pkg2");
147
148        checkExit(Exit.OK);
149
150        checkOutput("pkg2/Spliterator.OfDouble.html", true,
151            // Ensure the correct type parameters are displayed correctly
152            "<h3>Nested classes/interfaces inherited from interface&nbsp;pkg2."
153            + "<a href=\"../pkg2/Spliterator.html\" title=\"interface in pkg2\">Spliterator</a></h3>\n" +
154            "<code><a href=\"../pkg2/Spliterator.OfDouble.html\" title=\"interface in pkg2\">"
155            + "Spliterator.OfDouble</a>, <a href=\"../pkg2/Spliterator.OfInt.html\" "
156            + "title=\"interface in pkg2\">Spliterator.OfInt</a>&lt;"
157            + "<a href=\"../pkg2/Spliterator.OfInt.html\" title=\"type parameter in Spliterator.OfInt\">"
158            + "Integer</a>&gt;, <a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">"
159            + "Spliterator.OfPrimitive</a>&lt;<a href=\"../pkg2/Spliterator.OfPrimitive.html\" "
160            + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>,<a href=\"../pkg2/Spliterator.OfPrimitive.html\" "
161            + "title=\"type parameter in Spliterator.OfPrimitive\">T_CONS</a>,"
162            + "<a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">"
163            + "T_SPLITR</a> extends <a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">"
164            + "Spliterator.OfPrimitive</a>&lt;<a href=\"../pkg2/Spliterator.OfPrimitive.html\" "
165            + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>,"
166            + "<a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">"
167            + "T_CONS</a>,<a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">"
168            + "T_SPLITR</a>&gt;&gt;</code>");
169    }
170}
171