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