test/com/sun/javadoc/testPrivateClasses/TestPrivateClasses.java

Wed, 15 Oct 2008 08:07:59 -0700

author
jjg
date
Wed, 15 Oct 2008 08:07:59 -0700
changeset 140
22c4c1143a3a
parent 1
9a66ca7c79fa
child 182
47a62d8d98b4
permissions
-rw-r--r--

6748541: javadoc should be reusable
Reviewed-by: bpatel

     1 /*
     2  * Copyright 2003-2004 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    24 /*
    25  * @test
    26  * @bug      4780441 4874845 4978816
    27  * @summary  Make sure that when the -private flag is not used, members
    28  *           inherited from package private class are documented in the child.
    29  *
    30  *           Make sure that when a method inherits documentation from a method
    31  *           in a non-public class/interface, the non-public class/interface
    32  *           is not mentioned anywhere (not even in the signature or tree).
    33  *
    34  *           Make sure that when a private interface method with generic parameters
    35  *           is implemented, the comments can be inherited properly.
    36  * @author   jamieh
    37  * @library  ../lib/
    38  * @build    JavadocTester
    39  * @build    TestPrivateClasses
    40  * @run main TestPrivateClasses
    41  */
    43 public class TestPrivateClasses extends JavadocTester {
    45     //Test information.
    46     private static final String BUG_ID = "4780441-4874845-4978816";
    48     //Javadoc arguments.
    49     private static final String[] ARGS1 = new String[] {
    50         "-d", BUG_ID + "-1", "-sourcepath", SRC_DIR, "-source", "1.5", "pkg", "pkg2"
    51     };
    52     private static final String[] ARGS2 = new String[] {
    53         "-d", BUG_ID + "-2", "-sourcepath", SRC_DIR, "-private",
    54             "-source", "1.5", "pkg", "pkg2"
    55     };
    57     // Test output when -private flag is not used.
    58     private static final String[][] TEST1 = {
    59         // Field inheritence from non-public superclass.
    60         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
    61             "<A HREF=\"../pkg/PublicChild.html#fieldInheritedFromParent\">" +
    62                 "fieldInheritedFromParent</A>"
    63         },
    65         // Method inheritence from non-public superclass.
    66         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
    67             "<A HREF=\"../pkg/PublicChild.html#methodInheritedFromParent(int)\">" +
    68                 "methodInheritedFromParent</A>"
    69         },
    71         // Field inheritence from non-public superinterface.
    72         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
    73             "<A HREF=\"../pkg/PublicInterface.html#fieldInheritedFromInterface\">" +
    74                 "fieldInheritedFromInterface</A>"
    75         },
    77         // Method inheritence from non-public superinterface.
    78         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
    79             "<A HREF=\"../pkg/PublicInterface.html#methodInterface(int)\">" +
    80                 "methodInterface</A>"
    81         },
    83         // private class does not show up in tree
    84         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
    85             "<PRE>" + NL +
    86                 "java.lang.Object" + NL +
    87                 "  <IMG SRC=\"../resources/inherit.gif\" " +
    88                 "ALT=\"extended by \"><B>pkg.PublicChild</B>" + NL +
    89             "</PRE>"
    90         },
    92         // Method is documented as though it is declared in the inheriting method.
    93         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
    94             "public void <B>methodInheritedFromParent</B>(int&nbsp;p1)"
    95         },
    97         //Make sure implemented interfaces from private superclass are inherited
    98         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
    99             "<B>All Known Implementing Classes:</B> <DD><A HREF=\"../pkg/PublicChild.html\" " +
   100             "title=\"class in pkg\">PublicChild</A>"},
   102         {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
   103             "<B>All Implemented Interfaces:</B> <DD><A HREF=\"../pkg/PublicInterface.html\" " +
   104             "title=\"interface in pkg\">PublicInterface</A>"},
   106         //Generic interface method test.
   107         {BUG_ID + "-1" + FS + "pkg2" + FS + "C.html",
   108             "This comment should get copied to the implementing class"},
   109     };
   110     private static final String[][] NEGATED_TEST1 = {
   111        // Should not document that a method overrides method from private class.
   112       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
   113         "<B>Overrides:</B>"},
   114       // Should not document that a method specified by private interface.
   115       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
   116         "<B>Specified by:</B>"},
   117       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
   118         "<B>Specified by:</B>"},
   119       // Should not mention that any documentation was copied.
   120       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
   121         "Description copied from"},
   122       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
   123         "Description copied from"},
   124       // Don't extend private classes or interfaces
   125       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
   126         "PrivateParent"},
   127       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
   128         "PrivateInterface"},
   129       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicChild.html",
   130         "PrivateInterface"},
   131       {BUG_ID + "-1" + FS + "pkg" + FS + "PublicInterface.html",
   132         "All Superinterfaces"},
   133       // Make inherited constant are documented correctly.
   134       {BUG_ID + "-1" + FS + "constant-values.html",
   135         "PrivateInterface"},
   137         //Do not inherit private interface method with generic parameters.
   138         //This method has been implemented.
   139         {BUG_ID + "-1" + FS + "pkg2" + FS + "C.html",
   140             "<B><A HREF=\"../pkg2/I.html#hello(T)\">hello</A></B>"},
   141     };
   143     // Test output when -private flag is used.
   144     private static final String[][] TEST2 = {
   145         // Field inheritence from non-public superclass.
   146         {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   147             "Fields inherited from class " +
   148             "pkg.<A HREF=\"../pkg/PrivateParent.html\" " +
   149             "title=\"class in pkg\">PrivateParent</A>"
   150         },
   151         {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   152             "<A HREF=\"../pkg/PrivateParent.html#fieldInheritedFromParent\">" +
   153                 "fieldInheritedFromParent</A>"
   154         },
   155         // Field inheritence from non-public superinterface.
   156         {BUG_ID + "-2" + FS + "pkg" + FS + "PublicInterface.html",
   157             "Fields inherited from interface " +
   158             "pkg.<A HREF=\"../pkg/PrivateInterface.html\" " +
   159             "title=\"interface in pkg\">PrivateInterface</A>"
   160         },
   161         {BUG_ID + "-2" + FS + "pkg" + FS + "PublicInterface.html",
   162             "<A HREF=\"../pkg/PrivateInterface.html#fieldInheritedFromInterface\">" +
   163                 "fieldInheritedFromInterface</A>"
   164         },
   165         // Method inheritence from non-public superclass.
   166         {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   167             "Methods inherited from class " +
   168             "pkg.<A HREF=\"../pkg/PrivateParent.html\" " +
   169             "title=\"class in pkg\">PrivateParent</A>"
   170         },
   171         {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   172             "<A HREF=\"../pkg/PrivateParent.html#methodInheritedFromParent(int)\">" +
   173                 "methodInheritedFromParent</A>"
   174         },
   175         // Should document that a method overrides method from private class.
   176        {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   177             "<B>Overrides:</B><DD><CODE>" +
   178             "<A HREF=\"../pkg/PrivateParent.html#methodOverridenFromParent(char[], int, T, V, java.util.List)\">" +
   179             "methodOverridenFromParent</A></CODE> in class <CODE>" +
   180             "<A HREF=\"../pkg/PrivateParent.html\" title=\"class in pkg\">" +
   181             "PrivateParent</A></CODE></DL>"},
   182        // Should document that a method is specified by private interface.
   183        {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   184             "<B>Specified by:</B><DD><CODE>" +
   185             "<A HREF=\"../pkg/PrivateInterface.html#methodInterface(int)\">" +
   186             "methodInterface</A></CODE> in interface <CODE>" +
   187             "<A HREF=\"../pkg/PrivateInterface.html\" title=\"interface in pkg\">" +
   188             "PrivateInterface</A></CODE></DL>" + NL + "</DD>"},
   189        // Method inheritence from non-public superinterface.
   190        {BUG_ID + "-2" + FS + "pkg" + FS + "PublicInterface.html",
   191             "Methods inherited from interface " +
   192             "pkg.<A HREF=\"../pkg/PrivateInterface.html\" " +
   193             "title=\"interface in pkg\">PrivateInterface</A>"
   194         },
   195         {BUG_ID + "-2" + FS + "pkg" + FS + "PrivateInterface.html",
   196             "<A HREF=\"../pkg/PrivateInterface.html#methodInterface(int)\">" +
   197                 "methodInterface</A>"
   198         },
   199       // Should mention that any documentation was copied.
   200       {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   201         "Description copied from"},
   202       // Extend documented private classes or interfaces
   203       {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   204         "extends"},
   205       {BUG_ID + "-2" + FS + "pkg" + FS + "PublicInterface.html",
   206         "extends"},
   207       {BUG_ID + "-2" + FS + "pkg" + FS + "PublicInterface.html",
   208         "All Superinterfaces"},
   210       //Make sure implemented interfaces from private superclass are inherited
   211       {BUG_ID + "-2" + FS + "pkg" + FS + "PublicInterface.html",
   212         "<B>All Known Implementing Classes:</B> <DD><A HREF=\"../pkg/PrivateParent.html\" " +
   213         "title=\"class in pkg\">PrivateParent</A>, " +
   214         "<A HREF=\"../pkg/PublicChild.html\" title=\"class in pkg\">PublicChild</A>"},
   216       {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
   217         "<B>All Implemented Interfaces:</B> <DD><A HREF=\"../pkg/PrivateInterface.html\" " +
   218         "title=\"interface in pkg\">PrivateInterface</A>, " +
   219         "<A HREF=\"../pkg/PublicInterface.html\" title=\"interface in pkg\">" +
   220         "PublicInterface</A>"},
   222       //Since private flag is used, we can document that private interface method
   223       //with generic parameters has been implemented.
   224       {BUG_ID + "-2" + FS + "pkg2" + FS + "C.html",
   225             "<B>Description copied from interface: " +
   226             "<CODE><A HREF=\"../pkg2/I.html#hello(T)\">I</A></CODE></B>"},
   228       {BUG_ID + "-2" + FS + "pkg2" + FS + "C.html",
   229             "<B>Specified by:</B><DD><CODE><A HREF=\"../pkg2/I.html#hello(T)\">" +
   230             "hello</A></CODE> in interface <CODE><A HREF=\"../pkg2/I.html\" " +
   231             "title=\"interface in pkg2\">I</A>"},
   232     };
   233     private static final String[][] NEGATED_TEST2 = NO_TEST;
   235     /**
   236      * The entry point of the test.
   237      * @param args the array of command line arguments.
   238      */
   239     public static void main(String[] args) {
   240         TestPrivateClasses tester = new TestPrivateClasses();
   241         run(tester, ARGS1, TEST1, NEGATED_TEST1);
   242         run(tester, ARGS2, TEST2, NEGATED_TEST2);
   243         tester.printSummary();
   244     }
   246     /**
   247      * {@inheritDoc}
   248      */
   249     public String getBugId() {
   250         return BUG_ID;
   251     }
   253     /**
   254      * {@inheritDoc}
   255      */
   256     public String getBugName() {
   257         return getClass().getName();
   258     }
   259 }

mercurial