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>&nbsp;"
  70                 + "<span class=\"memberName\">method</span>()</div>",
  71                 "<div class=\"memberSignature\"><span class=\"modifiers\">static final</span>&nbsp;"
  72                 + "<span class=\"returnType\">int</span>&nbsp;<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>&lt;CE&gt;</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>&lt;CE&gt;\n"
  92                 + "<div class=\"inheritance\">pkg.Child&lt;CE&gt;</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>&nbsp;in interface&nbsp;<code>"
  98                 + "<a href=\"Interface.html\" title=\"interface in pkg\">"
  99                 + "Interface</a>&lt;<a href=\"Child.html\" title=\"type parameter in Child\">"
 100                 + "CE</a>&gt;</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>&nbsp;in class&nbsp;<code><a href=\"Parent.html\" "
 105                 + "title=\"class in pkg\">Parent</a>&lt;<a href=\"Child.html\" "
 106                 + "title=\"type parameter in Child\">CE</a>&gt;</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&nbsp;method--",
 118                 "public static final&nbsp;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                 "<section class=\"detail\" id=\"f\">\n"
 127                 + "<h3>f</h3>\n"
 128                 + "<div class=\"memberSignature\"><span class=\"modifiers\">public static</span>&nbsp;"
 129                 + "<span class=\"returnType\">int</span>&nbsp;<span class=\"memberName\">f</span></div>\n"
 130                 + "<div class=\"block\">A hider field</div>",
 131 
 132                 "<td class=\"colFirst\"><code>static void</code></td>\n"
 133                 + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
 134                 + "<a href=\"#m()\">m</a></span>()</code></th>\n"
 135                 + "<td class=\"colLast\">\n"
 136                 + "<div class=\"block\">A hider method</div>\n"
 137                 + "</td>\n",
 138 
 139                 "<section class=\"detail\" id=\"staticMethod()\">\n"
 140                 + "<h3>staticMethod</h3>\n"
 141                 + "<div class=\"memberSignature\"><span class=\"modifiers\">public static</span>&nbsp;"
 142                 + "<span class=\"returnType\">void</span>&nbsp;<span class=\"memberName\">staticMethod</span>()</div>\n"
 143                 + "<div class=\"block\"><span class=\"descfrmTypeLabel\">"
 144                 + "Description copied from interface:&nbsp;<code>"
 145                 + "<a href=\"InterfaceWithStaticMembers.html#staticMethod()\">"
 146                 + "InterfaceWithStaticMembers</a></code></span></div>\n"
 147                 + "<div class=\"block\">A static method</div>\n");
 148 
 149         checkOutput("pkg/ClassWithStaticMembers.InnerClass.html", true,
 150                 "<pre>public static class <span class=\"typeNameLabel\">"
 151                 + "ClassWithStaticMembers.InnerClass</span>\n"
 152                 + "extends java.lang.Object</pre>\n"
 153                 + "<div class=\"block\">A hider inner class</div>");
 154     }
 155 
 156     @Test
 157     public void test1() {
 158         javadoc("-d", "out-1",
 159                 "-sourcepath", testSrc,
 160                 "pkg1");
 161         checkExit(Exit.OK);
 162 
 163         checkOutput("pkg1/Child.html", true,
 164             // Ensure the correct Overrides in the inheritance hierarchy is reported
 165             "<span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n" +
 166             "<dd><code><a href=\"GrandParent.html#method1()\">method1</a></code>" +
 167             "&nbsp;in class&nbsp;" +
 168             "<code><a href=\"GrandParent.html\" title=\"class in pkg1\">GrandParent</a>" +
 169             "&lt;<a href=\"Child.html\" title=\"type parameter in Child\">CE</a>&gt;</code>");
 170     }
 171 
 172     @Test
 173     public void test2() {
 174         javadoc("-d", "out-2",
 175                 "-sourcepath", testSrc,
 176                 "pkg2");
 177 
 178         checkExit(Exit.OK);
 179 
 180         checkOutput("pkg2/Spliterator.OfDouble.html", true,
 181             // Ensure the correct type parameters are displayed correctly
 182             "<h2 id=\"nested.classes.inherited.from.class.pkg2.Spliterator\">"
 183             + "Nested classes/interfaces inherited from interface&nbsp;pkg2."
 184             + "<a href=\"Spliterator.html\" title=\"interface in pkg2\">Spliterator</a></h2>\n"
 185             + "<code><a href=\"Spliterator.OfDouble.html\" title=\"interface in pkg2\">"
 186             + "Spliterator.OfDouble</a>, <a href=\"Spliterator.OfInt.html\" "
 187             + "title=\"interface in pkg2\">Spliterator.OfInt</a>&lt;"
 188             + "<a href=\"Spliterator.OfInt.html\" title=\"type parameter in Spliterator.OfInt\">"
 189             + "Integer</a>&gt;, <a href=\"Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">"
 190             + "Spliterator.OfPrimitive</a>&lt;<a href=\"Spliterator.OfPrimitive.html\" "
 191             + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>,​<a href=\"Spliterator.OfPrimitive.html\" "
 192             + "title=\"type parameter in Spliterator.OfPrimitive\">T_CONS</a>,​"
 193             + "<a href=\"Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">"
 194             + "T_SPLITR</a> extends <a href=\"Spliterator.OfPrimitive.html\" title=\"interface in pkg2\">"
 195             + "Spliterator.OfPrimitive</a>&lt;<a href=\"Spliterator.OfPrimitive.html\" "
 196             + "title=\"type parameter in Spliterator.OfPrimitive\">T</a>,​"
 197             + "<a href=\"Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">"
 198             + "T_CONS</a>,​<a href=\"Spliterator.OfPrimitive.html\" title=\"type parameter in Spliterator.OfPrimitive\">"
 199             + "T_SPLITR</a>&gt;&gt;</code>");
 200     }
 201 }