1 /*
   2  * Copyright (c) 2002, 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 4638588 4635809 6256068 6270645 8025633 8026567 8162363 8175200
  27  *      8192850 8182765 8220217
  28  * @summary Test to make sure that members are inherited properly in the Javadoc.
  29  *          Verify that inheritance labels are correct.
  30  * @library ../../lib
  31  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  32  * @build javadoc.tester.*
  33  * @run main TestMemberInheritance
  34  */
  35 
  36 import javadoc.tester.JavadocTester;
  37 
  38 public class TestMemberInheritance extends JavadocTester {
  39 
  40     public static void main(String... args) throws Exception {
  41         TestMemberInheritance tester = new TestMemberInheritance();
  42         tester.runTests();
  43     }
  44 
  45     @Test
  46     public void test() {
  47         javadoc("-d", "out",
  48                 "-sourcepath", testSrc,
  49                 "pkg", "diamond", "inheritDist", "pkg1", "pkg2");
  50         checkExit(Exit.OK);
  51 
  52         checkOutput("pkg/SubClass.html", true,
  53                 // Public field should be inherited
  54                 "<a href=\"BaseClass.html#pubField\">",
  55                 // Public method should be inherited
  56                 "<a href=\"BaseClass.html#pubMethod()\">",
  57                 // Public inner class should be inherited.
  58                 "<a href=\"BaseClass.pubInnerClass.html\" title=\"class in pkg\">",
  59                 // Protected field should be inherited
  60                 "<a href=\"BaseClass.html#proField\">",
  61                 // Protected method should be inherited
  62                 "<a href=\"BaseClass.html#proMethod()\">",
  63                 // Protected inner class should be inherited.
  64                 "<a href=\"BaseClass.proInnerClass.html\" title=\"class in pkg\">",
  65                 // New labels as of 1.5.0
  66                 "Nested classes/interfaces inherited from class&nbsp;pkg."
  67                 + "<a href=\"BaseClass.html\" title=\"class in pkg\">BaseClass</a>",
  68                 "Nested classes/interfaces inherited from interface&nbsp;pkg."
  69                 + "<a href=\"BaseInterface.html\" title=\"interface in pkg\">BaseInterface</a>");
  70 
  71         checkOutput("pkg/BaseClass.html", true,
  72                 // Test overriding/implementing methods with generic parameters.
  73                 "<dl>\n"
  74                 + "<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n"
  75                 + "<dd><code><a href=\"BaseInterface.html#getAnnotation(java.lang.Class)\">"
  76                 + "getAnnotation</a></code>&nbsp;in interface&nbsp;<code>"
  77                 + "<a href=\"BaseInterface.html\" title=\"interface in pkg\">"
  78                 + "BaseInterface</a></code></dd>\n"
  79                 + "</dl>");
  80 
  81         checkOutput("diamond/Z.html", true,
  82                 // Test diamond inheritance member summary (6256068)
  83                 "<code><a href=\"A.html#aMethod()\">aMethod</a></code>");
  84 
  85         checkOutput("inheritDist/C.html", true,
  86                 // Test that doc is inherited from closed parent (6270645)
  87                 "<div class=\"block\">m1-B</div>");
  88 
  89         checkOutput("pkg/SubClass.html", false,
  90                 "<a href=\"BaseClass.html#staticMethod()\">staticMethod</a></code>");
  91 
  92         checkOutput("pkg1/Implementer.html", true,
  93                 // ensure the method makes it
  94                 "<td class=\"colFirst\"><code>static java.time.Period</code></td>\n"
  95                 + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
  96                 + "<a href=\"#between(java.time.LocalDate,java.time.LocalDate)\">"
  97                 + "between</a></span>​(java.time.LocalDate&nbsp;startDateInclusive,\n"
  98                 + "java.time.LocalDate&nbsp;endDateExclusive)</code></th>");
  99 
 100         checkOutput("pkg1/Implementer.html", false,
 101                 "<h3>Methods inherited from interface&nbsp;pkg1.<a href=\"Interface.html\""
 102                 + " title=\"interface in pkg1\">Interface</a></h3>\n"
 103                 + "<code><a href=\"Interface.html#between(java.time.chrono.ChronoLocalDate"
 104                 + ",java.time.chrono.ChronoLocalDate)\">between</a></code>"
 105         );
 106 
 107         checkOutput("pkg2/DocumentedNonGenericChild.html", true,
 108                 "<section class=\"description\">\n<hr>\n"
 109                 + "<pre>public abstract class <span class=\"typeNameLabel\">"
 110                 + "DocumentedNonGenericChild</span>\n"
 111                 + "extends java.lang.Object</pre>\n"
 112                 + "</section>");
 113 
 114         checkOutput("pkg2/DocumentedNonGenericChild.html", true,
 115                 "<td class=\"colFirst\"><code>protected abstract java.lang.String</code></td>\n"
 116                 + "<th class=\"colSecond\" scope=\"row\"><code><span class=\"memberNameLink\">"
 117                 + "<a href=\"#parentMethod()\">parentMethod</a></span>()</code></th>\n"
 118                 + "<td class=\"colLast\">\n"
 119                 + "<div class=\"block\">Returns some value.</div>\n"
 120                 + "</td>\n");
 121 
 122         checkOutput("pkg2/DocumentedNonGenericChild.html", true,
 123                 "<h3><a id=\"parentMethod()\">parentMethod</a></h3>\n"
 124                 + "<div class=\"memberSignature\"><span class=\"modifiers\">protected abstract</span>"
 125                 + "&nbsp;<span class=\"returnType\">java.lang.String</span>&nbsp;"
 126                 + "<span class=\"memberName\">parentMethod</span>()</div>");
 127 
 128     }
 129 }