/*
* Copyright (c) 2003, 2020, 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
* @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 {
TestNewLanguageFeatures tester = new TestNewLanguageFeatures();
tester.runTests();
}
@Test
public void test() {
javadoc("-Xdoclint:none",
"-d", "out",
"-use",
"-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 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 type,",
"Returns the enum constant of this type 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 type with the specified name.
The string must match exactly an identifier used to declare an
enum constant in this type. (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 type 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:
TypeParameters
""",
// 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[] methodThatHasTypeParameters(T par\
am1,
V param2)
""",
// Method that returns TypeParameters
"""
E[] |
methodThatReturnsTypeParameterA<\
/span>(E[] e) """,
"""
public E[] methodThatReturnsTypePar\
ameterA( E[] e)
""",
"""
| <T extends java.lang.Object & java.lang.Compa\
rable<? super T>> T |
methodtThatReturnsTyp\
eParametersB(java.util.Collection<? extends T> coll\
) """,
"""
Returns TypeParameters
""",
// Method takes a TypeVariable
"""
| <X extends java.lang.Throwable> E |
orElseThrow(java.u\
til.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 fooR\
03;(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> | """,
"""
Methods in pkg2 with type p\
arameters of type Foo""",
"""
ClassUseTest1.<\
/span>method(T t) | """,
"""
Fields in pkg2 with type pa\
rameters of type Foo""",
"""
td class="col-first">Par\
amTest<Foo> """
);
checkOutput("pkg2/class-use/ParamTest.html", true,
"""
Fields in pkg2 declared as \
ParamTest""",
"""
Pa\
ramTest<Foo> """
);
checkOutput("pkg2/class-use/Foo2.html", true,
"""
Classes in pkg2 with type p\
arameters of type Foo2""",
"""
| ClassUseTest1<T extends Foo & Foo2> | """,
"""
Methods in pkg2 with type p\
arameters of type Foo2""",
"""
ClassUseTest1.<\
/span>method(T t) | """
);
// ClassUseTest2: >
checkOutput("pkg2/class-use/ParamTest.html", true,
"""
Classes in pkg2 with type p\
arameters of type ParamTest""",
"""
ClassUseTest2<T extends ParamTest<Foo3>> | """,
"""
Methods in pkg2 with type p\
arameters of type ParamTest""",
"""
ClassUseTest2.<\
/span>method(T t) | """,
"""
Fields in pkg2 declared as \
ParamTest""",
"""
Pa\
ramTest<Foo> """,
"""
Methods in pkg2 with type p\
arameters of type ParamTest""",
"""
| <T extends ParamTest<Foo3\
a>>> ParamTest<\
;Foo3> | """
);
checkOutput("pkg2/class-use/Foo3.html", true,
"""
Classes in pkg2 with type p\
arameters of type Foo3\
caption>""",
"""
ClassUseTest2<T extends ParamTest<Foo3>> | """,
"""
Methods in pkg2 with type p\
arameters of type Foo3\
caption>""",
"""
ClassUseTest2.<\
/span>method(T t) | """,
"""
Methods in pkg2 that return\
types with arguments of type Foo3<\
/a>""",
"""
<T extends ParamTest<Foo3\
a>>> ParamTest<\
;Foo3> | """
);
// ClassUseTest3: >>
checkOutput("pkg2/class-use/ParamTest2.html", true,
"""
Classes in pkg2 with type p\
arameters of type ParamTest2<\
/a>""",
"""
ClassUseTest3<T extends ParamTest2<java.util.List\
<? extends Foo4>>><\
/span> | """,
"""
Methods in pkg2 with type p\
arameters of type ParamTest2<\
/a>""",
"""
ClassUseTest3.<\
/span>method(T t) | """,
"""
<T extends ParamTest2<java.util.List<? extends Foo4>>> ParamTest2<java.util.List<? extends Foo4>> | """
);
checkOutput("pkg2/class-use/Foo4.html", true,
"""
Classes in pkg2 with type p\
arameters of type Foo4\
caption>""",
"""
ClassUseTest3<T extends ParamTest2<java.util.List\
<? extends Foo4>>><\
/span> | """,
"""
Methods in pkg2 with type p\
arameters of type Foo4\
caption>""",
"""
ClassUseTest3.<\
/span>method(T t) | """,
"""
Methods in pkg2 that return\
types with arguments of type Foo4<\
/a>""",
"""
<T extends ParamTest2<java.util.List<? extends Foo4>>> ParamTest2<java.util.List<? extends Foo4>> | """
);
// Type parameters in constructor and method args
checkOutput("pkg2/class-use/Foo4.html", true,
"""
Method parameters in pkg2 w\
ith type arguments of type Foo4\
Modifier and Type |
Method |
Description |
void |
ClassUseTest3.<\
/span>method(java.util.Set<Foo4> p) | """,
"""
Constructor parameters in pkg2<\
/a> with type arguments of type Foo\
4"""
);
//=================================
// 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
"""
@AnnotationType(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
"""
""",
// CONSTRUCTOR
"""
""",
// METHOD
"""
""",
// METHOD PARAMS
"""
""",
// CONSTRUCTOR PARAMS
"""
public AnnotationTypeUsage( @AnnotationType(optional="Constructor Param Annotation",<\
a href="AnnotationType.html#required()">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 annotat\
ions of type Annotati\
onType""",
"""
Fields in pkg with annotati\
ons of type Annotatio\
nType""",
"""
Methods in pkg with annotat\
ions of type Annotati\
onType""",
"""
Method parameters in pkg wi\
th annotations of type AnnotationType""",
"""
Constructors in pkg with an\
notations of type Ann\
otationType""",
"""
Constructor parameters in pkg\
a> with annotations of type AnnotationType"""
);
//==============================================================
// ANNOTATION TYPE USAGE TESTING (When @Documented is omitted)
//===============================================================
checkOutput("pkg/AnnotationTypeUsage.html", false,
// CLASS
"""
@AnnotationT\
ypeUndocumented(optional="Class A\
nnotation",
required=1994)
public class AnnotationTypeUsage- extends java.lang.Object
""",
// FIELD
"""
@AnnotationT\
ypeUndocumented(optional="Field A\
nnotation",
required=1994)
public int field""",
// CONSTRUCTOR
"""
@AnnotationT\
ypeUndocumented(optional="Constru\
ctor Annotation",
required=1994)
public AnnotationTypeUsage()""",
// METHOD
"""
@AnnotationT\
ypeUndocumented(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(op\
tional="foo",required=19\
94),""",
// String Array
"""
sa={"up","down"},""",
// Primitive
"""
primitiveClassTest=boolean.class,""");
// XXX: Add array test case after this if fixed:
//5020899: Incorrect internal representation of class-valued annotation elements
// Make sure that annotations are surrounded by and
checkOutput("pkg1/B.html", true,
"""
@A""",
"""
public interface B """);
}
}
|