1/* 2 * Copyright (c) 2003, 2017, 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 * @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/jdk.javadoc.internal.tool 34 * @build JavadocTester 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 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 method​()</pre>", 68 "<pre>static final 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><code><a href=\"../pkg/Child.html\" title=\"class in pkg\">Child" 73 + "</a></code>, <code><a href=\"../pkg/Parent.html\" title=\"class in pkg\">Parent" 74 + "</a></code></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><code><a href=\"../pkg/Interface.html\" title=\"interface in pkg\">" 82 + "Interface</a><CE></code></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><CE></li>\n" 91 + "<li>\n" 92 + "<ul class=\"inheritance\">\n" 93 + "<li>pkg.Child<CE></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> in interface <code>" 103 + "<a href=\"../pkg/Interface.html\" title=\"interface in pkg\">" 104 + "Interface</a><<a href=\"../pkg/Child.html\" title=\"type parameter in Child\">" 105 + "CE</a>></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> in class <code><a href=\"../pkg/Parent.html\" " 110 + "title=\"class in pkg\">Parent</a><<a href=\"../pkg/Child.html\" " 111 + "title=\"type parameter in Child\">CE</a>></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><code><a href=\"../pkg/Child.html\" title=\"class in pkg\">Child" 118 + "</a></code></dd>\n" 119 + "</dl>"); 120 121 checkOutput("pkg/Interface.html", false, 122 "public int method​()", 123 "public static final int field"); 124 125 checkOutput("pkg/ClassWithStaticMethod.html", false, 126 //Make sure "Specified By" does not appear on class documentation when 127 //the method is a static method in the interface. 128 "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n"); 129 } 130 131 @Test 132 void test1() { 133 javadoc("-d", "out-1", 134 "-sourcepath", testSrc, 135 "pkg1"); 136 checkExit(Exit.OK); 137 138 checkOutput("pkg1/Child.html", true, 139 // Ensure the correct Overrides in the inheritance hierarchy is reported 140 "<span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" + 141 "<dd><code><a href=\"../pkg1/GrandParent.html#method1--\">method1</a></code>" + 142 " in class " + 143 "<code><a href=\"../pkg1/GrandParent.html\" title=\"class in pkg1\">GrandParent</a>" + 144 "<<a href=\"../pkg1/Child.html\" title=\"type parameter in Child\">CE</a>></code>"); 145 } 146 147 @Test 148 void test2() { 149 javadoc("-d", "out-2", 150 "-sourcepath", testSrc, 151 "pkg2"); 152 153 checkExit(Exit.OK); 154 155 checkOutput("pkg2/Spliterator.OfDouble.html", true, 156 // Ensure the correct type parameters are displayed correctly 157 "<h3>Nested classes/interfaces inherited from interface pkg2." 158 + "<a href=\"../pkg2/Spliterator.html\" title=\"interface in pkg2\">Spliterator</a></h3>\n" + 159 "<code><a href=\"../pkg2/Spliterator.OfDouble.html\" title=\"interface in pkg2\">" 160 + "Spliterator.OfDouble</a>, <a href=\"../pkg2/Spliterator.OfInt.html\" " 161 + "title=\"interface in pkg2\">Spliterator.OfInt</a><" 162 + "<a href=\"../pkg2/Spliterator.OfInt.html\" title=\"type parameter in Spliterator.OfInt\">" 163 + "Integer</a>>, <a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">" 164 + "Spliterator.OfPrimitive</a><<a href=\"../pkg2/Spliterator.OfPrimitive.html\" " 165 + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>,<a href=\"../pkg2/Spliterator.OfPrimitive.html\" " 166 + "title=\"type parameter in Spliterator.OfPrimitive\">T_CONS</a>," 167 + "<a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">" 168 + "T_SPLITR</a> extends <a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">" 169 + "Spliterator.OfPrimitive</a><<a href=\"../pkg2/Spliterator.OfPrimitive.html\" " 170 + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>," 171 + "<a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">" 172 + "T_CONS</a>,<a href=\"../pkg2/Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">" 173 + "T_SPLITR</a>>></code>"); 174 } 175} 176