/* * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4789689 4905985 4927164 4827184 4993906 5004549 7025314 7010344 8025633 8026567 8162363 * 8175200 8186332 8182765 8196202 8187288 8173730 8215307 8312445 * @summary Run Javadoc on a set of source files that demonstrate new * language features. Check the output to ensure that the new * language features are properly documented. * @library ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * @build javadoc.tester.* * @run main TestNewLanguageFeatures */ import javadoc.tester.JavadocTester; public class TestNewLanguageFeatures extends JavadocTester { public static void main(String... args) throws Exception { var tester = new TestNewLanguageFeatures(); tester.runTests(); } @Test public void test() { javadoc("-Xdoclint:none", "-d", "out", "-use", "--no-platform-links", "-sourcepath", testSrc, "pkg", "pkg1", "pkg2"); checkExit(Exit.OK); checkEnums(); checkTypeParameters(); checkVarArgs(); checkAnnotationTypeUsage(); } //================================= // ENUM TESTING //================================= void checkEnums() { checkOutput("pkg/Coin.html", true, // Make sure enum header is correct. "Enum Class Coin", // Make sure enum signature is correct. """
public enum Coin extends java.lang.Enum<Coin>
""", // Check for enum constant section """
Enum Constants
""", // Detail for enum constant """ Dime""", // Automatically insert documentation for values() and valueOf(). "Returns an array containing the constants of this enum class,", "Returns the enum constant of this class with the specified name", "Overloaded valueOf() method has correct documentation.", "Overloaded values method has correct documentation.", """
public static \ Coin\  valueOf(java.lang.String name)
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are\s not permitted.)
Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum class has no constant with the specified name
java.lang.NullPointerException - if the argument is null
"""); // NO constructor section checkOutput("pkg/Coin.html", false, "

Constructor Summary

"); } //================================= // TYPE PARAMETER TESTING //================================= void checkTypeParameters() { checkOutput("pkg/TypeParameters.html", true, // Make sure the header is correct. "Class TypeParameters<E>", // Check class type parameters section. """
Type Parameters:
E - the type parameter for this class.""", // Type parameters in @see/@link """
See Also:
""", // Method that uses class type parameter. """ (E param)""", // Method type parameter section. """
Type Parameters:
T - This is the first type parameter.
V - This is the second type parameter.""", // Signature of method with type parameters """
public <T extends java.util.List, V> java.lang.String[] meth\ odThatHasTypeParameters(T param1, V param2)
""", // Method that returns TypeParameters """
E[]
methodThatReturnsTypeParameterA(E[] \ e)""", """
public E[] methodThatReturnsTypePa\ rameterA(E[] e)
""", """
<T extends java.lang.Object & java.l\ ang.Comparable<? super T>>
T
methodtThatReturnsTypeParamete\ rsB(java.util.Collection<? extends T> coll)""", """
Returns TypeParameters
""", // Method takes a TypeVariable """
<X extends java.lang.Throwable>
E
\
orElseThrow(java.util.function.\ Supplier<? extends X> exceptionSupplier)""" ); checkOutput("pkg/Wildcards.html", true, // Wildcard testing. """ TypeParameters<? super java.lang.String> a""", """ TypeParameters<? extends java.lang.StringBuffer> b""", """ TypeParameters c"""); checkOutput(Output.OUT, true, // Bad type parameter warnings. """ warning: @param argument "" is not the name of a type parameter.""", """ warning: @param argument "" is not the name of a type parameter."""); // Signature of subclass that has type parameters. checkOutput("pkg/TypeParameterSubClass.html", true, """
public class TypeParameterSubClass<T extends java.lang.\ String> extends TypeParameterSuperClass<T>
"""); // Interface generic parameter substitution // Signature of subclass that has type parameters. checkOutput("pkg/TypeParameters.html", true, """
All Implemented Interfaces:
SubInterface&\ lt;E>, Su\ perInterface<E>
"""); checkOutput("pkg/SuperInterface.html", true, """
All Known Subinterfaces:
SubInterface<V>
"""); checkOutput("pkg/SubInterface.html", true, """
All Superinterfaces:
SuperInterface<V>
"""); //============================================================== // Handle multiple bounds. //============================================================== checkOutput("pkg/MultiTypeParameters.html", true, """
public <T extends java.lang.Number & java.lang.Runnable&g\ t; T foo(T t)
"""); //============================================================== // Test Class-Use Documentation for Type Parameters. //============================================================== // ClassUseTest1: checkOutput("pkg2/class-use/Foo.html", true, """
Classes in pkg2 with type p\ arameters of type Foo""", """
ClassUseTest1<T extends Foo & Foo2>
""", """ """, """ """, """
Fields in pkg2\ with type parameters of type Foo
""", """ """ ); checkOutput("pkg2/class-use/ParamTest.html", true, """
Fields in pkg2\ declared as ParamTest
""", """ """ ); checkOutput("pkg2/class-use/Foo2.html", true, """ """, """
ClassUseTest1<T extends Foo & Foo2>
""", """ """, """
ClassUseTes\ t1.method(T t)
""" ); // ClassUseTest2: > checkOutput("pkg2/class-use/ParamTest.html", true, """ """, """ """, """ """, """
ClassUseTes\ t2.method(T t)
""", """
Fields in pkg2\ declared as ParamTest
""", """ """, """ """, """ """ ); checkOutput("pkg2/class-use/Foo3.html", true, """ """, """ """, """ """, """
ClassUseTes\ t2.method(T t)
""", """ """, """ """ ); // ClassUseTest3: >> checkOutput("pkg2/class-use/ParamTest2.html", true, """ """, """
ClassUseTest3<T extends ParamTest2<java.util.List&\ lt;? extends Foo4>>><\ /code>
""", """ """, """
ClassUseTes\ t3.method(T t)
""", """
<T extends ParamTest2<java.util.List<? extends Foo4>>>
ParamTest2<java.util.List<? ext\ ends Foo4>>
""" ); checkOutput("pkg2/class-use/Foo4.html", true, """ """, """
ClassUseTest3<T extends ParamTest2<java.util.List&\ lt;? extends Foo4>>><\ /code>
""", """ """, """
ClassUseTes\ t3.method(T t)
""", """ """, """
<T extends ParamTest2<java.util.List<? extends Foo4>>>
ParamTest2<java.util.List<? ex\ tends Foo4>>
""" ); // Type parameters in constructor and method args checkOutput("pkg2/class-use/Foo4.html", true, """
Method parameters in pkg2 with type arguments of type Foo4
Modifier and Type
Method
Description
void
ClassUseTes\ t3.method(java.util.Set<Foo4> p)
 
""", """ """ ); //================================= // TYPE PARAMETER IN INDEX //================================= checkOutput("index-all.html", true, """ method(Vector<Object>)""" ); // TODO: duplicate of previous case; left in delibarately for now to simplify comparison testing //================================= // TYPE PARAMETER IN INDEX //================================= checkOutput("index-all.html", true, """ method(Vector<Object>)""" ); } //================================= // VAR ARG TESTING //================================= void checkVarArgs() { checkOutput("pkg/VarArgs.html", true, "(int... i)", "(int[][]... i)", "(int[]...)", """ TypeParameters... t"""); } //================================= // ANNOTATION TYPE TESTING //================================= void checkAnnotationTypes() { checkOutput("pkg/AnnotationType.html", true, // Make sure the summary links are correct. """
  • Summary: 
  • Field | 
  • Required | 
  • Optional
  • """, // Make sure the detail links are correct. """
  • Detail: 
  • Field | 
  • Element
  • """, // Make sure the heading is correct. "Annotation Type AnnotationType", // Make sure the signature is correct. """ public @interface AnnotationType""", // Make sure member summary headings are correct. "

    Required Element Summary

    ", "

    Optional Element Summary

    ", // Make sure element detail heading is correct "Element Detail", // Make sure default annotation type value is printed when necessary. """
    Default:
    "unknown"
    """); } //================================= // ANNOTATION TYPE USAGE TESTING //================================= void checkAnnotationTypeUsage() { checkOutput("pkg/package-summary.html", true, // PACKAGE """ @AnnotationTyp\ e(optional="Package Annotation", required=1994)"""); checkOutput("pkg/AnnotationTypeUsage.html", true, // CLASS """
    @AnnotationType(optional="Class Annotation", required=1994) public class AnnotationTypeUsage extends java.lang.Object
    """, // FIELD """
    @AnnotationType(optional="Field Annotation", required=1994) public int<\ /span> field
    """, // CONSTRUCTOR """
    @AnnotationType(optional="Constructor Annotation", required=1994) public AnnotationTypeUsage()
    """, // METHOD """
    @AnnotationType(optional="Method Annotation", required=1994) public void\  method()
    """, // METHOD PARAMS """
    public void methodWithParams<\ /span>(@AnnotationType(optional="Parameter Annotation",required=1994) int documented, int undocmented)
    """, // CONSTRUCTOR PARAMS """
    public AnnotationTypeUsage(@AnnotationType(optional="Constructor Param Anno\ tation",required=1994) int documented, int undocmented)
    """); //================================= // Annotatation Type Usage //================================= checkOutput("pkg/class-use/AnnotationType.html", true, """
    Packages with annotations of type AnnotationType""", """
    Classes in pkg\ with annotations of type AnnotationType
    """, """
    Fields in pkg\ with annotations of type AnnotationType
    """, """
    Methods in pkg\ with annotations of type AnnotationType
    """, """
    Method parameters in pkg with annotations of type AnnotationType
    """, """
    Constructors in pk\ g with annotations of type AnnotationType
    """, """
    Constructor parameters in pkg with annotations of type AnnotationType
    """ ); //============================================================== // ANNOTATION TYPE USAGE TESTING (When @Documented is omitted) //=============================================================== checkOutput("pkg/AnnotationTypeUsage.html", false, // CLASS """ @A\ nnotationTypeUndocumented(optional="Class Annotation", required=1994) public class AnnotationTypeUsage
    extends java.lang.Object
    """, // FIELD """ @A\ nnotationTypeUndocumented(optional="Field Annotation", required=1994) public int field""", // CONSTRUCTOR """ @A\ nnotationTypeUndocumented(optional="Constructor Annotation", required=1994) public AnnotationTypeUsage()""", // METHOD """ @A\ nnotationTypeUndocumented(optional="Method Annotation", required=1994) public void method()"""); //================================= // Make sure annotation types do not // trigger this warning. //================================= checkOutput(Output.OUT, false, "Internal error: package sets don't match: [] with: null"); //================================= // ANNOTATION TYPE USAGE TESTING (All Different Types). //================================= checkOutput("pkg1/B.html", true, // Integer "d=3.14,", // Double "d=3.14,", // Boolean "b=true,", // String """ s="sigh",""", // Class """ c=Foo.class,""", // Bounded Class """ w=TypeParameterSubClass.class,""", // Enum """ e=Penny,""", // Annotation Type """ a=@AnnotationType(optional="foo",requi\ red=1994),""", // String Array """ sa={"up","down"},""", // Primitive """ primitiveClassTest=boolean.class,""", // Arrays """ arrayClassTest=java.lang.String[][].class,""", """ arrayPrimitiveTest=boolean[].class,""", """ classArrayTest={TypeParameterSubClass[][].class,java.\ lang.String.class,long[][][].class})"""); checkOutput("pkg1/B.html", true, """
    @A""", """ public interface B
    """); } }