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 * @library ../../lib 33 * @modules jdk.javadoc/jdk.javadoc.internal.tool 34 * @build javadoc.tester.* 35 * @run main TestInterface 36 */ 37 38 /* 39 * TODO: make it Interface<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 52 import javadoc.tester.JavadocTester; 53 54 public class TestInterface extends JavadocTester { 55 56 public static void main(String... args) throws Exception { 57 TestInterface tester = new TestInterface(); 58 tester.runTests(); 59 } 60 61 @Test 62 public void test() { 63 javadoc("-d", "out", 64 "-sourcepath", testSrc, 65 "pkg"); 66 checkExit(Exit.OK); 67 68 checkOutput("pkg/Interface.html", true, 69 "<div class=\"memberSignature\"><span class=\"returnType\">int</span> " 70 + "<span class=\"memberName\">method</span>()</div>", 71 "<div class=\"memberSignature\"><span class=\"modifiers\">static final</span> " 72 + "<span class=\"returnType\">int</span> <span class=\"memberName\">field</span></div>", 73 // Make sure known implementing class list is correct and omits type parameters. 74 "<dl>\n" 75 + "<dt>All Known Implementing Classes:</dt>\n" 76 + "<dd><code><a href=\"Child.html\" title=\"class in pkg\">Child" 77 + "</a></code>, <code><a href=\"Parent.html\" title=\"class in pkg\">Parent" 78 + "</a></code></dd>\n" 79 + "</dl>"); 80 81 checkOutput("pkg/Child.html", true, 82 // Make sure "All Implemented Interfaces": has substituted type parameters 83 "<dl>\n" 84 + "<dt>All Implemented Interfaces:</dt>\n" 85 + "<dd><code><a href=\"Interface.html\" title=\"interface in pkg\">" 86 + "Interface</a><CE></code></dd>\n" 87 + "</dl>", 88 //Make sure Class Tree has substituted type parameters. 89 "<div class=\"inheritance\" title=\"Inheritance Tree\">java.lang.Object\n" 90 + "<div class=\"inheritance\"><a href=\"Parent.html\"" 91 + " title=\"class in pkg\">pkg.Parent</a><CE>\n" 92 + "<div class=\"inheritance\">pkg.Child<CE></div>\n" 93 + "</div>\n</div>", 94 //Make sure "Specified By" has substituted type parameters. 95 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n" 96 + "<dd><code><a href=\"Interface.html#method()\">method</a>" 97 + "</code> in interface <code>" 98 + "<a href=\"Interface.html\" title=\"interface in pkg\">" 99 + "Interface</a><<a href=\"Child.html\" title=\"type parameter in Child\">" 100 + "CE</a>></code></dd>", 101 //Make sure "Overrides" has substituted type parameters. 102 "<dt><span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" 103 + "<dd><code><a href=\"Parent.html#method()\">method</a>" 104 + "</code> in class <code><a href=\"Parent.html\" " 105 + "title=\"class in pkg\">Parent</a><<a href=\"Child.html\" " 106 + "title=\"type parameter in Child\">CE</a>></code></dd>"); 107 108 checkOutput("pkg/Parent.html", true, 109 //Make sure "Direct Know Subclasses" omits type parameters 110 "<dl>\n" 111 + "<dt>Direct Known Subclasses:</dt>\n" 112 + "<dd><code><a href=\"Child.html\" title=\"class in pkg\">Child" 113 + "</a></code></dd>\n" 114 + "</dl>"); 115 116 checkOutput("pkg/Interface.html", false, 117 "public int method--", 118 "public static final int field"); 119 120 checkOutput("pkg/ClassWithStaticMembers.html", false, 121 //Make sure "Specified By" does not appear on class documentation when 122 //the method is a static method in the interface. 123 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n"); 124 125 checkOutput("pkg/ClassWithStaticMembers.html", true, 126 "<h3><a id=\"f\">f</a></h3>\n" 127 + "<div class=\"memberSignature\"><span class=\"modifiers\">public static</span> " 128 + "<span class=\"returnType\">int</span> <span class=\"memberName\">f</span></div>\n" 129 + "<div class=\"block\">A hider field</div>", 130 131 "<td class=\"colFirst\"><code>static void</code></td>\n" 132 + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">" 133 + "<a href=\"#m()\">m</a></span>()</code></th>\n" 134 + "<td class=\"colLast\">\n" 135 + "<div class=\"block\">A hider method</div>\n" 136 + "</td>\n", 137 138 "<h3><a id=\"staticMethod()\">staticMethod</a></h3>\n" 139 + "<div class=\"memberSignature\"><span class=\"modifiers\">public static</span> " 140 + "<span class=\"returnType\">void</span> <span class=\"memberName\">staticMethod</span>()</div>\n" 141 + "<div class=\"block\"><span class=\"descfrmTypeLabel\">" 142 + "Description copied from interface: <code>" 143 + "<a href=\"InterfaceWithStaticMembers.html#staticMethod()\">" 144 + "InterfaceWithStaticMembers</a></code></span></div>\n" 145 + "<div class=\"block\">A static method</div>\n"); 146 147 checkOutput("pkg/ClassWithStaticMembers.InnerClass.html", true, 148 "<pre>public static class <span class=\"typeNameLabel\">" 149 + "ClassWithStaticMembers.InnerClass</span>\n" 150 + "extends java.lang.Object</pre>\n" 151 + "<div class=\"block\">A hider inner class</div>"); 152 } 153 154 @Test 155 public void test1() { 156 javadoc("-d", "out-1", 157 "-sourcepath", testSrc, 158 "pkg1"); 159 checkExit(Exit.OK); 160 161 checkOutput("pkg1/Child.html", true, 162 // Ensure the correct Overrides in the inheritance hierarchy is reported 163 "<span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" + 164 "<dd><code><a href=\"GrandParent.html#method1()\">method1</a></code>" + 165 " in class " + 166 "<code><a href=\"GrandParent.html\" title=\"class in pkg1\">GrandParent</a>" + 167 "<<a href=\"Child.html\" title=\"type parameter in Child\">CE</a>></code>"); 168 } 169 170 @Test 171 public void test2() { 172 javadoc("-d", "out-2", 173 "-sourcepath", testSrc, 174 "pkg2"); 175 176 checkExit(Exit.OK); 177 178 checkOutput("pkg2/Spliterator.OfDouble.html", true, 179 // Ensure the correct type parameters are displayed correctly 180 "<h2>Nested classes/interfaces inherited from interface pkg2." 181 + "<a href=\"Spliterator.html\" title=\"interface in pkg2\">Spliterator</a></h2>\n" 182 + "<a id=\"nested.classes.inherited.from.class.pkg2.Spliterator\">\n" 183 + "<!-- -->\n" 184 + "</a><code><a href=\"Spliterator.OfDouble.html\" title=\"interface in pkg2\">" 185 + "Spliterator.OfDouble</a>, <a href=\"Spliterator.OfInt.html\" " 186 + "title=\"interface in pkg2\">Spliterator.OfInt</a><" 187 + "<a href=\"Spliterator.OfInt.html\" title=\"type parameter in Spliterator.OfInt\">" 188 + "Integer</a>>, <a href=\"Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">" 189 + "Spliterator.OfPrimitive</a><<a href=\"Spliterator.OfPrimitive.html\" " 190 + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>,<a href=\"Spliterator.OfPrimitive.html\" " 191 + "title=\"type parameter in Spliterator.OfPrimitive\">T_CONS</a>," 192 + "<a href=\"Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">" 193 + "T_SPLITR</a> extends <a href=\"Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">" 194 + "Spliterator.OfPrimitive</a><<a href=\"Spliterator.OfPrimitive.html\" " 195 + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>," 196 + "<a href=\"Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">" 197 + "T_CONS</a>,<a href=\"Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">" 198 + "T_SPLITR</a>>></code>"); 199 } 200 }