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