undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,39 @@
###########################################################################
#
# Copyright (c) 2025, 2026, 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.
#
###########################################################################
# Currently empty
#############################################################################
# Preview project specific failures go here at the end of the file.
#
# These are NOT failures that occur with the '--enable-preview' option
# specified; those go in the appropriate ProblemList-enable-preview.txt file.
# These are failures that occur WITHOUT the '--enable-preview' option
# specified AND occur because of some issue with preview project code,
# in either implementation or test code.
#############################################################################

View file

@ -0,0 +1,32 @@
#
# Copyright (c) 2025, 2026, 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.
#
#############################################################################
#
# List of quarantined tests for testing with --enable-preview
#
# These are failures that ONLY occur with the '--enable-preview' option
# specified. There are separate sub-sections for each preview project.
#
#############################################################################

View file

@ -0,0 +1,86 @@
###########################################################################
#
# Copyright (c) 2015, 2026, 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.
#
###########################################################################
#############################################################################
#
# List of quarantined tests -- tests that should not be run by default, because
# they may fail due to known reason. The reason (CR#) must be mandatory specified.
#
# List items are testnames followed by labels, all MUST BE commented
# as to why they are here and use a label:
# generic-all Problems on all platforms
# generic-ARCH Where ARCH is one of: x64, i586, ppc64, ppc64le, s390x etc.
# OSNAME-all Where OSNAME is one of: linux, windows, macosx, aix
# OSNAME-ARCH Specific on to one OSNAME and ARCH, e.g. macosx-x64
# OSNAME-REV Specific on to one OSNAME and REV, e.g. macosx-10.7.4
#
# More than one label is allowed but must be on the same line.
#
#############################################################################
###########################################################################
#
# javadoc
###########################################################################
#
# jshell
jdk/jshell/UserJdiUserRemoteTest.java 8173079 linux-all
jdk/jshell/UserInputTest.java 8169536 generic-all
jdk/jshell/ToolBasicTest.java 8265357 macosx-aarch64
jdk/jshell/HighlightUITest.java 8284144 generic-all
###########################################################################
#
# javac
tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java 8057687 generic-all emit correct byte code an attributes for type annotations
tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java 8057687 generic-all emit correct byte code an attributes for type annotations
tools/javac/warnings/suppress/TypeAnnotations.java 8057683 generic-all improve ordering of errors with type annotations
tools/javac/modules/SourceInSymlinkTest.java 8180263 windows-all fails when run on a subst drive
###########################################################################
#
# javap
tools/javap/output/RepeatingTypeAnnotations.java 8057687 generic-all emit correct byte code an attributes for type annotations
###########################################################################
#
# jdeps
#############################################################################
# Preview project specific failures go here at the end of the file.
#
# These are NOT failures that occur with the '--enable-preview' option
# specified; those go in the appropriate ProblemList-enable-preview.txt file.
# These are failures that occur WITHOUT the '--enable-preview' option
# specified AND occur because of some issue with preview project code,
# in either implementation or test code.
#############################################################################

47
test/langtools/TEST.ROOT Normal file
View file

@ -0,0 +1,47 @@
# This file identifies the root of the test-suite hierarchy.
# It also contains test-suite configuration information.
# The list of keywords supported in the entire test suite. The
# "intermittent" keyword marks tests known to fail intermittently.
# The "randomness" keyword marks tests using randomness with test
# cases differing from run to run. (A test using a fixed random seed
# would not count as "randomness" by this definition.) Extra care
# should be taken to handle test failures of intermittent or
# randomness tests.
keys=intermittent randomness needs-src needs-src-jdk_javadoc
# Group definitions
groups=TEST.groups
# Minimum jtreg version
requiredVersion=8.2.1+1
# Path to libraries in the topmost test directory. This is needed so @library
# does not need ../../ notation to reach them
external.lib.roots = ../../
# Allow querying of various System properties in @requires clauses
#
# Source files for classes that will be used at the beginning of each test suite run,
# to determine additional characteristics of the system for use with the @requires tag.
# Note: compiled bootlibs classes will be added to BCP.
requires.extraPropDefns = ../jtreg-ext/requires/VMProps.java
requires.extraPropDefns.bootlibs = ../lib/jdk/test/whitebox
requires.extraPropDefns.libs = \
../lib/jdk/test/lib/Platform.java \
../lib/jdk/test/lib/Container.java
requires.extraPropDefns.javacOpts = \
--add-exports java.base/jdk.internal.foreign=ALL-UNNAMED \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED
requires.extraPropDefns.vmOpts = \
-XX:+UnlockDiagnosticVMOptions \
-XX:+LogVMOutput -XX:-DisplayVMOutput -XX:LogFile=vmprops.flags.final.vm.log \
-XX:+PrintFlagsFinal \
-XX:+WhiteBoxAPI \
--add-exports java.base/jdk.internal.foreign=ALL-UNNAMED \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED
requires.properties= \
vm.continuations \
vm.debug

100
test/langtools/TEST.groups Normal file
View file

@ -0,0 +1,100 @@
# Copyright (c) 2015, 2024, 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.
#
# Langtools-specific test groups
langtools_javac = \
tools/all \
tools/javac
langtools_javap = \
tools/all \
tools/javap
langtools_javadoc = \
tools/all \
tools/doclint \
tools/javac/doctree \
jdk/javadoc
langtools_jshell = \
tools/all \
jdk/jshell
langtools_jshell_unstable = \
jdk/jshell/ExternalEditorTest.java \
jdk/jshell/FailOverDirectExecutionControlTest.java \
jdk/jshell/FailOverExecutionControlDyingLaunchTest.java \
jdk/jshell/FailOverExecutionControlHangingListenTest.java \
jdk/jshell/JdiHangingListenExecutionControlTest.java \
jdk/jshell/JdiLaunchingExecutionControlTest.java \
jdk/jshell/JdiListeningExecutionControlTest.java \
jdk/jshell/JdiListeningLocalhostExecutionControlTest.java \
jdk/jshell/ToolBasicTest.java \
jdk/jshell/ToolLocaleMessageTest.java \
jdk/jshell/ToolReloadTest.java \
jdk/jshell/UserInputTest.java \
jdk/jshell/UserJdiUserRemoteTest.java
langtools_jdeprscan = \
tools/all \
tools/jdeprscan
langtools_jdeps = \
tools/all \
tools/jdeps
langtools_jnativescan = \
tools/all \
tools/jnativescan
langtools_slow = \
jdk/internal/shellsupport/doc/FullJavadocHelperTest.java
# All tests
all = \
:langtools_all
langtools_all = \
/
# Tiered testing definitions
# (Nearly) all langtools tests are tier 1.
tier1 = \
:langtools_all \
lib \
tools \
-:langtools_jshell_unstable \
-:langtools_slow
# (Almost) no langtools tests are tier 2.
tier2 = \
:langtools_jshell_unstable \
:langtools_slow
# No langtools tests are tier 3 either.
tier3 =
# No langtools tests are tier 4 either.
tier4 =

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, 2026, 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 8189778
* @summary Test JavadocHelper
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.jshell/jdk.internal.shellsupport.doc
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
* @run junit/timeout=900/othervm -Xmx1024m FullJavadocHelperTest
*/
import java.io.IOException;
import org.junit.jupiter.api.Test;
public class FullJavadocHelperTest {
/*
* Long-running test to retrieve doc comments for enclosed elements of all JDK classes.
*/
@Test
public void testAllDocs() throws IOException {
new JavadocHelperTest().retrieveDocComments(Boolean.TRUE::booleanValue);
}
}

View file

@ -0,0 +1,417 @@
/*
* Copyright (c) 2015, 2026, 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 8131019 8169561 8261450
* @summary Test JavadocFormatter
* @library /tools/lib
* @modules jdk.jshell/jdk.internal.shellsupport.doc
* @run junit JavadocFormatterTest
*/
import java.util.Objects;
import jdk.internal.shellsupport.doc.JavadocFormatter;
import org.junit.jupiter.api.Test;
public class JavadocFormatterTest {
private static final String CODE_RESET = "\033[0m";
private static final String CODE_HIGHLIGHT = "\033[1m";
private static final String CODE_UNDERLINE = "\033[4m";
@Test
public void testReflow() {
String actual;
String expected;
actual = new JavadocFormatter(25, true).formatJavadoc(
"test",
"1234 1234\n1234\n1234 12345 123456789012345678901234567890 1234 1234\n1234 {@code 1234} 1234 1234\n1234 1234 123456 123456\n<b>123456</b>\n123456 123456 {@link String string} 1");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"1234 1234 1234 1234 12345\n" +
"123456789012345678901234567890\n" +
"1234 1234 1234 1234 1234\n" +
"1234 1234 1234 123456\n" +
"123456 123456 123456\n" +
"123456 string 1\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"@param <T> 51234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"@param <E> 61234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"@param shortName 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"@param aVeryLongName1234567890123456789012345678901234567890 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"\n" +
CODE_UNDERLINE + "Type Parameters:" + CODE_RESET + "\n" +
"T - 51234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"E - 61234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"\n" +
CODE_UNDERLINE + "Parameters:" + CODE_RESET + "\n" +
"shortName - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234\n" +
"aVeryLongName1234567890123456789012345678901234567890 - \n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"@throws ShortExcp 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"@throws aVeryLongException1234567890123456789012345678901234567890 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"\n" +
CODE_UNDERLINE + "Thrown Exceptions:" + CODE_RESET + "\n" +
"ShortExcp - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234\n" +
"aVeryLongException1234567890123456789012345678901234567890 - \n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"@return 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"\n" +
CODE_UNDERLINE + "Returns:" + CODE_RESET + "\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 \n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//handling of <p>, <pre>:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 <p>1234 1234 <p>1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 <p>1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"<blockquote><pre>\n" +
"for (String data : content) {\n" +
" System.err.println(data);\n" +
"}\n" +
"</pre></blockquote>\n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234\n" +
"1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234\n" +
" for (String data : content) {\n" +
" System.err.println(data);\n" +
" }\n" +
" \n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//list handling:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"<ul>" +
" <li>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</li>" +
" <li>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" <li>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234<ol>" +
" <li>D 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</li>" +
" <li>E 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234<ul>" +
" <li>F 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234<ol>" +
" <li>G 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" </ol>" +
" </ul>" +
" </OL>" +
" <LI><p>H 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 <p>1234 1234 1234 1234 1234 1234 1234<ul>" +
" <li>I 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" </ul>" +
"</ul> followup" +
"<dl>" +
"<dt>Term1</dt>" +
"<dd>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</dd>" +
"<dt>Term2" +
"<dd>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
"<dt>Term3" +
"<dd>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
"</dl>" +
"<dl>" +
"<dt>TermUnfinished" +
"</dl> followup");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
" * A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234\n" +
" * B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234\n" +
" * C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234\n" +
" 1. D 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234\n" +
" 2. E 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234\n" +
" * F 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234\n" +
" 1. G 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" * H 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234\n" +
" * I 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234\n" +
"followup\n" +
CODE_HIGHLIGHT + "Term1" + CODE_RESET + "\n" +
" A 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
CODE_HIGHLIGHT + "Term2" + CODE_RESET + "\n" +
" B 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
CODE_HIGHLIGHT + "Term3" + CODE_RESET + "\n" +
" C 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
CODE_HIGHLIGHT + "TermUnfinished" + CODE_RESET + "\n" +
"followup\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//sections:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"text 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"<h3>1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</h3>" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"text 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"\n" +
CODE_UNDERLINE + "1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234" + CODE_RESET + "\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//table:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"<table>" +
"<tr>" +
"<th>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</th>" +
"<th>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</th>" +
"<th>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</th>" +
"</tr>" +
"<tr>" +
"<td>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td> \n" +
"<td>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
"<td>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
"<tr>" +
"<td>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
"<td>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
"<td>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
"</tr>" +
"<tr>" +
"<td>1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
"<td>1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
"</table>");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"----------------------------------------------------------------\n" +
"| " + CODE_HIGHLIGHT + "A 1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "B 1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "C 1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " |\n" +
"----------------------------------------------------------------\n" +
"| A 1234 1234 1234 | B 1234 1234 1234 | C 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 | 1234 1234 | 1234 1234 |\n" +
"----------------------------------------------------------------\n" +
"| A 1234 1234 1234 | B 1234 1234 1234 | C 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 | 1234 1234 | 1234 1234 |\n" +
"----------------------------------------------------------------\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 | 1234 1234 |\n" +
"-------------------------------------------\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//no escape sequences:
actual = new JavadocFormatter(66, false).formatJavadoc("test",
"@param shortName 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"@param aVeryLongName1234567890123456789012345678901234567890 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = "test\n" +
"\n" +
"Parameters:\n" +
"shortName - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234\n" +
"aVeryLongName1234567890123456789012345678901234567890 - \n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//null javadoc:
actual = new JavadocFormatter(66, true).formatJavadoc("test", null);
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//stray tags:
for (String tag : new String[] {"li", "ol", "h3", "table", "tr", "td", "dl", "dt", "dd"}) {
for (boolean closing : new boolean[] {false, true}) {
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"<" + (closing ? "/" : "") + tag + ">text");
if (!actual.contains("text")) {
throw new AssertionError("Incorrect output: " + actual);
}
}
}
//entities:
actual = new JavadocFormatter(66, false).formatJavadoc("test",
"&alpha; &lt; &#65; &#X42; &gt; &broken; &#xFFFFFFFF; &#xFFFFFFF;\n");
expected = "test\n" +
"\u03b1 < A B > &broken; &#xFFFFFFFF; &#xFFFFFFF;\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//img:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"1234 <img src='any.png' alt='text'/> 1234");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"1234 text 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//unknown HTML tag:
actual = new JavadocFormatter(66, false).formatJavadoc("test",
"1234 <unknown any any>1234</unknown> 1234");
expected = "test\n" +
"1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
}
@Test
public void testSpaceAtEndOfLine() {
String header = "Class<?> Class<T>.forName(Module module, String name)";
String javadoc = """
@throws SecurityException
<ul>
<li> test </li>
</ul>
""";
new JavadocFormatter(60, true).formatJavadoc(header, javadoc);
}
}

View file

@ -0,0 +1,628 @@
/*
* Copyright (c) 2015, 2026, 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 8131019 8189778 8190552
* @summary Test JavadocHelper
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.jshell/jdk.internal.shellsupport.doc
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
* @run junit JavadocHelperTest
* @key randomness
*/
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import javax.lang.model.element.Element;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.ModuleElement.ExportsDirective;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic.Kind;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
import com.sun.source.util.JavacTask;
import jdk.internal.shellsupport.doc.JavadocHelper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JavadocHelperTest {
@Test
public void testJavadoc() throws Exception {
doTestJavadoc("",
t -> t.getElements().getTypeElement("test.Super"),
"Top level. ");
doTestJavadoc("",
t -> getFirstMethod(t, "test.Super"),
" javadoc1\n" +
"\n" +
" @param p1 param1\n" +
" @param p2 param2\n" +
" @param p3 param3\n" +
" @throws IllegalStateException exc1\n" +
" @throws IllegalArgumentException exc2\n" +
" @throws IllegalAccessException exc3\n" +
" @return value\n");
}
@Test
public void testInheritNoJavadoc() throws Exception {
doTestJavadoc("",
getSubTest,
" javadoc1\n" +
"\n" +
" @param p1 param1\n" +
" @param p2 param2\n" +
" @param p3 param3\n" +
" @throws IllegalStateException exc1\n" +
" @throws IllegalArgumentException exc2\n" +
" @throws IllegalAccessException exc3\n" +
" @return value\n");
}
@Test
public void testInheritFull() throws Exception {
doTestJavadoc(" /**\n" +
" * Prefix {@inheritDoc} suffix.\n" +
" *\n" +
" * @param p1 prefix {@inheritDoc} suffix\n" +
" * @param p2 prefix {@inheritDoc} suffix\n" +
" * @param p3 prefix {@inheritDoc} suffix\n" +
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" +
" * @return prefix {@inheritDoc} suffix\n" +
" */\n",
getSubTest,
" Prefix javadoc1 suffix.\n" +
"\n" +
" @param p1 prefix param1 suffix\n" +
" @param p2 prefix param2 suffix\n" +
" @param p3 prefix param3 suffix\n" +
" @throws IllegalStateException prefix exc1 suffix\n" +
" @throws IllegalArgumentException prefix exc2 suffix\n" +
" @throws IllegalAccessException prefix exc3 suffix\n" +
" @return prefix value suffix\n");
}
@Test
public void testInheritMissingParam() throws Exception {
doTestJavadoc(" /**\n" +
" * Prefix {@inheritDoc} suffix.\n" +
" *\n" +
" * @param p1 prefix {@inheritDoc} suffix\n" +
" * @param p3 prefix {@inheritDoc} suffix\n" +
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" +
" * @return prefix {@inheritDoc} suffix\n" +
" */\n",
getSubTest,
" Prefix javadoc1 suffix.\n" +
"\n" +
" @param p1 prefix param1 suffix\n" +
"@param p2 param2\n" +
" @param p3 prefix param3 suffix\n" +
" @throws IllegalStateException prefix exc1 suffix\n" +
" @throws IllegalArgumentException prefix exc2 suffix\n" +
" @throws IllegalAccessException prefix exc3 suffix\n" +
" @return prefix value suffix\n");
}
@Test
public void testInheritMissingFirstParam() throws Exception {
doTestJavadoc(" /**\n" +
" * Prefix {@inheritDoc} suffix.\n" +
" *\n" +
" * @param p2 prefix {@inheritDoc} suffix\n" +
" * @param p3 prefix {@inheritDoc} suffix\n" +
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" +
" * @return prefix {@inheritDoc} suffix\n" +
" */\n",
getSubTest,
" Prefix javadoc1 suffix.\n" +
"\n" +
"@param p1 param1\n" +
" @param p2 prefix param2 suffix\n" +
" @param p3 prefix param3 suffix\n" +
" @throws IllegalStateException prefix exc1 suffix\n" +
" @throws IllegalArgumentException prefix exc2 suffix\n" +
" @throws IllegalAccessException prefix exc3 suffix\n" +
" @return prefix value suffix\n");
}
@Test
public void testInheritMissingThrows() throws Exception {
doTestJavadoc(" /**\n" +
" * Prefix {@inheritDoc} suffix.\n" +
" *\n" +
" * @param p1 prefix {@inheritDoc} suffix\n" +
" * @param p2 prefix {@inheritDoc} suffix\n" +
" * @param p3 prefix {@inheritDoc} suffix\n" +
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" +
" * @return prefix {@inheritDoc} suffix\n" +
" */\n",
getSubTest,
" Prefix javadoc1 suffix.\n" +
"\n" +
" @param p1 prefix param1 suffix\n" +
" @param p2 prefix param2 suffix\n" +
" @param p3 prefix param3 suffix\n" +
" @throws IllegalStateException prefix exc1 suffix\n" +
"@throws java.lang.IllegalArgumentException exc2\n" +
" @throws IllegalAccessException prefix exc3 suffix\n" +
" @return prefix value suffix\n");
}
@Test
public void testInheritMissingReturn() throws Exception {
doTestJavadoc(" /**\n" +
" * Prefix {@inheritDoc} suffix.\n" +
" *\n" +
" * @param p1 prefix {@inheritDoc} suffix\n" +
" * @param p2 prefix {@inheritDoc} suffix\n" +
" * @param p3 prefix {@inheritDoc} suffix\n" +
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" +
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" +
" */\n",
getSubTest,
" Prefix javadoc1 suffix.\n" +
"\n" +
" @param p1 prefix param1 suffix\n" +
" @param p2 prefix param2 suffix\n" +
" @param p3 prefix param3 suffix\n" +
" @throws IllegalStateException prefix exc1 suffix\n" +
" @throws IllegalArgumentException prefix exc2 suffix\n" +
" @throws IllegalAccessException prefix exc3 suffix\n" +
"@return value\n");
}
@Test
public void testInheritAllButOne() throws Exception {
doTestJavadoc(" /**\n" +
" * @throws IllegalArgumentException {@inheritDoc}\n" +
" */\n",
getSubTest,
"javadoc1\n" +
"@param p1 param1\n" +
"@param p2 param2\n" +
"@param p3 param3\n" +
"@throws java.lang.IllegalStateException exc1\n" +
" @throws IllegalArgumentException exc2\n" +
"@throws java.lang.IllegalAccessException exc3\n" +
"@return value\n");
}
@Test
public void testInheritEmpty() throws Exception {
doTestJavadoc(" /**\n" +
" */\n",
" /**@param p1\n" +
" * @param p2\n" +
" * @param p3\n" +
" * @throws IllegalStateException\n" +
" * @throws IllegalArgumentException\n" +
" * @throws IllegalAccessException\n" +
" * @return\n" +
" */\n",
getSubTest,
"\n" +
"@param p1 \n" +
"@param p2 \n" +
"@param p3 \n" +
"@throws java.lang.IllegalStateException \n" +
"@throws java.lang.IllegalArgumentException \n" +
"@throws java.lang.IllegalAccessException \n" +
"@return \n");
}
@Test
public void testEmptyValue() throws Exception {
doTestJavadoc(" /**\n" +
" */\n",
" /**@param p1 {@value}\n" +
" * @param p2\n" +
" * @param p3\n" +
" * @throws IllegalStateException\n" +
" * @throws IllegalArgumentException\n" +
" * @throws IllegalAccessException\n" +
" * @return\n" +
" */\n",
getSubTest,
"\n" +
"@param p1 {@value}\n" +
"@param p2 \n" +
"@param p3 \n" +
"@throws java.lang.IllegalStateException \n" +
"@throws java.lang.IllegalArgumentException \n" +
"@throws java.lang.IllegalAccessException \n" +
"@return \n");
}
@Test
public void testShortComment() throws Exception {
doTestJavadoc(" /**Test.*/\n",
getSubTest,
"Test." +
"@param p1 param1\n" +
"@param p2 param2\n" +
"@param p3 param3\n" +
"@throws java.lang.IllegalStateException exc1\n" +
"@throws java.lang.IllegalArgumentException exc2\n" +
"@throws java.lang.IllegalAccessException exc3\n" +
"@return value\n");
}
@Test
public void testMarkdown() throws Exception {
doTestJavadoc("""
/// Prefix {@inheritDoc} suffix.
///
/// *Another* __paragraph__.
///
/// Paragraph \ufffc with \ufffc replacement \ufffc character.
///
/// @param p1 prefix {@inheritDoc} suffix
/// @param p2 prefix {@inheritDoc} suffix
/// @param p3 prefix {@inheritDoc} suffix
/// @throws IllegalStateException prefix {@inheritDoc} suffix
/// @throws IllegalArgumentException prefix {@inheritDoc} suffix
/// @throws IllegalAccessException prefix {@inheritDoc} suffix
/// @return prefix {@inheritDoc} suffix
""",
getSubTest,
"""
Prefix javadoc1 suffix.
<p><em>Another</em> <strong>paragraph</strong>.
<p>Paragraph \ufffc with \ufffc replacement \ufffc character.
@param p1 prefix param1 suffix
@param p2 prefix param2 suffix
@param p3 prefix param3 suffix
@throws IllegalStateException prefix exc1 suffix
@throws IllegalArgumentException prefix exc2 suffix
@throws IllegalAccessException prefix exc3 suffix
@return prefix value suffix""");
}
@Test
public void testMarkdown2() throws Exception {
doTestJavadoc("""
/// {@inheritDoc}
///
/// *Another* __paragraph__. [java.lang.Object]
///
/// @since snc
""",
getSubTest,
"""
javadoc1
<p><em>Another</em> <strong>paragraph</strong>. {@link java.lang.Object}
@param p1 param1
@param p2 param2
@param p3 param3
@throws java.lang.IllegalStateException exc1
@throws java.lang.IllegalArgumentException exc2
@throws java.lang.IllegalAccessException exc3
@return value
@since snc""");
}
@Test
public void testMarkdown3() throws Exception {
doTestJavadoc("""
/// {@inheritDoc}
///
/// *Another* __paragraph__.
""",
getSubTest,
//the formatting could be improved:
"""
javadoc1
<p><em>Another</em> <strong>paragraph</strong>.@param p1 param1
@param p2 param2
@param p3 param3
@throws java.lang.IllegalStateException exc1
@throws java.lang.IllegalArgumentException exc2
@throws java.lang.IllegalAccessException exc3
@return value
""");
}
@Test
public void testMarkdown4() throws Exception {
doTestJavadoc("""
/// {@inheritDoc}
///
/// *Another* __paragraph__. [test][java.lang.Object]
///
/// @since snc
""",
getSubTest,
"""
javadoc1
<p><em>Another</em> <strong>paragraph</strong>. {@linkplain java.lang.Object test}
@param p1 param1
@param p2 param2
@param p3 param3
@throws java.lang.IllegalStateException exc1
@throws java.lang.IllegalArgumentException exc2
@throws java.lang.IllegalAccessException exc3
@return value
@since snc""");
}
@Test
public void testMarkdown5() throws Exception {
doTestJavadoc("""
///[define classes][java.lang.invoke.MethodHandles.Lookup#defineClass(byte\\[\\])]
///
/// @since snc
""",
getSubTest,
"""
{@linkplain java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes}
@param p1 param1
@param p2 param2
@param p3 param3
@throws java.lang.IllegalStateException exc1
@throws java.lang.IllegalArgumentException exc2
@throws java.lang.IllegalAccessException exc3
@return value
@since snc""");
}
@Test
public void testMarkdown6() throws Exception {
doTestJavadoc("""
///Text1 [define classes][java.lang.invoke.MethodHandles.Lookup#defineClass(byte\\[\\])]
///text2
///
/// @since snc
""",
getSubTest,
"""
Text1 {@linkplain java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes}
text2
@param p1 param1
@param p2 param2
@param p3 param3
@throws java.lang.IllegalStateException exc1
@throws java.lang.IllegalArgumentException exc2
@throws java.lang.IllegalAccessException exc3
@return value
@since snc""");
}
private void doTestJavadoc(String origJavadoc, Function<JavacTask, Element> getElement, String expectedJavadoc) throws Exception {
doTestJavadoc(origJavadoc,
" /**\n" +
" * javadoc1\n" +
" *\n" +
" * @param p1 param1\n" +
" * @param p2 param2\n" +
" * @param p3 param3\n" +
" * @throws IllegalStateException exc1\n" +
" * @throws IllegalArgumentException exc2\n" +
" * @throws IllegalAccessException exc3\n" +
" * @return value\n" +
" */\n",
getElement, expectedJavadoc);
}
private void doTestJavadoc(String origJavadoc,
String superJavadoc,
Function<JavacTask, Element> getElement,
String expectedJavadoc) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String subClass =
"package test;\n" +
"public class Sub extends Super {\n" +
origJavadoc +
" public String test(int p1, int p2, int p3) throws IllegalStateException, IllegalArgumentException, IllegalAccessException { return null;} \n" +
"}\n";
String superClass =
"package test;\n" +
"/**Top level." +
" */\n" +
"public class Super {\n" +
superJavadoc +
" public String test(int p1, int p2, int p3) throws IllegalStateException, IllegalArgumentException, IllegalAccessException { return null;} \n" +
"}\n";
Path srcZip = Paths.get("src.zip");
try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
out.putNextEntry(new JarEntry("test/Sub.java"));
out.write(subClass.getBytes());
out.putNextEntry(new JarEntry("test/Super.java"));
out.write(superClass.getBytes());
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
DiagnosticListener<? super JavaFileObject> noErrors = d -> {
if (d.getKind() == Kind.ERROR) {
throw new AssertionError(d.getMessage(null));
}
};
assertTrue(compiler.getTask(null, null, noErrors, Arrays.asList("-d", "."), null, Arrays.asList(new JFOImpl("Super", superClass), new JFOImpl("Sub", subClass))).call());
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
fm.setLocationFromPaths(StandardLocation.CLASS_PATH, Arrays.asList(Paths.get(".").toAbsolutePath()));
JavacTask task = (JavacTask) compiler.getTask(null, fm, noErrors, null, null, null);
Element el = getElement.apply(task);
try (JavadocHelper helper = JavadocHelper.create(task, Arrays.asList(srcZip))) {
String javadoc = helper.getResolvedDocComment(el);
assertEquals(expectedJavadoc, javadoc);
}
}
}
private Element getFirstMethod(JavacTask task, String typeName) {
return ElementFilter.methodsIn(task.getElements().getTypeElement(typeName).getEnclosedElements()).get(0);
}
private Function<JavacTask, Element> getSubTest = t -> getFirstMethod(t, "test.Sub");
private static final class JFOImpl extends SimpleJavaFileObject {
private final String code;
public JFOImpl(String name, String code) throws URISyntaxException {
super(new URI("mem:///" + name + ".java"), Kind.SOURCE);
this.code = code;
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return code;
}
}
private static long getSeed() {
long seed;
try {
// Throws NumberFormatException if the property is undefined
seed = Long.parseLong(System.getProperty("seed"));
} catch (NumberFormatException e) {
seed = new Random().nextLong();
}
System.out.println("Random Seed: " + seed);
return seed;
}
/*
* Retrieves doc comments for a random subset of JDK classes.
* Set the system property `seed` to a random seed to reproduce
* a specific run of this test.
*/
@Test
public void testRandomDocs() throws IOException {
Random random = new Random(getSeed());
// Run test on 2% of classes, which corresponds to ~ 140 classes
retrieveDocComments(() -> random.nextInt(100) < 2);
}
/**
* Retrieve documentation of enclosed elements for some or all JDK classes.
*
* @param shouldTest oracle function to decide whether a class should be tested
*/
protected void retrieveDocComments(BooleanSupplier shouldTest) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticListener<? super JavaFileObject> noErrors = d -> {
if (d.getKind() == Kind.ERROR) {
throw new AssertionError(d.getMessage(null));
}
};
List<Path> sources = new ArrayList<>();
Path home = Paths.get(System.getProperty("java.home"));
Path srcZip = home.resolve("lib").resolve("src.zip");
if (Files.isReadable(srcZip)) {
URI uri = URI.create("jar:" + srcZip.toUri());
try (FileSystem zipFO = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
Path root = zipFO.getRootDirectories().iterator().next();
//modular format:
try (DirectoryStream<Path> ds = Files.newDirectoryStream(root)) {
for (Path p : ds) {
if (Files.isDirectory(p)) {
sources.add(p);
}
}
}
try (StandardJavaFileManager fm =
compiler.getStandardFileManager(null, null, null)) {
JavacTask task =
(JavacTask) compiler.getTask(null, fm, noErrors, null, null, null);
task.getElements().getTypeElement("java.lang.Object");
for (ModuleElement me : task.getElements().getAllModuleElements()) {
List<ExportsDirective> exports =
ElementFilter.exportsIn(me.getDirectives());
for (ExportsDirective ed : exports) {
try (JavadocHelper helper = JavadocHelper.create(task, sources)) {
List<? extends Element> content =
ed.getPackage().getEnclosedElements();
for (TypeElement clazz : ElementFilter.typesIn(content)) {
if (shouldTest.getAsBoolean()) {
for (Element el : clazz.getEnclosedElements()) {
helper.getResolvedDocComment(el);
}
}
}
}
}
}
}
}
}
}
}

View file

@ -0,0 +1,108 @@
/*
* Copyright 2009 Google, Inc. All Rights Reserved.
* Copyright (c) 2013, 2024, 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 5093723 8202617
* @summary REGRESSION: ClassCastException in SingleIndexWriter
* Check that links to undocumented members are not generated
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main T5093723
*/
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
import java.io.IOException;
import java.nio.file.Path;
public class T5093723 extends JavadocTester {
ToolBox tb = new ToolBox();
public static void main(String... args) throws Exception {
var tester = new T5093723();
tester.runTests();
}
@Test
public void test(Path base) throws IOException {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/** A documented class. */
public class DocumentedClass extends UndocumentedClass {
/** {@link #method} */
public void m1() {}
/** {@link #publicMethod} */
public void m2() {}
/** {@link #protectedMethod} */
public void m3() {}
/** {@link #privateMethod} */
public void m4() {}
}
""", """
package p;
class UndocumentedClass {
void method() {}
public void publicMethod() {}
protected void protectedMethod() {}
private void privateMethod() {}
}
""");
javadoc("-d", "out",
"-Xdoclint:none",
"-sourcepath",
src.toString(),
"p");
checkExit(Exit.OK);
checkOutput("p/DocumentedClass.html",
true,
"<div class=\"block\"><code>UndocumentedClass.method()</code></div>",
"<div class=\"block\"><code>UndocumentedClass.privateMethod()</code></div>");
checkOutput("p/DocumentedClass.html",
false,
"<div class=\"block\"><a href=\"#method()\"><code>method()</code></a></div>",
"<div class=\"block\"><a href=\"#privateMethod()\"><code>privateMethod()</code></a></div>");
checkOutput(Output.OUT, true,
"warning: reference not accessible: privateMethod()",
"/** {@link #privateMethod} */",
"warning: reference not accessible: method()",
"/** {@link #method} */");
checkOutput(Output.OUT, false,
"warning: reference not accessible: publicMethod()",
"warning: reference not accessible: protectedMethod()",
"/** {@link #publicMethod} */",
"/** {@link #protectedMethod} */");
}
}

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2002, 2022, 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 4706779 4956908
* @summary Add text equivalent of class tree ASCII art for accessibility
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main AccessAsciiArt
*/
import javadoc.tester.JavadocTester;
public class AccessAsciiArt extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new AccessAsciiArt();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"p1", "p1.subpkg");
checkExit(Exit.OK);
checkOutput("p1/subpkg/SSC.html", true,
// Test the top line of the class tree
"""
<div class="inheritance"><a href="../C.html" title="class in p1">p1.C</a>""",
// Test the second line of the class tree
"""
<div class="inheritance"><a href="../SC.html" title="class in p1">p1.SC</a>""",
// Test the third line of the class tree
"""
<div class="inheritance">p1.subpkg.SSC</div>
</div>
</div>""");
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C implements SI {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public interface I {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class SC extends C {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public interface SI extends I {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1.subpkg;
public class SSC extends p1.SC {
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2002, 2025, 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 4636667 7052425 8016549 8196202 8344301
* @summary Use <H1, <H2>, and <H3> in proper sequence for accessibility
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main AccessH1
*/
import javadoc.tester.JavadocTester;
public class AccessH1 extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new AccessH1();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-doctitle", "Document Title",
"-sourcepath", testSrc,
"p1", "p2");
checkExit(Exit.OK);
// Test the style sheet
checkOutput("resource-files/stylesheet.css", true,
"""
h1 {
font-size:1.425em;
}""");
// Test the doc title in the overview page
checkOutput("index.html", true,
"""
<h1 class="title">Document Title</h1>""");
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2002, 2022, 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 4638136 7198273 8025633 8081854 8182765 8258659 8261976
* @summary Add ability to skip over nav bar for accessibility
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main AccessSkipNav
*/
import javadoc.tester.JavadocTester;
public class AccessSkipNav extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new AccessSkipNav();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"p1", "p2");
checkExit(Exit.OK);
// Testing only for the presence of the <a href> and <a id>
checkOutput("p1/C1.html", true,
// Top navbar <a href>
"""
<a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a>""",
// Top navbar <span id>
"""
<span class="skip-nav" id="skip-navbar-top"></span>""");
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C1 {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2002, 2022, 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 4637604 4775148 8183037 8182765 8196202
* @summary Test the tables for summary attribute
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main AccessSummary
*/
import javadoc.tester.JavadocTester;
public class AccessSummary extends JavadocTester {
/**
* The entry point of the test.
* @param args the array of command line arguments.
* @throws Exception if the test fails
*/
public static void main(String... args) throws Exception {
var tester = new AccessSummary();
tester.runTests();
}
@Test
public void testAccessSummary() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"p1", "p2");
checkExit(Exit.OK);
checkSummary(false);
}
void checkSummary(boolean found) {
checkOutput("index.html", found,
"""
summary="Package Summary table, listing packages, and an explanation\"""");
// Test that the summary attribute appears or not
checkOutput("p1/C1.html", found,
"""
summary="Constructor Summary table, listing constructors, and an explanation\"""");
// Test that the summary attribute appears or not
checkOutput("constant-values.html", found,
"""
summary="Constant Field Values table, listing constant fields, and values\"""");
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C1 {
public static final String STATICFINALFIELD = "test";
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2002, 2022, 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 4651598 8026567 8239804
* @summary Javadoc wrongly inserts </DD> tags when using multiple @author tags
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main AuthorDD
*/
/**
* Runs javadoc and runs regression tests on the resulting HTML.
*/
import javadoc.tester.JavadocTester;
public class AuthorDD extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new AuthorDD();
tester.runTests();
}
@Test
public void test() {
// Test for all cases except the split index page
javadoc("-d", "out",
"-author",
"-version",
"-sourcepath", testSrc,
"p1");
checkExit(Exit.OK);
checkOutput("p1/C1.html", true,
"<dl class=\"notes\">",
// Test single @since tag:
"<dt>Since:</dt>\n"
+ "<dd>JDK 1.0</dd>",
// Test multiple @author tags:
"""
<dt>Author:</dt>
<dd>Alice, Bob, Eve</dd>""");
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2002, 2019, 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.
*/
package p1;
/**
* This is the class documentation.
* Testing multiple @since and @version tags only to see if all
* instances of SimpleTaglet have the same bug
*
* @author Alice
* @author Bob
* @author Eve
*
* @since JDK 1.0
*
* @version 1.1
* @version 1.2
* @version 1.3
*/
public class C1 {
}

View file

@ -0,0 +1,143 @@
/*
* Copyright (c) 2002, 2022, 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 4524350 4662945 4633447 8196202 8261976
* @summary stddoclet: {@docRoot} inserts an extra trailing "/"
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main DocRootSlash
*/
import java.util.regex.*;
/**
* Runs javadoc and runs regression tests on the resulting HTML.
* It reads each file, complete with newlines, into a string to easily
* find strings that contain newlines.
*/
import javadoc.tester.JavadocTester;
public class DocRootSlash extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new DocRootSlash();
tester.runTests();
}
@Test
public void test() {
// Directory that contains source files that javadoc runs on
String srcdir = System.getProperty("test.src", ".");
javadoc("-d", "out",
"-Xdoclint:none",
"-overview", (srcdir + "/overview.html"),
"-header", """
<A HREF="{@docroot}/element-list">{&#064;docroot}</A> <A HREF="{@docRoot}/help-doc.html">{&#064;docRoot}</A>""",
"-sourcepath", srcdir,
"p1", "p2");
checkFiles(
"p1/C1.html",
"p1/package-summary.html",
"index.html");
}
void checkFiles(String... filenameArray) {
int count = 0;
for (String f : filenameArray) {
// Read contents of file into a string
String fileString = readFile(f);
System.out.println("\nSub-tests for file: " + f + " --------------");
// Loop over all tests in a single file
for ( int j = 0; j < 7; j++ ) {
// Compare actual to expected string for a single subtest
compareActualToExpected(++count, fileString);
}
}
}
/**
* Regular expression pattern matching code
*
* Prefix Pattern:
* flag (?i) (case insensitive, so "a href" == "A HREF" and all combinations)
* group1 (
* <a or <A
* \\s+ (one or more whitespace characters)
* href or HREF
* \" (double quote)
* )
* group2 ([^\"]*) (link reference -- characters that don't include a quote)
* group3 (\".*?>) (" target="frameName">)
* group4 (.*?) (label - zero or more characters)
* group5 (</a>) (end tag)
*/
private static final String prefix = "(?i)(<a\\s+href="; // <a href= (start group1)
private static final String ref1 = "\")([^\"]*)(\".*?>)"; // doublequotes (end group1, group2, group3)
/**
* Compares the actual string to the expected string in the specified string
* @param str String to search through
*/
void compareActualToExpected(int count, String str) {
checking("comparison for " + str);
// Pattern must be compiled each run because numTestsRun is incremented
Pattern actualLinkPattern1 =
Pattern.compile("Sub-test " + count + " Actual: " + prefix + ref1, Pattern.DOTALL);
Pattern expectLinkPattern1 =
Pattern.compile("Sub-test " + count + " Expect: " + prefix + ref1, Pattern.DOTALL);
// Pattern linkPattern2 = Pattern.compile(prefix + ref2 + label + end, Pattern.DOTALL);
Matcher actualLinkMatcher1 = actualLinkPattern1.matcher(str);
Matcher expectLinkMatcher1 = expectLinkPattern1.matcher(str);
if (expectLinkMatcher1.find() && actualLinkMatcher1.find()) {
String expectRef = expectLinkMatcher1.group(2);
String actualRef = actualLinkMatcher1.group(2);
if (actualRef.equals(expectRef)) {
passed(expectRef);
// System.out.println("pattern: " + actualLinkPattern1.pattern());
// System.out.println("actualRef: " + actualRef);
// System.out.println("group0: " + actualLinkMatcher1.group());
// System.out.println("group1: " + actualLinkMatcher1.group(1));
// System.out.println("group2: " + actualLinkMatcher1.group(2));
// System.out.println("group3: " + actualLinkMatcher1.group(3));
// System.exit(0);
} else {
failed("\n"
+ "Actual: \"" + actualRef + "\"\n"
+ "Expect: \"" + expectRef + "\"");
}
} else {
failed("Didn't find <A HREF> that fits the pattern: "
+ expectLinkPattern1.pattern());
}
}
}

View file

@ -0,0 +1,42 @@
<HTML>
<HEAD>
</HEAD>
<BODY>
Dummy first sentence to suppress BreakIterator warning.
<p>
Case 0 Actual: <A HREF=".">.</A> &nbsp; Current directory
<p>
Sub-test 15 Actual: <A HREF="{@docroot}">{&#064;docroot}</A> Bare tag - ALL LOWERCASE <br>
Sub-test 15 Expect: <A HREF=""></A> <br>
(Expect empty string because lowercase docroot is illegal)
<p>
Sub-test 16 Actual: <A HREF="{@docRoot}">{&#064;docRoot}</A> Bare tag - "R" UPPERCASE <br>
Sub-test 16 Expect: <A HREF=".">.</A>
<p>
Sub-test 17 Actual: <A HREF="{@docRoot}/element-list">{&#064;docRoot}/element-list</A> <br>
Sub-test 17 Expect: <A HREF="./element-list">./element-list</A>
<p>
Sub-test 18 Actual: <A HREF="{@docRoot}/p2/C2.html">{&#064;docRoot}/p2/C2.html</A> <br>
Sub-test 18 Expect: <A HREF="./p2/C2.html">./p2/C2.html</A>
<p>
Sub-test 19 Actual: <A HREF="{@docRoot}/../out/p2/C2.html">{&#064;docRoot}/../out/p2/C2.html</A> <br>
Sub-test 19 Expect: <A HREF="./../out/p2/C2.html">./../out/p2/C2.html</A>
<p>
Sub-test 20 Actual: <A
HREF="{@docRoot}/p2/package-summary.html#package-description">{&#064;docRoot}/p2/package-summary.html#package-description</A> <br>
Sub-test 20 Expect: <A HREF="./p2/package-summary.html#package-description">./p2/package-summary.html#package-description</A>
<p>
Sub-test 21 Actual: <A HREF="{@docRoot}/../out/p2/package-summary.html#package-description">{&#064;docRoot}/../out/p2/package-summary.html#package-description</A> <br>
Sub-test 21 Expect: <A HREF="./../out/p2/package-summary.html#package-description">./../out/p2/package-summary.html#package-description</A>
</BODY>
</HTML>

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2002, 2021, 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.
*/
package p1;
/**
* Dummy first sentence to suppress breakiterator warning.
* <p>
*
* Case 0 Actual: <A HREF=".">.</A> &nbsp; Current directory
* <p>
*
* Sub-test 1 Actual: <A HREF="{@docroot}">{&#064;docroot}</A> Bare tag - ALL LOWERCASE <br>
* Sub-test 1 Expect: <A HREF=""></A> <br>
* (Expect empty string because lowercase docroot is illegal)
* <p>
*
* Sub-test 2 Actual: <A HREF="{@docRoot}">{&#064;docRoot}</A> Bare tag - "R" UPPERCASE <br>
* Sub-test 2 Expect: <A HREF="..">..</A>
* <p>
*
* Sub-test 3 Actual: <A HREF="{@docRoot}/element-list">{&#064;docRoot}/element-list</A> <br>
* Sub-test 3 Expect: <A HREF="../element-list">../element-list</A>
* <p>
*
* Sub-test 4 Actual: <A HREF="{@docRoot}/p2/C2.html">{&#064;docRoot}/p2/C2.html</A> <br>
* Sub-test 4 Expect: <A HREF="../p2/C2.html">../p2/C2.html</A>
* <p>
*
* Sub-test 5 Actual: <A HREF="{@docRoot}/../out/p2/C2.html">{&#064;docRoot}/../out/p2/C2.html</A> <br>
* Sub-test 5 Expect: <A HREF="../../out/p2/C2.html">../../out/p2/C2.html</A>
* <p>
*
* Sub-test 6 Actual: <A HREF="{@docRoot}/p2/package-summary.html#package-description">{&#064;docRoot}/p2/package-summary.html#package-description</A> <br>
* Sub-test 6 Expect: <A HREF="../p2/package-summary.html#package-description">../p2/package-summary.html#package-description</A>
* <p>
*
* Sub-test 7 Actual: <A HREF="{@docRoot}/../out/p2/package-summary.html#package-description">{&#064;docRoot}/../out/p2/package-summary.html#package-description</A> <br>
* Sub-test 7 Expect: <A HREF="../../out/p2/package-summary.html#package-description">../../out/p2/package-summary.html#package-description</A>
*
*/
public class C1 {
}

View file

@ -0,0 +1,42 @@
<HTML>
<HEAD>
</HEAD>
<BODY>
Dummy first sentence to suppress breakiterator warning.
<p>
Case 0 Actual: <A HREF=".">.</A> &nbsp; Current directory
<p>
Sub-test 8 Actual: <A HREF="{@docroot}">{&#064;docroot}</A> Bare tag - ALL LOWERCASE <br>
Sub-test 8 Expect: <A HREF=""></A> <br>
(Expect empty string because lowercase docroot is illegal)
<p>
Sub-test 9 Actual: <A HREF="{@docRoot}">{&#064;docRoot}</A> Bare tag - "R" UPPERCASE <br>
Sub-test 9 Expect: <A HREF="..">..</A>
<p>
Sub-test 10 Actual: <A HREF="{@docRoot}/element-list">{&#064;docRoot}/element-list</A> <br>
Sub-test 10 Expect: <A HREF="../element-list">../element-list</A>
<p>
Sub-test 11 Actual: <A HREF="{@docRoot}/p2/C2.html">{&#064;docRoot}/p2/C2.html</A> <br>
Sub-test 11 Expect: <A HREF="../p2/C2.html">../p2/C2.html</A>
<p>
Sub-test 12 Actual: <A HREF="{@docRoot}/../out/p2/C2.html">{&#064;docRoot}/../out/p2/C2.html</A> <br>
Sub-test 12 Expect: <A HREF="../../out/p2/C2.html">../../out/p2/C2.html</A>
<p>
Sub-test 13 Actual: <A HREF="{@docRoot}/p2/package-summary.html#package-description">{&#064;docRoot}/p2/package-summary.html#package-description</A> <br>
Sub-test 13 Expect: <A HREF="../p2/package-summary.html#package-description">../p2/package-summary.html#package-description</A>
<p>
Sub-test 14 Actual: <A HREF="{@docRoot}/../out/p2/package-summary.html#package-description">{&#064;docRoot}/../out/p2/package-summary.html#package-description</A> <br>
Sub-test 14 Expect: <A HREF="../../out/p2/package-summary.html#package-description">../../out/p2/package-summary.html#package-description</A>
</BODY>
</HTML>

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
/**
* Source file for C2
*/
public class C2 {
}

View file

@ -0,0 +1,9 @@
<HTML>
<HEAD>
</HEAD>
<BODY>
This is the description of package p2.
</BODY>
</HTML>

View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 2013, 2022, 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 8008768 8287379
* @summary Using {@inheritDoc} in simple tag defined via -tag fails
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main DocTest
*/
import javadoc.tester.JavadocTester;
public class DocTest extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new DocTest();
tester.runTests();
}
@Test
public void test() {
javadoc("-verbose",
"-d", "DocTest",
"-sourcepath", System.getProperty("test.src.path"),
"-tag", "apiNote:a:API Note",
"-tag", "implSpec:a:Implementation Requirements:",
"-tag", "implNote:a:Implementation Note:",
"-package",
testSrc("DocTest.java")
);
checkExit(Exit.OK);
}
/**
* DocTest.testMethod() documentation.
*
* @apiNote DocTest.testMethod() API note.
* @implSpec DocTest.testMethod() implementation spec.
* @implNote DocTest.testMethod() implementation note.
*/
public void testMethod() {
}
}
class DocTestWithTags {
/**
* DocTest.testMethod() documentation.
*
* @apiNote DocTestWithTags.testMethod() API note.
* <pre>
* DocTestWithTags.testMethod() API note code sample.
* </pre>
* @implSpec DocTestWithTags.testMethod() implementation spec.
* <pre>
* DocTestWithTags.testMethod() implementation spec code sample.
* </pre>
* @implNote DocTest.testMethod() implementation note.
* <pre>
* DocTest.testMethod() implementation note code sample.
* </pre>
*/
public void testMethod() {
}
}
class MinimallyExtendsDocTest extends DocTest {
}
class SimpleExtendsDocTest extends DocTest {
/**
* SimpleExtendsDocTest.testMethod() documentation.
*/
@Override
public void testMethod() {
}
}
class SimpleInheritDocDocTest extends DocTest {
/**
* {@inheritDoc}
*/
@Override
public void testMethod() {
}
}
class FullInheritDocDocTest extends DocTest {
/**
* {@inheritDoc}
*
* @apiNote {@inheritDoc}
* @implSpec {@inheritDoc}
* @implNote {@inheritDoc}
*/
@Override
public void testMethod() {
}
}
class FullInheritDocPlusDocTest extends DocTest {
/**
* {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() documentation.
*
* @implSpec {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() implementation specification.
* @implNote {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() implementation note.
* @apiNote {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() API note.
*/
@Override
public void testMethod() {
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2002, 2022, 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 4645058 4747738 4855054 8024756 8141492 8196202 8205593 8215599
* @summary Javascript IE load error when linked by -linkoffline
* Window title shouldn't change when loading left frames (javascript)
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main JavascriptWinTitle
*/
import javadoc.tester.JavadocTester;
public class JavascriptWinTitle extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new JavascriptWinTitle();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-source", "8",
"-doctitle", "Document Title",
"-windowtitle", "Window Title",
"-overview", testSrc("overview.html"),
"-linkoffline", "http://java.sun.com/j2se/1.4/docs/api", testSrc,
"-sourcepath", testSrc,
"p1", "p2");
checkExit(Exit.OK);
checkOutput("index.html", true,
"<script type=\"text/javascript\">",
"""
<body class="package-index-page">""");
// Test that "onload" is not present in BODY tag:
checkOutput("p1/package-summary.html", true, """
<body class="package-declaration-page">""");
checkOutput("p1/C.html", true, "<title>C (Window Title)</title>");
}
}

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
</head>
<body bgcolor="white">
This document is generated from sample source code and HTML files
with examples of a wide variety of Java language constructs: packages,
subclasses, subinterfaces, nested classes, nested interfaces,
inheriting from other packages, constructors, fields,
methods, and so forth.
</body>
</html>

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C {
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,134 @@
java.applet
java.awt
java.awt.color
java.awt.datatransfer
java.awt.dnd
java.awt.event
java.awt.font
java.awt.geom
java.awt.im
java.awt.im.spi
java.awt.image
java.awt.image.renderable
java.awt.print
java.beans
java.beans.beancontext
java.io
java.lang
java.lang.ref
java.lang.reflect
java.math
java.net
java.nio
java.nio.channels
java.nio.channels.spi
java.nio.charset
java.nio.charset.spi
java.rmi
java.rmi.activation
java.rmi.dgc
java.rmi.registry
java.rmi.server
java.security
java.security.cert
java.security.interfaces
java.security.spec
java.sql
java.text
java.util
java.util.jar
java.util.logging
java.util.prefs
java.util.regex
java.util.zip
javax.accessibility
javax.crypto
javax.crypto.interfaces
javax.crypto.spec
javax.imageio
javax.imageio.event
javax.imageio.metadata
javax.imageio.plugins.jpeg
javax.imageio.spi
javax.imageio.stream
javax.naming
javax.naming.directory
javax.naming.event
javax.naming.ldap
javax.naming.spi
javax.net
javax.net.ssl
javax.print
javax.print.attribute
javax.print.attribute.standard
javax.print.event
javax.rmi
javax.rmi.CORBA
javax.security.auth
javax.security.auth.callback
javax.security.auth.kerberos
javax.security.auth.login
javax.security.auth.spi
javax.security.auth.x500
javax.security.cert
javax.sound.midi
javax.sound.midi.spi
javax.sound.sampled
javax.sound.sampled.spi
javax.sql
javax.swing
javax.swing.border
javax.swing.colorchooser
javax.swing.event
javax.swing.filechooser
javax.swing.plaf
javax.swing.plaf.basic
javax.swing.plaf.metal
javax.swing.plaf.multi
javax.swing.table
javax.swing.text
javax.swing.text.html
javax.swing.text.html.parser
javax.swing.text.rtf
javax.swing.tree
javax.swing.undo
javax.transaction
javax.transaction.xa
javax.xml.parsers
javax.xml.transform
javax.xml.transform.dom
javax.xml.transform.sax
javax.xml.transform.stream
org.ietf.jgss
org.omg.CORBA
org.omg.CORBA.DynAnyPackage
org.omg.CORBA.ORBPackage
org.omg.CORBA.TypeCodePackage
org.omg.CORBA.portable
org.omg.CORBA_2_3
org.omg.CORBA_2_3.portable
org.omg.CosNaming
org.omg.CosNaming.NamingContextExtPackage
org.omg.CosNaming.NamingContextPackage
org.omg.Dynamic
org.omg.DynamicAny
org.omg.DynamicAny.DynAnyFactoryPackage
org.omg.DynamicAny.DynAnyPackage
org.omg.IOP
org.omg.IOP.CodecFactoryPackage
org.omg.IOP.CodecPackage
org.omg.Messaging
org.omg.PortableInterceptor
org.omg.PortableInterceptor.ORBInitInfoPackage
org.omg.PortableServer
org.omg.PortableServer.CurrentPackage
org.omg.PortableServer.POAManagerPackage
org.omg.PortableServer.POAPackage
org.omg.PortableServer.ServantLocatorPackage
org.omg.PortableServer.portable
org.omg.SendingContext
org.omg.stub.java.rmi
org.w3c.dom
org.xml.sax
org.xml.sax.ext
org.xml.sax.helpers

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2002, 2022, 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 4034096 4764726 6235799 8182765 8196202
* @summary Add support for HTML keywords via META tag for
* class and member names to improve API search
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main MetaTag
*/
import java.text.SimpleDateFormat;
import java.util.Date;
import javadoc.tester.JavadocTester;
public class MetaTag extends JavadocTester {
/**
* The entry point of the test.
* @param args the array of command line arguments
* @throws Exception if the test fails
*/
public static void main(String... args) throws Exception {
var tester = new MetaTag();
tester.runTests();
}
@Test
public void testStandard() {
javadoc("-d", "out-1",
"-sourcepath", testSrc,
"-keywords",
"-doctitle", "Sample Packages",
"p1", "p2");
checkExit(Exit.OK);
checkMeta("dc.created", true);
}
@Test
public void testNoTimestamp() {
javadoc("-d", "out-2",
"-sourcepath", testSrc,
"-notimestamp",
"-doctitle", "Sample Packages",
"p1", "p2");
checkExit(Exit.OK);
// No keywords when -keywords is not used.
checkMeta("dc.created", false);
}
void checkMeta(String metaNameDate, boolean found) {
checkOutput("p1/C1.html", found,
"""
<meta name="keywords" content="p1.C1 class">""",
"""
<meta name="keywords" content="field1">""",
"""
<meta name="keywords" content="field2">""",
"""
<meta name="keywords" content="method1()">""",
"""
<meta name="keywords" content="method2()">""");
checkOutput("p1/package-summary.html", found,
"""
<meta name="keywords" content="p1 package">""");
checkOutput("index.html", found,
"""
<meta name="keywords" content="Overview, Sample Packages">""");
// NOTE: Hopefully, this regression test is not run at midnight. If the output
// was generated yesterday and this test is run today, this check could fail ...
// so make sure the date has not changed since the test started
String date = date();
if (date.equals(startDate)) {
checkOutput("index.html", found,
"<meta name=\"" + metaNameDate + "\" content=\"" + date + "\">");
}
}
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static final String startDate = date();
static String date() {
return dateFormat.format(new Date());
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C1 {
public C1() {
}
public C1(Object obj) {
}
public int field1 = 0;
public int field2 = 0;
public int method1() {
return 0;
}
/**
* Overload of method1() to demonstrate how all
* overloads are combined into a single meta keyword
*/
public int method1(String s) {
return 0;
}
public int method2(String s1, String s2) {
return 0;
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2025, 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 8346128 8346659
* @summary Check that snippet generation is reproducible
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main ReproducibleSnippetTest
*/
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
import java.nio.file.Path;
public class ReproducibleSnippetTest extends JavadocTester {
ToolBox tb = new ToolBox();
public static void main(String... args) throws Exception {
var tester = new ReproducibleSnippetTest();
tester.runTests();
}
@Test
public void test(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package p;
public interface One {
/**
* {@code One obj1}
* {@snippet lang = java:
* // @link substring="ab" target="One#ab" :
* obj1.ab(a()); // @link substring="a" target="#a"
*} class comment
*/
int a();
void ab(int i);
}
""");
javadoc("-d",
"out",
"-sourcepath",
src.toString(),
"p");
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true,
"One.java:5: error: snippet link tags:",
"#a",
"One#ab",
"overlap in obj1.ab(a());\n * {@snippet lang = java:\n ^");
}
}

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2011, 2015, 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.
*/
import java.io.ObjectStreamField;
import java.io.Serializable;
public class SerialFieldTest implements Serializable {
/**
* @serialField
* @serialField count int
* @serialField name String a test
*/
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("i", int.class),
new ObjectStreamField("count", Integer.TYPE),
new ObjectStreamField("name", String.class)
};
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2011, 2022, 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 6735320
* @summary javadoc throws exception if serialField value is missing
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main T6735320
*/
import javadoc.tester.JavadocTester;
public class T6735320 extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new T6735320();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
testSrc("SerialFieldTest.java"));
checkExit(Exit.ERROR);
checkOutput(Output.STDERR, false,
"OutOfBoundsException");
}
}

View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 2024, 2025, 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 8322708
* @summary Test to make sure global tags work properly
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestGlobalHtml
*/
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
import java.nio.file.Path;
public class TestGlobalHtml extends JavadocTester {
ToolBox tb = new ToolBox();
public static void main(String... args) throws Exception {
var tester = new TestGlobalHtml();
tester.runTests();
}
@Test
public void testGlobalTags() {
javadoc("--allow-script-in-comments",
"-d",
"out-global",
"-sourcepath",
testSrc,
"pkg1");
checkExit(Exit.OK);
}
@Test
public void testNegative(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package p;
/**
* class comment
* <a href="https://openjdk.org/">Hyperlink to the OpenJDK website</a>
*/
public class C {
/**
* <form>
* <label for="methodname">Method name:</label><br>
* <input type="text" id="methodname" name="methodname"><br>
* <label for="paramname">Method Parameter:</label><br>
* <input type="text" id="paramname" name="paramname">
* </form>
*/
public C() {
}
}
""");
javadoc("--allow-script-in-comments",
"-d",
"out-negative",
"-sourcepath",
src.toString(),
"p");
checkExit(Exit.ERROR);
}
}

View file

@ -0,0 +1,105 @@
/*
* Copyright (c) 2024, 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.
*/
package pkg1;
/**
* <div inert>
* <p> This content is inert and not interactable.</p>
* <a href="https://openjdk.org/" title="OpenJDK's Website" tabindex="0">
* Visit OpenJDK's Website!
* </a>
* </div>
*
* <div>
* <p autocapitalize="on">This content is interactable.</p>
* <a href="https://openjdk.org/" title="OpenJDK's Website" tabindex="0">
* Visit OpenJDK's Website!
* </a>
* </div>
*
*
* <div dir="ltr" lang="en">
* <p itemprop="description">This is used in a jtreg test to check that global HTML tags are allowed</p>
* <ul spellcheck="true">
* <li>Class C</li>
* <li>Has a default constructor</li>
* </ul>
* </div>
*
* <p contenteditable="true" inputmode="text">Here is a description of the class and methods:</p>
*
* <ol draggable="true" tabindex="0">
* <li><p accesskey="1" data-element-type="constructor" title="Class Details">Has a default constructor</p></li>
* <li><p accesskey="2" data-element-type="toString" title="Methods Summary">Overrides toString method</p></li>
* <li><p accesskey="3" data-element-type="other" title="Usage Example">Is used for testing</p></li>
* </ol>
*
* <div itemscope>
* <p itemprop="name">C1</p>
* <p itemprop="description">C1</p>
* </div>
*/
public class C1 {
/**
* <p lang="en" accesskey="D" autocapitalize="on" draggable="true" spellcheck="false">
* Default constructor for the {@code C1} class. (this content is draggable!) </p>
* <div lang="en" contenteditable="true">
* <p itemprop="creator">Author: try editing this content!</p>
* <p title="Creation Date">Created on: June 14 2024</p>
* </div>
*/
public C1() {
}
/**
* A method in C1
*
* <p lang="en" inputmode="numeric">simple method.</p>
*
* <div itemprop="method" itemscope>
* <p itemprop="name">method m</p>
* <p itemprop="description">the method m does nothing</p>
* </div>
*/
public void m() {
}
/**
* A toString Override.
*
* <p dir="ltr" spellcheck="true">returns a String Object.</p>
*
* <div itemprop="method" itemscope>
* <p itemprop="name">toString</p>
* </div>
*
* @return a string.
*/
@Override
public String toString() {
return "C1";
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2002, 2022, 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 4275630 4749453 4625400 4753048 4415270 8074521 8182765 8196202
* @summary Generated HTML is invalid with frames.
* Displays unnecessary horizontal scroll bars.
* Missing whitespace in DOCTYPE declaration
* HTML table tags inserted in wrong place in pakcage use page
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main ValidHtml
*/
import javadoc.tester.JavadocTester;
public class ValidHtml extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new ValidHtml();
tester.runTests();
}
@Test
public void test() {
// Test for all cases except the split index page
javadoc("-d", "out",
"-doctitle", "Document Title",
"-windowtitle", "Window Title",
"-use",
"-overview", testSrc("overview.html"),
"-sourcepath", testSrc,
"p1", "p2");
checkExit(Exit.OK);
String HTML5 = "<!DOCTYPE HTML>";
checkValidHTML(HTML5);
}
void checkValidHTML(String doctype) {
// Test the proper DOCTYPE element are present:
checkOutput("index.html", true, doctype);
checkOutput("overview-summary.html", true, doctype);
checkOutput("p1/package-summary.html", true, doctype);
checkOutput("p1/C.html", true, doctype);
}
}

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
</head>
<body bgcolor="white">
This document is generated from sample source code and HTML files
with examples of a wide variety of Java language constructs: packages,
subclasses, subinterfaces, nested classes, nested interfaces,
inheriting from other packages, constructors, fields,
methods, and so forth.
</body>
</html>

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C {
/**
* @param classparam C type included for "use"test
* @return String "Hi"
*/
public String publicMethod(C classparam) {
return "Hi";
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2002, 2022, 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 4720849
* @summary Standard doclet contains hard-coded version number
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main VersionNumber
*/
/**
* Runs javadoc and runs regression tests on the resulting HTML.
*/
import javadoc.tester.JavadocTester;
public class VersionNumber extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new VersionNumber();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"p1");
checkExit(Exit.OK);
// Test the proper DOCTYPE element is present:
checkOutput("p1/C.html", true,
"<!-- Generated by javadoc (");
}
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
public class C {
/**
* @param classparam C type included for "use"test
* @return String "Hi"
*/
public String publicMethod(C classparam) {
return "Hi";
}
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2002, 2022, 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 4530730 8196202
* @summary stddoclet: With frames off, window titles have "()" appended
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main WindowTitles
*/
/**
* Runs javadoc and runs regression tests on the resulting HTML.
*/
import javadoc.tester.JavadocTester;
public class WindowTitles extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new WindowTitles();
tester.runTests();
}
@Test
public void test() {
// Test for all cases except the split index page
javadoc("-d", "out-1",
"-use",
"-sourcepath", testSrc,
"p1", "p2");
checkExit(Exit.OK);
checkFiles(false, "allclasses-noframe.html");
checkTitle("index.html", "Overview");
checkTitle("overview-tree.html", "Class Hierarchy");
checkTitle("p1/package-summary.html", "p1");
checkTitle("p1/package-tree.html", "p1 Class Hierarchy");
checkTitle("p1/package-use.html", "Uses of Package p1");
checkTitle("p1/C1.html", "C1");
checkTitle("constant-values.html", "Constant Field Values");
checkTitle("deprecated-list.html", "Deprecated List");
checkTitle("serialized-form.html", "Serialized Form");
checkTitle("help-doc.html", "API Help");
checkTitle("index-all.html", "Index");
checkTitle("p1/class-use/C1.html", "Uses of Class p1.C1");
}
@Test
public void test2() {
// Test only for the split-index case (and run on only one package)
javadoc("-d", "out-2",
"-splitindex",
"-sourcepath", testSrc,
"p1");
checkExit(Exit.OK);
checkTitle("index-files/index-1.html", "C-Index");
}
void checkTitle(String file, String title) {
checkOutput(file, true, "<title>" + title + "</title>");
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2002, 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.
*/
package p1;
import java.io.Serializable;
public class C1 implements Serializable {
@Deprecated
public static final int ZERO = 0;
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2002, 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.
*/
package p2;
public class C2 {
}

View file

@ -0,0 +1,155 @@
/*
* Copyright (c) 2022, 2025, 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 8293177 8324774 8357458
* @summary Verify version numbers in legal files
* @library /test/lib
* @build jtreg.SkippedException
* @run main CheckLibraryVersions
*/
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import jtreg.SkippedException;
/**
* Checks the names and version strings of 3rd party libraries in legal files
* against the actual names and versions in library files.
*/
public class CheckLibraryVersions {
static class SourceDirNotFound extends Error {}
// Regex pattern for library name and version in legal Markdown file
static final Pattern versionPattern = Pattern.compile("## ([\\w\\s.]+) v(\\d+(\\.\\d+){1,2})");
// Map of 3rd party libraries. The keys are the names of files in the legal directory,
// the values are lists of templates for library files with the following placeholders:
// %V is replaced with the version string
// %M is replaced twice, once with an empty string and once with ".min"
static final Map<String, List<String>> libraries = Map.of(
"jquery.md", List.of("jquery/jquery-%V%M.js"),
"jqueryUI.md", List.of("jquery/jquery-ui%M.js", "jquery/jquery-ui%M.css"),
"dejavufonts.md", List.of("fonts/dejavu.css"),
"highlightjs.md", List.of("highlight.js")
);
public static void main(String... args) throws Exception {
try {
new CheckLibraryVersions().run(args);
} catch (SourceDirNotFound e) {
throw new SkippedException("NOTE: Cannot find src directory; test skipped");
}
}
static final PrintStream out = System.err;
void run(String... args) throws Exception {
var rootDir = args.length == 0 ? findRootDir() : Path.of(args[0]);
var legalDir = rootDir.resolve("src/jdk.javadoc/share/legal");
var scriptDir = rootDir.resolve("src/jdk.javadoc/share/classes")
.resolve("jdk/javadoc/internal/doclets/formats/html")
.resolve("resources");
for (var legalFileName : libraries.keySet()) {
var legalFile = legalDir.resolve(legalFileName);
out.println();
if (!Files.exists(legalFile)) {
error("Legal file not found: " + legalFile);
continue;
}
out.println("Checking legal file: " + legalFile);
var contents = Files.readString(legalFile);
var matcher = versionPattern.matcher(contents);
if (!matcher.find()) {
error("Library name and version not found in " + legalFile);
continue;
}
var libraryName = matcher.group(1);
var versionString = matcher.group(2);
out.println("Found name and version: " + matcher.group(1) + " " + matcher.group(2));
var templates = libraries.get(legalFileName);
for (var template : templates) {
checkLibraryFile(scriptDir, template, libraryName, versionString, "");
if (template.contains("%M")) {
checkLibraryFile(scriptDir, template, libraryName, versionString, ".min");
}
}
}
if (errors > 0) {
out.println(errors + " errors found");
throw new Exception(errors + " errors found");
}
}
void checkLibraryFile(Path scriptDir, String template, String libraryName,
String versionString, String minified) throws IOException {
out.println();
var libraryFileName = template
.replaceAll("%V", versionString)
.replaceAll("%M", minified);
var libraryFile = scriptDir.resolve(libraryFileName);
if (!Files.exists(libraryFile)) {
error("Library file not found: " + libraryFile);
return;
}
out.println("Checking library file: " + libraryFile);
var libraryContents = Files.readString(libraryFile);
var pattern = Pattern.compile("\\b" + libraryName + "[^\\n]* v" + versionString + "\\b");
var matcher = pattern.matcher(libraryContents);
if (!matcher.find()) {
error("Matching library name and version not found in " + libraryFileName);
return;
}
out.println("Found matching name and version: " + matcher.group());
}
int errors = 0;
void error(String message) {
("Error: " + message).lines().forEach(out::println);
errors++;
}
Path findRootDir() {
Path dir = Path.of(System.getProperty("test.src", ".")).toAbsolutePath();
while (dir != null) {
if (Files.exists(dir.resolve("src").resolve("jdk.javadoc"))) {
return dir;
} else {
Path openDir = dir.resolve("open");
if (Files.exists(openDir.resolve("src").resolve("jdk.javadoc"))) {
return openDir;
}
}
dir = dir.getParent();
}
throw new SourceDirNotFound();
}
}

View file

@ -0,0 +1,217 @@
/*
* Copyright (c) 2021, 2025, 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 8267574
* @summary check stylesheet names against HtmlStyle
* @modules jdk.javadoc/jdk.javadoc.internal.html
* jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.markup
* jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.resources:open
*/
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jdk.javadoc.internal.html.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
/**
* This test compares the set of CSS class names defined in HtmlStyles
* and other files (such as search.js) against the set of CSS class names
* defined in the main stylesheet.css provided by the doclet.
*
* The goal is to detect "unexpected" discrepancies between the two sets.
* "Expected" discrepancies are taken into account, but may indicate a
* need to resolve the discrepancy.
*
* The test does not take into direct account the recent introduction of
* CSS constructs like section {@code [class$="-details"]}
*/
public class CheckStylesheetClasses {
public static void main(String... args) throws Exception {
CheckStylesheetClasses c = new CheckStylesheetClasses();
c.run();
}
int errors = 0;
void run() throws Exception {
Set<String> htmlStyleNames = getHtmlStyleNames();
Set<String> styleSheetNames = getStylesheetNames();
System.err.println("found " + htmlStyleNames.size() + " names in HtmlStyle");
System.err.println("found " + styleSheetNames.size() + " names in stylesheet");
// Write the lists to external files for the benefit of external diff tools:
// for example, to compare against the CSS class names used in generated documentation.
// To find the classes used in a directory containing HTML files, use something like
// find $DIRECTORY -name \*.html | \
// xargs grep -o 'class="[^"]*"' | \
// sed -e 's/^[^"]*"//' -e 's/".*$//' | \
// while read line ; do for w in $line ; do echo $w ; done ; done | \
// sort -u
try (BufferedWriter out = Files.newBufferedWriter(Path.of("htmlStyleNames.txt"));
PrintWriter pw = new PrintWriter(out)) {
htmlStyleNames.forEach(pw::println);
}
try (BufferedWriter out = Files.newBufferedWriter(Path.of("styleSheetNames.txt"));
PrintWriter pw = new PrintWriter(out)) {
styleSheetNames.forEach(pw::println);
}
// Remove names from htmlStyleNames if they are valid names generated by the doclet,
// even if they do not by default require a style to be defined in the stylesheet.
// In general, names in these lists are worthy of attention to see if they *should*
// be defined in the stylesheet, especially when the names exist in a family of
// related items: related by name or by function.
// the page names are provided to override a style on a specific page;
// only some are used in the stylesheet
htmlStyleNames.removeIf(s -> s.endsWith("-page") && !styleSheetNames.contains(s));
// descriptions; class-description is used;
// surprisingly? module-description and package-description are not
htmlStyleNames.removeIf(s -> s.endsWith("-description") && !styleSheetNames.contains(s));
// help page
htmlStyleNames.removeIf(s -> s.startsWith("help-") && !styleSheetNames.contains(s));
// summary and details tables; styles for these may be present in the stylesheet
// using constructs like these:
// .summary section[class$="-summary"], .details section[class$="-details"],
htmlStyleNames.removeIf(s -> s.endsWith("-details") && !styleSheetNames.contains(s));
htmlStyleNames.removeIf(s -> s.endsWith("-summary") && !styleSheetNames.contains(s));
// signature classes
removeAll(htmlStyleNames, "element-name", "extends-implements",
"modifiers", "permits", "return-type");
// misc: these are defined in HtmlStyle, and used by the doclet
removeAll(htmlStyleNames, "col-plain", "external-link", "header",
"package-uses", "packages", "permits-note", "serialized-package-container",
"source-container");
// Remove names from styleSheetNames if they are false positives,
// or used by other code (i.e. not HtmlStyle),
// or if they are unused and therefore candidates to be deleted.
// false positives: file extensions and URL components
removeAll(styleSheetNames, "css", "svg", "w3", "org");
// for doc-comment authors; maybe worthy of inclusion in HtmlStyle, just to be documented
removeAll(styleSheetNames, "borderless", "plain", "striped");
// used in search.js and search-page.js; may be worth documenting in HtmlStyle
removeAll(styleSheetNames, "result-highlight", "result-item", "anchor-link", "expanded",
"page-search-header", "result-table", "ui-autocomplete", "ui-autocomplete-category",
"ui-state-active", "ui-menu", "ui-menu-item-wrapper", "ui-static-link",
"search-result-desc", "search-result-label", "search-result-link", "selected",
"sort-asc", "sort-desc", "two-column-search-results", "visible");
// very JDK specific
styleSheetNames.remove("module-graph");
styleSheetNames.remove("sealed-graph");
boolean ok = check(htmlStyleNames, "HtmlStyle", styleSheetNames, "stylesheet")
& check(styleSheetNames, "stylesheet", htmlStyleNames, "HtmlStyle");
if (!ok) {
throw new Exception("differences found");
}
if (errors > 0) {
throw new Exception(errors + " errors found");
}
}
boolean check(Set<String> s1, String l1, Set<String> s2, String l2) {
boolean equal = true;
for (String s : s1) {
if (!s2.contains(s)) {
System.err.println("In " + l1 + " but not " + l2 + ": " + s);
equal = false;
}
}
return equal;
}
/**
* Remove all the names from the set, giving a message for any that were not found.
*/
void removeAll(Set<String> set, String... names) {
for (String name : names) {
if (!set.remove(name)) {
error("name not found in set: " + name);
}
}
}
void error(String message) {
System.err.println("error: " + message);
errors++;
}
Set<String> getHtmlStyleNames() {
return Arrays.stream(HtmlStyles.values())
.map(HtmlStyle::cssName)
.collect(Collectors.toCollection(TreeSet::new));
}
Set<String> getStylesheetNames() throws IOException {
Set<String> names = new TreeSet<>();
String stylesheet = "/jdk/javadoc/internal/doclets/formats/html/resources/stylesheet.css";
URL url = HtmlStyles.class.getResource(stylesheet);
readStylesheet(url, names);
return names;
}
private void readStylesheet(URL resource, Set<String> names) throws IOException {
try (InputStream in = resource.openStream()) {
if (in == null) {
throw new AssertionError("Cannot find or access resource " + resource);
}
String s = new String(in.readAllBytes())
.replaceAll("(?s)/\\*.*?\\*/", ""); // remove comments
Pattern p = Pattern.compile("(?i)\\.(?<name>[a-z][a-z0-9-]+)\\b");
Matcher m = p.matcher(s);
while (m.find()) {
names.add(m.group("name"));
}
}
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2005, 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.
*/
package pkg2;
public class A {
/** Test constant. */
public static final String DEMO= "y<abs(x)";
/** Connection URL for the JDBC Driver. */
public static final String THIS_IS_OK= "y < abs(x)";
public static final String DEMO_STRING = "<Hello World>";
public A() {
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2001, 2015, 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.
*/
public class TestConstantValues {
/**
* Test 1 passes ({@value}).
*/
public static final int TEST1PASSES = 500000;
/**
* Test 2 passes ({@value}).
*/
public static final String TEST2PASSES = "My String";
// all of if not most are in the JDK sources, it is
// crucial we catch any discrepancies now.
public static final byte BYTE_MAX_VALUE = 127;
public static final byte BYTE_MIN_VALUE = -127;
public static final char CHAR_MAX_VALUE = 65535;
public static final double DOUBLE_MAX_VALUE = 1.7976931348623157E308;
public static final double DOUBLE_MIN_VALUE = 4.9E-324;
public static final float MAX_FLOAT_VALUE = 3.4028234663852886E38f;
public static final float MIN_FLOAT_VALUE = 1.401298464324817E-45f;
public static final boolean HELLO = true;
public static final boolean GOODBYE = false;
public static final int INT_MAX_VALUE = 2147483647;
public static final int INT_MIN_VALUE = -2147483647;
public static final long LONG_MAX_LONG_VALUE = 9223372036854775807L;
public static final long LONG_MIN_LONG_VALUE = -9223372036854775808L;
public static final short SHORT_MAX_VALUE = 32767;
public static final short SHORT_MIN_VALUE = -32767;
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2002, 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.
*/
public interface TestConstantValues2 {
/**
* Test 3 passes ({@value}).
*/
public static final int TEST3PASSES = 500000;
/**
* Test 4 passes ({@value}).
*/
public static final String TEST4PASSES = "My String";
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2002, 2022, 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 4504730 4526070 5077317 8162363
* @summary Test the generation of constant-values.html.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestConstantValuesDriver
*/
import javadoc.tester.JavadocTester;
public class TestConstantValuesDriver extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestConstantValuesDriver();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
testSrc("TestConstantValues.java"),
testSrc("TestConstantValues2.java"),
testSrc("A.java"));
checkExit(Exit.OK);
checkOutput("constant-values.html", true,
"TEST1PASSES",
"TEST2PASSES",
"TEST3PASSES",
"TEST4PASSES",
"""
<code>"&lt;Hello World&gt;"</code>""",
"""
<code id="TestConstantValues.BYTE_MAX_VALUE">public&nbsp;static&nbsp;final&nbsp;byte</code></div>
<div class="col-second even-row-color"><code><a href="TestConstantValues.html#BYTE_MAX_VALUE">BYTE_MAX_VALUE</a></code></div>
<div class="col-last even-row-color"><code>0x7f</code></div>""",
"""
<code id="TestConstantValues.BYTE_MIN_VALUE">public&nbsp;static&nbsp;final&nbsp;byte</code></div>
<div class="col-second odd-row-color"><code><a href="TestConstantValues.html#BYTE_MIN_VALUE">BYTE_MIN_VALUE</a></code></div>
<div class="col-last odd-row-color"><code>0x81</code></div>""",
"""
<code id="TestConstantValues.CHAR_MAX_VALUE">public&nbsp;static&nbsp;final&nbsp;char</code></div>
<div class="col-second even-row-color"><code><a href="TestConstantValues.html#CHAR_MAX_VALUE">CHAR_MAX_VALUE</a></code></div>
<div class="col-last even-row-color"><code>'\\uffff'</code></div>""",
"""
<code id="TestConstantValues.DOUBLE_MAX_VALUE">public&nbsp;static&nbsp;final&nbsp;double</code></div>""",
"""
<div class="col-second odd-row-color"><code><a href="TestConstantValues.html#DOUBLE_MAX_VALUE">\
DOUBLE_MAX_VALUE</a></code></div>
<div class="col-last odd-row-color"><code>1.7976931348623157E308</code></div>""",
"""
<code id="TestConstantValues.DOUBLE_MIN_VALUE">public&nbsp;static&nbsp;final&nbsp;double</code></div>
<div class="col-second even-row-color"><code><a href="TestConstantValues.html#DOUBLE_MIN_VALUE">\
DOUBLE_MIN_VALUE</a></code></div>""",
"""
<code id="TestConstantValues.GOODBYE">public&nbsp;static&nbsp;final&nbsp;boolean</code></div>
<div class="col-second odd-row-color"><code><a href="TestConstantValues.html#GOODBYE">GOODBYE</a></code></div>""",
"""
<code id="TestConstantValues.HELLO">public&nbsp;static&nbsp;final&nbsp;boolean</code></div>
<div class="col-second even-row-color"><code><a href="TestConstantValues.html#HELLO">HELLO</a></code></div>
<div class="col-last even-row-color"><code>true</code></div>"""
);
}
}

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2002, 2022, 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 4525364
* @summary Determine if duplicate throws tags can be used.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestDupThrowsTags
*/
import javadoc.tester.JavadocTester;
public class TestDupThrowsTags extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestDupThrowsTags();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
testSrc("TestDupThrowsTags.java"));
checkExit(Exit.ERROR);
checkOutput("TestDupThrowsTags.html", true,
"Test 1 passes",
"Test 2 passes",
"Test 3 passes",
"Test 4 passes");
}
/**
* @throws java.io.IOException Test 1 passes
* @throws java.io.IOException Test 2 passes
* @throws java.lang.NullPointerException Test 3 passes
* @throws java.io.IOException Test 4 passes
*/
public void method() {}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2002, 2022, 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 4640745
* @summary This test verifys that the -link option handles absolute paths.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestAbsLinkPath
*/
import javadoc.tester.JavadocTester;
public class TestAbsLinkPath extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestAbsLinkPath();
tester.runTests();
}
@Test
public void test1() {
String out1 = "out1";
javadoc("-d", out1, "-sourcepath", testSrc, "pkg2");
checkExit(Exit.OK);
javadoc("-d", "out2",
"-sourcepath", testSrc,
"-link", "../" + out1,
"pkg1");
checkExit(Exit.OK);
checkOutput("pkg1/C1.html", true,
"C2.html");
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2002, 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.
*/
package pkg1;
import pkg2.*;
/**
* Class 1
*/
public class C1 extends C2 {}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2002, 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.
*/
package pkg2;
/**
* Class 2
*/
public class C2 {}

View file

@ -0,0 +1,132 @@
/*
* Copyright (c) 2012, 2022, 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 8004891 8184205
* @summary Make sure that the abstract method is identified correctly
* if the abstract modifier is present explicitly or implicitly.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestAbstractMethod
*/
import javadoc.tester.JavadocTester;
public class TestAbstractMethod extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestAbstractMethod();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"pkg");
checkExit(Exit.OK);
checkOutput("pkg/A.html", true,
"""
<div class="col-first even-row-color method-summary-table method-summary-table-t\
ab2 method-summary-table-tab5"><code>default void</code></div>""",
"""
<div class="table-tabs" role="tablist" aria-orientation="horizontal">\
<button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-cont\
rols="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" o\
nclick="show('method-summary-table', 'method-summary-table', 3)" class="active-t\
able-tab">All Methods</button>\
<button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="t\
able-tab">Instance Methods</button>\
<button id="method-summary-table-tab3" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab3', 3)" class="t\
able-tab">Abstract Methods</button>\
<button id="method-summary-table-tab5" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab5', 3)" class="t\
able-tab">Default Methods</button>\
</div>""");
checkOutput("pkg/B.html", true,
"""
<div class="table-tabs" role="tablist" aria-orientation="horizontal">\
<button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-cont\
rols="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" o\
nclick="show('method-summary-table', 'method-summary-table', 3)" class="active-t\
able-tab">All Methods</button>\
<button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="t\
able-tab">Instance Methods</button>\
<button id="method-summary-table-tab3" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab3', 3)" class="t\
able-tab">Abstract Methods</button>\
<button id="method-summary-table-tab4" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab4', 3)" class="t\
able-tab">Concrete Methods</button>\
</div>""",
"""
<div class="col-first even-row-color method-summary-table method-summary-table-t\
ab2 method-summary-table-tab3"><code>abstract void</code></div>""");
checkOutput("pkg/C.html", true,
"""
<div class="table-tabs" role="tablist" aria-orientation="horizontal">\
<button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-cont\
rols="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" o\
nclick="show('method-summary-table', 'method-summary-table', 3)" class="active-t\
able-tab">All Methods</button>\
<button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="t\
able-tab">Instance Methods</button>\
<button id="method-summary-table-tab5" role="tab" aria-selected="false" aria-con\
trols="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)"\
onclick="show('method-summary-table', 'method-summary-table-tab5', 3)" class="t\
able-tab">Default Methods</button>\
</div>""");
checkOutput("pkg/A.html", false,
"""
<div class="col-first even-row-color method-summary-table-tab2 method-summary-ta\
ble method-summary-table-tab3"><code>abstract void</code></div>""");
checkOutput("pkg/B.html", false,
"""
Default Methods""",
"""
<div class="col-first even-row-color method-summary-table-tab2 method-summary-ta\
ble-tab5 method-summary-table"><code>default void</code></div>""");
checkOutput("pkg/C.html", false,
"""
Abstract Methods""");
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2012, 2013, 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.
*/
package pkg;
public interface A {
public void method1();
public default void defaultMethod() { }
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2012, 2013, 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.
*/
package pkg;
public abstract class B {
public abstract void method1();
public void method2() { }
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2012, 2013, 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.
*/
package pkg;
public interface C {
public default void onlyMethod() { }
}

View file

@ -0,0 +1,252 @@
/*
* Copyright (c) 2013, 2024, 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 8025633 8025524 8081854 8187521 8182765 8261976
* @summary Test for valid name attribute in HTML anchors.
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestAnchorNames
*/
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
public class TestAnchorNames extends JavadocTester {
public final ToolBox tb;
public static void main(String... args) throws Exception {
var tester = new TestAnchorNames();
tester.runTests();
}
public TestAnchorNames() {
tb = new ToolBox();
}
@Test
public void testHtml5(Path ignore) {
javadoc("-d", "out-html5",
"-sourcepath", testSrc,
"-source", "8", //so that '_' can be used as an identifier
"-use",
"pkg1");
checkExit(Exit.OK);
// Test some section markers and links to these markers
checkOutput("pkg1/RegClass.html", true,
"""
<span class="skip-nav" id="skip-navbar-top">""",
"""
<a href="#skip-navbar-top" title="Skip navigation links">""",
"""
<section class="nested-class-summary" id="nested-class-summary">
<h2>Nested Class Summary</h2>""",
"<a href=\"#nested-class-summary\" tabindex=\"0\">",
"""
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>""",
"<a href=\"#method-summary\" tabindex=\"0\">",
"""
<section class="field-details" id="field-detail">
<h2>Field Details</h2>""",
"<a href=\"#field-detail\" tabindex=\"0\">",
"""
<section class="constructor-details" id="constructor-detail">
<h2>Constructor Details</h2>""",
"<a href=\"#constructor-detail\" tabindex=\"0\">");
// Test some members and link to these members
checkOutput("pkg1/RegClass.html", true,
//The marker for this appears in the serialized-form.html which we will
//test below
"""
<a href="../serialized-form.html#pkg1.RegClass">""");
// Test some fields
checkOutput("pkg1/RegClass.html", true,
"<section class=\"detail\" id=\"_\">",
"<a href=\"#_\" class=\"member-name-link\">",
"<section class=\"detail\" id=\"_$\">",
"<a href=\"#_$\" class=\"member-name-link\">",
"<section class=\"detail\" id=\"$_\">",
"<a href=\"#$_\" class=\"member-name-link\">",
"""
<section class="detail" id="$field">""",
"<a href=\"#$field\" class=\"member-name-link\">",
"""
<section class="detail" id="fieldInCla$$">""",
"<a href=\"#fieldInCla$$\" class=\"member-name-link\">",
"""
<section class="detail" id="S_$$$$$INT">""",
"<a href=\"#S_$$$$$INT\" class=\"member-name-link\">",
"""
<section class="detail" id="method$$">""",
"<a href=\"#method$$\" class=\"member-name-link\">");
checkOutput("pkg1/DeprMemClass.html", true,
"""
<section class="detail" id="_field_In_Class">""",
"<a href=\"#_field_In_Class\" class=\"member-name-link\">");
// Test constructor
checkOutput("pkg1/RegClass.html", true,
"""
<section class="detail" id="&lt;init&gt;(java.lang.String,int)">""",
"""
<a href="#%3Cinit%3E(java.lang.String,int)" class="member-name-link">""");
// Test some methods
checkOutput("pkg1/RegClass.html", true,
"""
<section class="detail" id="_methodInClass(java.lang.String)">""",
"""
<a href="#_methodInClass(java.lang.String)" class="member-name-link">""",
"""
<section class="detail" id="method()">""",
"<a href=\"#method()\" class=\"member-name-link\">",
"""
<section class="detail" id="foo(java.util.Map)">""",
"<a href=\"#foo(java.util.Map)\" class=\"member-name-link\">",
"""
<section class="detail" id="methodInCla$s(java.lang.String[])">""",
"""
<a href="#methodInCla$s(java.lang.String%5B%5D)" class="member-name-link">""",
"""
<section class="detail" id="_methodInClas$(java.lang.String,int)">""",
"""
<a href="#_methodInClas$(java.lang.String,int)" class="member-name-link">""",
"""
<section class="detail" id="methodD(pkg1.RegClass.$A)">""",
"""
<a href="#methodD(pkg1.RegClass.$A)" class="member-name-link">""",
"""
<section class="detail" id="methodD(pkg1.RegClass.D[])">""",
"""
<a href="#methodD(pkg1.RegClass.D%5B%5D)" class="member-name-link">""");
checkOutput("pkg1/DeprMemClass.html", true,
"""
<section class="detail" id="$method_In_Class()">""",
"<a href=\"#$method_In_Class()\" class=\"member-name-link\">");
// Test enum
checkOutput("pkg1/RegClass.Te$t_Enum.html", true,
"""
<section class="detail" id="$FLD2">""",
"<a href=\"#$FLD2\" class=\"member-name-link\">");
// Test nested class
checkOutput("pkg1/RegClass._NestedClas$.html", true,
"""
<section class="detail" id="&lt;init&gt;()">""",
"<a href=\"#%3Cinit%3E()\" class=\"member-name-link\">");
// Test class use page
checkOutput("pkg1/class-use/DeprMemClass.html", true,
"""
<a href="../RegClass.html#d____mc" class="member-name-link">""");
// Test deprecated list page
checkOutput("deprecated-list.html", true,
"""
<a href="pkg1/DeprMemClass.html#_field_In_Class">""",
"""
<a href="pkg1/DeprMemClass.html#$method_In_Class()">""");
// Test constant values page
checkOutput("constant-values.html", true,
"""
<a href="pkg1/RegClass.html#S_$$$$$INT">""");
// Test serialized form page
checkOutput("serialized-form.html", true,
//This is the marker for the link that appears in the pkg1.RegClass.html page
"""
<section class="serialized-class-details" id="pkg1.RegClass">""");
// Test member name index page
checkOutput("index-all.html", true,
"""
<h2 class="title" id="I:$">$</h2>""",
"<a href=\"#I:$\">$",
"<a href=\"#I:_\">_");
}
/**
* The following test is somewhat simplistic, but it is useful
* in conjunction with the W3C Validation Service at https://validator.w3.org/nu/#file
* @param base A working directory for this method, in which some UTF-8 source files
* will be generated
* @throws IOException if there is a problem generating the source files
*/
@Test
public void testNonAscii(Path base) throws IOException {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"package p; public class Def {\n"
+ " public int \u00e0\u00e9;\n" // a`e'
+ " public void \u00c0\u00c9() { }\n" // A`E'
+ " public int \u03b1\u03b2\u03b3;\n" // alpha beta gamma
+ " public void \u0391\u0392\u0393() { }\n" // ALPHA BETA GAMMA
+ "}",
"package p; \n"
+ "/**\n"
+ " * {@link Def#\u00e0\u00e9 &agrave;&eacute;}<br>\n"
+ " * {@link Def#\u00c0\u00c9() &Agrave;&Eacute;}<br>\n"
+ " * {@link Def#\u03b1\u03b2\u03b3 &alpha;&beta;&gamma;}<br>\n"
+ " * {@link Def#\u0391\u0392\u0393() &Alpha;&Beta;&Gamma;}<br>\n"
+ " */\n"
+ "public class Ref { }");
javadoc("-d", "out-nonAscii",
"-sourcepath", src.toString(),
"-html5",
"-encoding", "utf-8",
"p");
checkExit(Exit.OK);
checkOutput("p/Def.html", true,
"<section class=\"detail\" id=\"\u00e0\u00e9\">",
"<section class=\"detail\" id=\"\u00c0\u00c9()\">",
"<section class=\"detail\" id=\"\u03b1\u03b2\u03b3\">",
"<section class=\"detail\" id=\"\u0391\u0392\u0393()\">");
checkOutput("p/Ref.html", true,
"""
<a href="Def.html#%C3%A0%C3%A9"><code>&agrave;&eacute;</code></a>""",
"""
<a href="Def.html#%C3%80%C3%89()"><code>&Agrave;&Eacute;</code></a>""",
"""
<a href="Def.html#%CE%B1%CE%B2%CE%B3"><code>&alpha;&beta;&gamma;</code></a>""",
"""
<a href="Def.html#%CE%91%CE%92%CE%93()"><code>&Alpha;&Beta;&Gamma;</code></a>""");
}
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2013, 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.
*/
package pkg1;
public class DeprMemClass
{
/**
* Field in the class.
* @deprecated Do not use this field.
*/
public int _field_In_Class;
public int _fld;
/**
* Method in the class.
* @deprecated Do not use this method.
*/
public void $method_In_Class() {
}
public void regularMethod() {
}
}

View file

@ -0,0 +1,186 @@
/*
* Copyright (c) 2013, 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.
*/
package pkg1;
import java.io.Serializable;
import java.util.Map;
/**
* @serial This is the serial tag's comment.
*/
public class RegClass implements Serializable {
/**
* Normal field in class.
*/
public String field;
/**
* Normal field in class.
*/
public String method$$;
/**
* Filed staring with $.
*/
public String $field;
/**
* Filed staring with underscore.
*/
public String _field;
/**
* Serial field
* @serial
*/
public boolean t_e$t;
/**
* Field in class with a $ in the name.
*/
public String fieldInCla$$;
/**
* Field name as just an underscore.
*/
public int _;
/**
* Field name as just a $.
*/
public int $;
/**
* Field name with underscore and $.
*/
public int _$;
/**
* Field name with $ and underscore.
*/
public int $_;
/**
* An array.
*/
public int arr[];
/**
* Another array.
*/
public int[] arr1;
/**
* A constant field.
*/
public static final int S_$$$$$INT = 0;
/**
* Another field.
*/
public DeprMemClass d____mc;
/**
* An enum.
*/
public static enum Te$t_Enum {
FLD_1,
$FLD2
};
/**
* A constructor.
*/
public RegClass(String p, int i) {
}
/**
* Method in Class.
* @param p a string
*/
public void _methodInClass(String p) {
}
/**
* Method in Class.
* @param p a string
* @param i an int
*/
public void _methodInClas$(String p, int i) {
}
/**
* Method with $ in the name.
* @param p a string array
*/
public void methodInCla$s(String[] p) {
}
/**
* Method with D[] as a parameter.
* @param p an array of D
*/
public void methodD(D[] p) {
}
/**
* Method with $A as a parameter.
* @param p an object of $A
*/
public void methodD($A p) {
}
/**
* Serial test.
* @serialData This is a serial data comment.
* @return null
*/
protected Object $readResolve(){return null;}
/**
* Simple method.
*/
public void method() {}
/**
* Generics.
*/
public static <A> void foo(Map<A, Map<A, A>> map) {}
/**
* A nested class.
*/
public class _NestedClas$ {}
/**
* Nested class D.
*/
class D {}
/**
* Nested class $A.
*/
class $A {}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2009, 2022, 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 8025633 8081854 8182765 8261976
* @summary Make sure that annotations types with optional elements have
* element headers
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestAnnotationOptional
*/
import javadoc.tester.JavadocTester;
public class TestAnnotationOptional extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestAnnotationOptional();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"pkg");
checkExit(Exit.OK);
checkOutput("pkg/AnnotationOptional.html", true,
"""
<section class="details" id="annotation-interface-element-detail">""");
}
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2009, 2019, 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.
*/
package pkg;
import java.lang.annotation.*;
/**
* This is just a test annotation type with optional value element.
*/
@Documented public @interface AnnotationOptional {
String value() default "";
}

View file

@ -0,0 +1,210 @@
/*
* Copyright (c) 2004, 2025, 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 4973609 8015249 8025633 8026567 6469561 8071982 8162363 8182765 8223364
8242056 8261976 8223358 8313204
* @summary Make sure that annotation types with 0 members does not have
* extra HR tags.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestAnnotationTypes
*/
import javadoc.tester.JavadocTester;
public class TestAnnotationTypes extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestAnnotationTypes();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out-1",
"-sourcepath", testSrc,
"--no-platform-links",
"pkg");
checkExit(Exit.OK);
checkOutput("pkg/AnnotationTypeField.html", true,
"""
<li><a href="#field-summary" tabindex="0">Field Summary</a></li>""",
"""
<li><a href="#field-detail" tabindex="0">Field Details</a>
<ol class="toc-list">
<li><a href="#DEFAULT_NAME" tabindex="0">DEFAULT_NAME</a></li>""",
"<!-- =========== FIELD SUMMARY =========== -->",
"<h2>Field Summary</h2>",
"""
<div class="col-second even-row-color"><code><a href="#DEFAULT_NAME" class="memb\
er-name-link">DEFAULT_NAME</a></code></div>""",
"<!-- ============ FIELD DETAIL =========== -->",
"""
<section class="detail" id="DEFAULT_NAME">
<h3>DEFAULT_NAME</h3>
<div class="horizontal-scroll">
<div class="member-signature"><span class="modifiers">static final</span>&nbsp;<\
span class="return-type">java.lang.String</span>&nbsp;<span class="element-name">DEFAULT_NAME</span></div>
""");
checkOutput("pkg/AnnotationType.html", true,
"""
<ol class="toc-list" tabindex="-1">
<li><a href="#" tabindex="0">Description</a></li>
<li><a href="#annotation-interface-required-element-summary" tabindex="0">Required Element Summary</a></li>
<li><a href="#annotation-interface-optional-element-summary" tabindex="0">Optional Element Summary</a></li>
<li><a href="#annotation-interface-element-detail" tabindex="0">Element Details</a>
<ol class="toc-list">
<li><a href="#value()" tabindex="0">value</a></li>
<li><a href="#optional()" tabindex="0">optional</a></li>
</ol>
</li>
</ol>""");
checkOutput("pkg/AnnotationType.html", true,
"""
<section class="summary">
<ul class="summary-list">
<!-- =========== ANNOTATION INTERFACE REQUIRED MEMBER SUMMARY =========== -->
<li>
<section class="member-summary" id="annotation-interface-required-element-summary">
<h2>Required Element Summary</h2>
<div class="caption"><span>Required Elements</span></div>
<div class="summary-table three-column-summary">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Required Element</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color"><code>int</code></div>
<div class="col-second even-row-color"><code><a href="#value()" class="member-name-link">value</a></code></div>
<div class="col-last even-row-color">&nbsp;</div>
</div>
</section>
</li>
<!-- =========== ANNOTATION INTERFACE OPTIONAL MEMBER SUMMARY =========== -->
<li>
<section class="member-summary" id="annotation-interface-optional-element-summary">
<h2>Optional Element Summary</h2>
<div class="caption"><span>Optional Elements</span></div>
<div class="summary-table three-column-summary">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Optional Element</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color"><code>java.lang.String</code></div>
<div class="col-second even-row-color"><code><a href="#optional()" class="member-name-link">optional</a></code></div>
<div class="col-last even-row-color">&nbsp;</div>
</div>
</section>
</li>
</ul>
</section>""",
"""
<section class="details" id="annotation-interface-element-detail">
<ul class="details-list">
<!-- ============ ANNOTATION INTERFACE MEMBER DETAIL =========== -->
<li>
<section class="member-details">
<h2>Element Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="value()">
<h3>value</h3>
<div class="horizontal-scroll">
<div class="member-signature"><span class="return-type">int</span>&nbsp;<span class="element-name">value</span></div>
</div>
</section>
</li>
<li>
<section class="detail" id="optional()">
<h3>optional</h3>
<div class="horizontal-scroll">
<div class="member-signature"><span class="return-type">java.lang.String</span>&nbsp;<span class="element-name">optional</span></div>
<dl class="notes">
<dt>Default:</dt>
<dd><code>""</code></dd>
</dl>
</div>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>""");
checkOutput("pkg/AnnotationType.html", false,
"""
<HR>
<P>
<P><!-- ========= END OF CLASS DATA ========= --><HR>""");
}
@Test
public void testLinkSource() {
javadoc("-d", "out-2",
"-linksource",
"--no-platform-links",
"-sourcepath", testSrc,
"pkg");
checkExit(Exit.OK);
checkOutput("src-html/pkg/AnnotationType.html", true,
"<title>Source code</title>",
"@Documented public @interface AnnotationType {");
checkOutput("src-html/pkg/AnnotationTypeField.html", true,
"<title>Source code</title>",
"@Documented public @interface AnnotationTypeField {");
checkOutput("pkg/AnnotationType.html", true,
"""
<span class="modifiers">public @interface </span><span class="element-name"><a href="../src-html/pkg/AnnotationType.html#line-31">AnnotationType</a></span></div>""");
checkOutput("pkg/AnnotationTypeField.html", true,
"""
<span class="modifiers">public @interface </span><span class="element-name"><a href="../src-html/pkg/AnnotationTypeField.html#line-31">AnnotationTypeField</a></span></div>""");
}
@Test
public void testSectionOrdering() {
javadoc("-d", "out-3",
"-linksource",
"--no-platform-links",
"-sourcepath", testSrc,
"pkg");
checkExit(Exit.OK);
checkOrder("pkg/AnnotationTypeField.html",
"<ul class=\"summary-list\">",
"<section class=\"field-summary\" id=\"field-summary\">",
"<section class=\"member-summary\" id=\"annotation-interface-optional-element-summary\">",
"<ul class=\"details-list\">",
"<section class=\"field-details\" id=\"field-detail\">",
"<section class=\"detail\" id=\"DEFAULT_NAME\">");
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004, 2021, 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.
*/
package pkg;
import java.lang.annotation.*;
/**
* This is just a test annotation type.
*/
@Documented public @interface AnnotationType {
int value();
String optional() default "";
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2013, 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.
*/
package pkg;
import java.lang.annotation.*;
/**
* This is just a test for annotation type fields.
*/
@Documented public @interface AnnotationTypeField {
String DEFAULT_NAME = "test";
String name() default DEFAULT_NAME;
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 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 8309150
* @summary Need to escape " inside attribute values
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestAttribute
*/
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
public class TestAttribute extends JavadocTester {
public final ToolBox tb;
public static void main(String... args) throws Exception {
var tester = new TestAttribute();
tester.runTests();
}
public TestAttribute() {
tb = new ToolBox();
}
@Test
public void testQuote(Path base) throws IOException {
var src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/**
* First sentence.
* @spec http://example.com title with "quotes"
*/
public class C { private C() { } }""");
javadoc("-d", base.resolve("api").toString(),
"-sourcepath", src.toString(),
"p");
checkExit(Exit.OK);
// Test some section markers and links to these markers
checkOutput("p/C.html", true,
"""
<a href="http://example.com"><span id="titlewith&quot;quotes&quot;" \
class="search-tag-result">title with "quotes"</span></a>""");
}
}

View file

@ -0,0 +1,232 @@
/*
* Copyright (c) 2018, 2024, 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 8202947 8239804 8324342
* @summary test the at-author tag, and corresponding option
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestAuthor
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
public class TestAuthor extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestAuthor();
tester.runTests();
}
ToolBox tb = new ToolBox();
Path src;
TestAuthor() throws Exception {
src = Files.createDirectories(Paths.get("src"));
tb.writeJavaFiles(src,
"""
package pkg;
/** Introduction.\s
* @author anonymous
*/
public class Test { }
""");
}
@Test
public void testAuthor() {
javadoc("-d", "out-author",
"-sourcepath", src.toString(),
"-author",
"pkg");
checkExit(Exit.OK);
checkAuthor(true);
}
@Test
public void testNoAuthor() {
javadoc("-d", "out-noauthor",
"-sourcepath", src.toString(),
"pkg");
checkExit(Exit.OK);
checkAuthor(false);
}
@Test
public void testBadAuthor_NoWarning(Path base) throws IOException {
testBadAuthor(base, false);
}
@Test
public void testBadAuthor_Warning(Path base) throws IOException {
testBadAuthor(base, true);
}
public void testBadAuthor(Path base, boolean useAuthorOption) throws IOException {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package pkg;
/** Comment. */
public class Test {
private Test() { }
/**
* Comment.
* @author anonymous
*/
public void m() { }
}""");
javadoc("-d", base.resolve("out").toString(),
"-sourcepath", src.toString(),
"-Xdoclint:none",
(useAuthorOption ? "-author" : "-XDdummy=dummy"),
"pkg");
checkExit(Exit.OK);
// bad tags never cause corresponding output, whether the option is enabled or not
checkAuthor(false);
checkOutput(Output.OUT, useAuthorOption,
"warning: Tag @author cannot be used in method documentation.");
}
void checkAuthor(boolean on) {
checkOutput("pkg/Test.html", on,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>anonymous</dd>
</dl>""");
}
@Test
public void testAuthorDefault(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/**
* Class C.
* @author J. Duke
*/
public class C {
/** Class Nested, with no explicit at-author. */
public class Nested { }
}""");
javadoc("-d", base.resolve("api").toString(),
"-author",
"-sourcepath", src.toString(),
"p");
checkExit(Exit.OK);
checkOutput("p/C.html", true,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>J. Duke</dd>""");
checkOutput("p/C.Nested.html", true,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>J. Duke</dd>""");
}
@Test
public void testAuthorDefault_Multiple(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/**
* Class C.
* @author J. Duke
* @author A. N. Other
*/
public class C {
/** Class Nested, with no explicit at-author. */
public class Nested { }
}""");
javadoc("-d", base.resolve("api").toString(),
"-author",
"-sourcepath", src.toString(),
"p");
checkExit(Exit.OK);
checkOutput("p/C.html", true,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>J. Duke, A. N. Other</dd>""");
checkOutput("p/C.Nested.html", true,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>J. Duke, A. N. Other</dd>""");
}
@Test
public void testAuthorDefault_Nested(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/**
* Class C.
* @author J. Duke
* @author A. N. Other
*/
public class C {
public class Nested1 {
/** Class Nested, with no explicit at-author. */
public class Nested { }
}
}""");
javadoc("-d", base.resolve("api").toString(),
"-author",
"-sourcepath", src.toString(),
"p");
checkExit(Exit.OK);
checkOutput("p/C.html", true,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>J. Duke, A. N. Other</dd>""");
checkOutput("p/C.Nested1.Nested.html", true,
"""
<dl class="notes">
<dt>Author:</dt>
<dd>J. Duke, A. N. Other</dd>""");
}
}

View file

@ -0,0 +1,236 @@
/*
* Copyright (c) 2022, 2025, 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 8289332 8286470 8309471 8345555
* @summary Auto-generate ids for user-defined headings
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.* toolbox.ToolBox
* @run main TestAutoHeaderId
*/
import java.nio.file.Path;
import toolbox.ToolBox;
import javadoc.tester.JavadocTester;
public class TestAutoHeaderId extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestAutoHeaderId();
tester.runTests();
}
private final ToolBox tb;
TestAutoHeaderId() {
tb = new ToolBox();
}
@Test
public void testAutoHeaderId(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package p;
/**
* First sentence.
*
* <h2>1.0 First Header</h2>
*
* <h3 id="fixed-id-1">1.1 Header with ID</h3>
*
* <h4><a id="fixed-id-2">Embedded A-Tag with ID</a></h4>
*
* <h5>{@code Embedded Code Tag}</h5>
*
* <h6>{@linkplain C Embedded Link Tag}</h6>
*
* <h3>Duplicate Text</h3>
*
* <h4>Duplicate Text</h4>
*
* <h2>2.0 Extra (#*!. chars</h2>
*
* <h3 style="color: red;" class="some-class">Other attributes</h3>
*
* <h4></h4>
*
* <h2> 3.0 Multi-line
* heading with extra
* whitespace</h2>
*
* Last sentence.
*/
public class C {
/** Comment. */
C() { }
}
""");
javadoc("-d", base.resolve("api").toString(),
"-sourcepath", src.toString(),
"--no-platform-links", "p");
checkIds();
checkSearchIndex();
checkHtmlIndex();
}
private void checkIds() {
checkOutput("p/C.html", true,
"""
<h2 id="1-0-first-header-heading">1.0 First Header</h2>
""",
"""
<h3 id="fixed-id-1">1.1 Header with ID</h3>
""",
"""
<h4><a id="fixed-id-2">Embedded A-Tag with ID</a></h4>
""",
"""
<h5 id="embedded-code-tag-heading"><code>Embedded Code Tag</code></h5>
""",
"""
<h6 id="embedded-link-tag-heading"><a href="C.html" title="class in p">Embedded Link Tag</a></h6>
""",
"""
<h3 id="duplicate-text-heading">Duplicate Text</h3>
""",
"""
<h4 id="duplicate-text-heading1">Duplicate Text</h4>
""",
"""
<h2 id="2-0-extra-chars-heading">2.0 Extra (#*!. chars</h2>
""",
"""
<h3 id="other-attributes-heading" style="color: red;" class="some-class">Other attributes</h3>
""",
"""
<h4 id="-heading"></h4>
""",
"""
<h2 id="3-0-multi-line-heading-with-extra-whitespace-heading"> 3.0 Multi-line
heading with extra
whitespace</h2>""");
}
private void checkSearchIndex() {
checkOutput("tag-search-index.js", true,
"""
{"l":"Duplicate Text","h":"class p.C","k":"16","u":"p/C.html#duplicate-text-heading"}""",
"""
{"l":"Duplicate Text","h":"class p.C","k":"16","u":"p/C.html#duplicate-text-heading1"}""",
"""
{"l":"Embedded A-Tag with ID","h":"class p.C","k":"16","u":"p/C.html#fixed-id-2"}""",
"""
{"l":"Embedded Code Tag","h":"class p.C","k":"16","u":"p/C.html#embedded-code-tag-heading"}""",
"""
{"l":"Embedded Link Tag","h":"class p.C","k":"16","u":"p/C.html#embedded-link-tag-heading"}""",
"""
{"l":"2.0 Extra (#*!. chars","h":"class p.C","k":"16","u":"p/C.html#2-0-extra-chars-heading"}""",
"""
{"l":"1.0 First Header","h":"class p.C","k":"16","u":"p/C.html#1-0-first-header-heading"}""",
"""
{"l":"1.1 Header with ID","h":"class p.C","k":"16","u":"p/C.html#fixed-id-1"}""",
"""
{"l":"3.0 Multi-line heading with extra whitespace","h":"class p.C","k":"16","u":"p/C.html\
#3-0-multi-line-heading-with-extra-whitespace-heading"}""",
"""
{"l":"Other attributes","h":"class p.C","k":"16","u":"p/C.html#other-attributes-heading"}""");
}
private void checkHtmlIndex() {
// Make sure section links are not included in static index pages
checkOutput("index-all.html", true,
"""
<a href="#I:C">C</a>&nbsp;<a href="#I:D">D</a>&nbsp;<a href="#I:E">E</a>&nbsp;<a href="#I\
:F">F</a>&nbsp;<a href="#I:H">H</a>&nbsp;<a href="#I:M">M</a>&nbsp;<a href="#I:O">O</a>&n\
bsp;<a href="#I:P">P</a>&nbsp;<br><a href="allclasses-index.html">All&nbsp;Classes&nbsp;a\
nd&nbsp;Interfaces</a><span class="vertical-separator">|</span><a href="allpackages-index\
.html">All&nbsp;Packages</a>
<h2 class="title" id="I:C">C</h2>
<dl class="index">
<dt><a href="p/C.html" class="type-name-link" title="class in p">C</a> - Class in <a href\
="p/package-summary.html">p</a></dt>
<dd>
<div class="block">First sentence.</div>
</dd>
</dl>
<h2 class="title" id="I:D">D</h2>
<dl class="index">
<dt><a href="p/C.html#duplicate-text-heading" class="search-tag-link">Duplicate Text</a> \
- Section in class p.C</dt>
<dd>&nbsp;</dd>
<dt><a href="p/C.html#duplicate-text-heading1" class="search-tag-link">Duplicate Text</a>\
- Section in class p.C</dt>
<dd>&nbsp;</dd>
</dl>
<h2 class="title" id="I:E">E</h2>
<dl class="index">
<dt><a href="p/C.html#2-0-extra-chars-heading" class="search-tag-link">2.0 Extra (#*!. ch\
ars</a> - Section in class p.C</dt>
<dd>&nbsp;</dd>
<dt><a href="p/C.html#fixed-id-2" class="search-tag-link">Embedded A-Tag with ID</a> - Se\
ction in class p.C</dt>
<dd>&nbsp;</dd>
<dt><a href="p/C.html#embedded-code-tag-heading" class="search-tag-link">Embedded Code Ta\
g</a> - Section in class p.C</dt>
<dd>&nbsp;</dd>
<dt><a href="p/C.html#embedded-link-tag-heading" class="search-tag-link">Embedded Link Ta\
g</a> - Section in class p.C</dt>
<dd>&nbsp;</dd>
</dl>
<h2 class="title" id="I:F">F</h2>
<dl class="index">
<dt><a href="p/C.html#1-0-first-header-heading" class="search-tag-link">1.0 First Header<\
/a> - Section in class p.C</dt>
<dd>&nbsp;</dd>
</dl>
<h2 class="title" id="I:H">H</h2>
<dl class="index">
<dt><a href="p/C.html#fixed-id-1" class="search-tag-link">1.1 Header with ID</a> - Sectio\
n in class p.C</dt>
<dd>&nbsp;</dd>
</dl>
<h2 class="title" id="I:M">M</h2>
<dl class="index">
<dt><a href="p/C.html#3-0-multi-line-heading-with-extra-whitespace-heading" class="search\
-tag-link">3.0 Multi-line heading with extra whitespace</a> - Section in class p.C</dt>
<dd>&nbsp;</dd>
</dl>
<h2 class="title" id="I:O">O</h2>
<dl class="index">
<dt><a href="p/C.html#other-attributes-heading" class="search-tag-link">Other attributes<\
/a> - Section in class p.C</dt>
<dd>&nbsp;</dd>
</dl>
<h2 class="title" id="I:P">P</h2>
<dl class="index">
<dt><a href="p/package-summary.html">p</a> - package p</dt>
<dd>&nbsp;</dd>
</dl>""");
}
}

View file

@ -0,0 +1,132 @@
/*
* Copyright (c) 2019, 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 8219958
* @summary Automatically load taglets from a jar file
* @library /tools/lib ../../lib
* @modules
* jdk.javadoc/jdk.javadoc.internal.tool
* jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* @build javadoc.tester.* toolbox.ToolBox builder.ClassBuilder toolbox.JarTask
* @run main/othervm TestAutoLoadTaglets
*/
import java.nio.file.Path;
import java.nio.file.Paths;
import builder.ClassBuilder;
import toolbox.JarTask;
import toolbox.JavacTask;
import toolbox.ToolBox;
import javadoc.tester.JavadocTester;
public class TestAutoLoadTaglets extends JavadocTester {
final ToolBox tb;
public static void main(String... args) throws Exception {
var tester = new TestAutoLoadTaglets();
tester.runTests();
}
TestAutoLoadTaglets() {
tb = new ToolBox();
}
@Test
public void test(Path base) throws Exception {
Path srcDir = base.resolve("src");
Path outDir = base.resolve("out");
createTagletsJar(base, srcDir);
new ClassBuilder(tb, "pkg.A")
.setComments("test {@taglet1} and {@taglet2}")
.setModifiers("public", "class")
.write(srcDir);
javadoc("-d", outDir.toString(),
"-sourcepath", srcDir.toString(),
"-tagletpath", "taglets.jar",
"pkg");
checkExit(Exit.OK);
checkOutput("pkg/A.html", true,
"test user taglet taglet1 and user taglet taglet2");
}
private void createTagletsJar(Path base, Path srcDir) throws Exception {
Path classes = base.resolve("classes");
tb.createDirectories(classes);
createTaglets(srcDir);
new JavacTask(tb).files(srcDir.resolve("Taglet1.java"), srcDir.resolve("Taglet2.java"))
.outdir(classes).run();
Path services = classes.resolve("META-INF").resolve("services").resolve("jdk.javadoc.doclet.Taglet");
tb.writeFile(services,
"Taglet1\n"
+ "Taglet2");
new JarTask(tb, srcDir).run("cf", "taglets.jar", "-C", classes.toString(), ".");
}
private void createTaglets(Path srcDir) throws Exception {
for (int i = 1; i < 3; i++) {
tb.writeJavaFiles(srcDir,
"""
import com.sun.source.doctree.DocTree;
import jdk.javadoc.doclet.Taglet;
import javax.lang.model.element.Element;
import java.util.List;
import java.util.Set;
public class Taglet""" + i + """
\simplements Taglet {
@Override
public Set<Location> getAllowedLocations() {
return Set.of();
}
@Override
public boolean isInlineTag() {
return true;
}
@Override
public String getName() {
return "taglet""" + i + """
";
}
@Override
public String toString(List<? extends DocTree> tags, Element element) {
return "user taglet taglet""" + i + "\";\n"
+ " }\n"
+ "}\n");
}
}
}

View file

@ -0,0 +1,7 @@
/* /nodynamiccopyright/ */
/**
* This is a comment.
*/
public class C {}

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2002, 2022, 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 4511110 8261976
* @summary Test to make sure that the link to source documentation
* has a forward slash. It would be wrong to use a back slash.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestBackSlashInLink
*/
import javadoc.tester.JavadocTester;
public class TestBackSlashInLink extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestBackSlashInLink();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"-linksource",
testSrc("C.java"));
checkExit(Exit.OK);
checkOutput("C.html", true,
"src-html/C.html#line-7");
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2017, 2022, 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 8176901
* @summary The doclet should cope with bad HTML form
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestBadHtml
*/
import javadoc.tester.JavadocTester;
public class TestBadHtml extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestBadHtml();
tester.runTests();
}
@Test
public void testNegative() {
javadoc("-d", "out1",
"-sourcepath", testSrc,
"pkg1");
checkExit(Exit.ERROR);
checkOutput(Output.STDERR, false, "NullPointerException");
checkOutput(Output.OUT, false, "NullPointerException");
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2017, 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.
*/
package pkg1;
/**
* The first sentence.
* <parameters the word action is crucial here object>
* <parameters the word cite is crucial here object>
* <parameters the word classid is crucial here object>
* <parameters the word codebase is crucial here object>
* <parameters the word data is crucial here object>
* <parameters the word datasrc is crucial here object>
* <parameters the word for is crucial here object>
* <parameters the word href is crucial here object>
* <parameters the word longdesc is crucial here object>
* <parameters the word profile is crucial here object>
* <parameters the word src is crucial here object>
* <parameters the word usemap is crucial here object>
*/
public class A {}

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2002, 2022, 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 4691095 6306394
* @summary Make sure that Javadoc emits a useful warning
* when a bad package.html exists in a JAR archive.
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.* toolbox.ToolBox toolbox.JarTask
* @run main TestBadPackageFileInJar
*/
import toolbox.JarTask;
import toolbox.Task.Result;
import toolbox.ToolBox;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import javadoc.tester.JavadocTester;
public class TestBadPackageFileInJar extends JavadocTester {
final ToolBox tb = new ToolBox();
public static void main(String... args) throws Exception {
var tester = new TestBadPackageFileInJar();
tester.runTests();
}
@Test
public void test() throws IOException {
// create the file
Path pkgDir = Paths.get("pkg");
tb.createDirectories(pkgDir);
Path pkgfilePath = pkgDir.resolve("package.html");
tb.writeFile(pkgfilePath, "<html>\n\n</html>");
// create the jar file
Path jarFile = Paths.get("badPackageFileInJar.jar");
JarTask jar = new JarTask(tb, "badPackageFileInJar.jar");
jar.files(pkgDir.toString()).run();
// clean up to prevent accidental pick up
tb.cleanDirectory(pkgDir);
tb.deleteFiles(pkgDir.toString());
javadoc("-d", "out",
"-sourcepath", testSrc,
"-classpath", jarFile.toString(),
"pkg");
checkExit(Exit.OK);
checkOutput(Output.OUT, true,
"badPackageFileInJar.jar(/pkg/package.html):1: warning: no comment");
}
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2002, 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.
*/
package pkg;
public class C {}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2003, 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.
*/
package com.package1;
/**
* This is a comment.
*/
public class C1 {
public void foo(int p) {}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2003, 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.
*/
/**
* @see C1#foo(int)
*/
public class C2 {}

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2003, 2022, 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 4835749
* @summary Make sure exception is not thrown if there is a bad source
* file in the same directory as the file being documented.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestBadSourceFile
*/
import javadoc.tester.JavadocTester;
public class TestBadSourceFile extends JavadocTester {
/**
* The entry point of the test.
* @param args the array of command line arguments
* @throws Exception if the test fails
*/
public static void main(String... args) throws Exception {
var tester = new TestBadSourceFile();
tester.runTests();
}
@Test
public void test() {
javadoc("-Xdoclint:none",
"-d", "out",
testSrc("C2.java"));
checkExit(Exit.ERROR);
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
import baz.*;
/** First line of comments for Bar
* Second line of comments for Bar
*/
public class Bar extends Foo {
/**
* A public method.
*/
public void aPublicMethod(){}
/**
* A protected method.
*/
protected void aProtectedMethod(){}
/**
* A private method.
*/
private void aPrivateMethod(){}
/**
* A package protected method.
*/
void aPackagePrivateMethod(){}
} // end class Bar

View file

@ -0,0 +1,131 @@
/*
* Copyright (c) 1999, 2019, 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.
*/
/**
* Regression test for:
* Javadoc does not process base class. If user specifies few classes on the
* command line and few packages, with a situation where one of the specified
* classes(on the command line) extends a class from one of the packages, then
* due to some anomaly in ordering in which all the class and package objects
* get constructed, few classes were getting marked as "not included", even
* thought they were included in this run and hence documentation for those
* packages was wrong. The test case for which javadoc was failing is given
* in bug# 4197513.
*
* @bug 4197513
* @summary Javadoc does not process base class.
* @build BaseClass.java
*/
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import jdk.javadoc.doclet.*;
public class BaseClass implements Doclet {
public boolean run(DocletEnvironment root) {
Elements elementUtils = root.getElementUtils();
TypeElement klass = elementUtils.getTypeElement("baz.Foo");
if (!root.isIncluded(klass)) {
throw new AssertionError("Base class is not included: baz.Foo");
}
for (TypeElement te : ElementFilter.typesIn(root.getSpecifiedElements())) {
if (te.getKind() == ElementKind.CLASS &&
te.getSimpleName().contentEquals("Bar")) {
klass = te;
}
}
if (klass == null) {
throw new AssertionError("class Bar not found");
}
List<? extends Element> members = klass.getEnclosedElements();
boolean foundPublic = false;
boolean foundProtected = false;
boolean foundPackagePrivate = false;
boolean foundPrivate = false;
List<Element> included = members.stream()
.filter(cls -> root.isIncluded(cls))
.collect(Collectors.toList());
for (Element e : included) {
System.out.println("element: " + e);
if (e.getSimpleName().toString().equals("aPublicMethod")) {
foundPublic = true;
}
if (e.getSimpleName().toString().equals("aProtectedMethod")) {
foundProtected = true;
}
if (e.getSimpleName().toString().equals("aPackagePrivateMethod")) {
foundPackagePrivate = true;
}
if (e.getSimpleName().toString().equals("aPackagePrivateMethod")) {
foundPrivate = true;
}
}
if (!foundPublic || !foundProtected) {
throw new AssertionError("selected methods not found");
}
if (foundPrivate || foundPackagePrivate) {
throw new AssertionError("unselected methods found");
}
return true;
}
public Set<Doclet.Option> getSupportedOptions() {
return Collections.emptySet();
}
public void init(Locale locale, Reporter reporter) {
return;
}
@Override
public String getName() {
return "BaseClass";
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2002, 2022, 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 4197513
* @summary Javadoc does not process base class.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build BaseClass
* @build javadoc.tester.*
* @run main TestBaseClass
*/
import javadoc.tester.JavadocTester;
public class TestBaseClass extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestBaseClass();
tester.runTests();
}
@Test
public void test() {
javadoc("-sourcepath", testSrc,
"-docletpath", System.getProperty("test.classes", "."),
"-doclet", "BaseClass",
testSrc("Bar.java"), "baz");
checkExit(Exit.OK);
}
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2002, 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.
*/
package baz;
public class Foo {}

View file

@ -0,0 +1,152 @@
/*
* Copyright (c) 2018, 2022, 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 8202947
* @summary Test bimodal (inline and block) taglets
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestBimodalTaglets
*/
import java.nio.file.Path;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.UnknownBlockTagTree;
import com.sun.source.doctree.UnknownInlineTagTree;
import javadoc.tester.JavadocTester;
import jdk.javadoc.doclet.Taglet;
import toolbox.ToolBox;
public class TestBimodalTaglets extends JavadocTester implements Taglet {
public static void main(String... args) throws Exception {
new TestBimodalTaglets().runTests();
}
ToolBox tb = new ToolBox();
@Test
public void testBimodalTaglet(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"package p;\n"
+ comment("This is a comment.",
"Here is an inline {@test abc} test tag {@test def}.",
"@see Object",
"@test 123",
"@see String",
"@test 456")
+ "public class C { }\n");
javadoc("-d", base.resolve("out").toString(),
"--source-path", src.toString(),
"-tagletpath", System.getProperty("test.class.path"),
"-taglet", "TestBimodalTaglets",
"p");
checkOutput("p/C.html", true,
"Here is an inline INLINE[abc] test tag INLINE[def].",
"<dt>BLOCK:<dd>123<dd>456");
}
String comment(String... lines) {
return Arrays.stream(lines)
.collect(Collectors.joining("\n * ", "/**\n * ", "\n */"));
}
// the taglet ....
@Override
public Set<Location> getAllowedLocations() {
return EnumSet.allOf(Location.class);
}
@Override
public boolean isInlineTag() {
return true;
}
@Override
public boolean isBlockTag() {
return true;
}
@Override
public String getName() {
return "test";
}
@Override
public String toString(List<? extends DocTree> tags, Element element) {
if (tags.size() == 1 && tags.get(0) instanceof UnknownInlineTagTree) {
return inlineTagToString((UnknownInlineTagTree) tags.get(0));
} else {
return blockTagsToString(tags);
}
}
/**
* Converts an inline tag to a string composed of its contents wrapped in "INLINE[" ... "]"
*
* @param tag the tag
* @return the string
*/
private String inlineTagToString(UnknownInlineTagTree tag) {
return "INLINE[" +
toString(tag.getContent())
+ "]";
}
/**
* Converts a series of block tags to a string composed of a {@code> <dt>} header,
* followed by the contents of each tag preceded by {@code <dd>}.
* Note that the doclet provides the enclosing {@code <dl>...</dl>} around all the
* block tags.
*
* @param tags the tags
* @return the string
*/
private String blockTagsToString(List<? extends DocTree> tags) {
return "<dt>BLOCK:"
+ tags.stream()
.map (t -> (UnknownBlockTagTree) t)
.map(t -> "<dd>" + toString(t.getContent()))
.collect(Collectors.joining());
}
private String toString(List<? extends DocTree> trees) {
return trees.stream()
.map(Object::toString)
.collect(Collectors.joining());
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2002, 2025, 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 4165985 8326332
* @summary Determine the end of the first sentence using BreakIterator.
* If the first sentence of "method" is parsed correctly, the test passes.
* Correct Answer: "This is a class (i.e. it is indeed a class)."
* Wrong Answer: "This is a class (i.e."
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestBreakIterator
*/
import javadoc.tester.JavadocTester;
public class TestBreakIterator extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestBreakIterator();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-sourcepath", testSrc,
"-breakiterator",
"pkg");
checkExit(Exit.OK);
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">This is a class (i.e. it is indeed a class).</div>""");
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">tests the breakiterator (i.e. how the firstSentence is broken up).</div>""");
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">with an inline tag <code>jdk.javadoc.taglet.Taglet</code> does it work.</div>""");
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">with a block tag</div>""");
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">with an anchor for the
<a href="../index-all.html">top level index</a>.</div>""");
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">A constant indicating that the keyLocation is indeterminate
or not relevant.</div>""");
checkOutput("pkg/BreakIteratorTest.html", true,
"""
<div class="block">Inline tags <i><a href="../index-all.html">extending
beyond the first sentence.</a></i></div>""");
}
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2001, 2024, 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.
*/
package pkg;
/**
* This is a class (i.e. it is indeed a class).
*/
public class BreakIteratorTest {
/**
* tests the breakiterator (i.e. how the firstSentence is broken up). Second sentence.
*/
public void foo(){}
/**
* with an inline tag <code>jdk.javadoc.taglet.Taglet</code> does it work. Second line.
*/
public void bar(){}
/**
* with a block tag <p> does it work. Second line.
*/
public void baz(){}
/**
* with an anchor for the
* <a href="{@docRoot}/index-all.html">top level index</a>. Second line.
*/
public void foobar(){}
/**
* A constant indicating that the keyLocation is indeterminate
* or not relevant.
* <code>KEY_TYPED</code> events do not have a keyLocation; this value
* is used instead.
*/
public void fe(){}
/**
* Inline tags <i><a href="{@docRoot}/index-all.html">extending
* beyond the first sentence. Tags are closed here.</a></i>
*/
public void meh(){}
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2004, 2025, 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 4979486
* @summary Make sure tool parses CR line separators properly.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestCRLineSeparator
*/
import java.io.*;
import java.util.*;
import javadoc.tester.JavadocTester;
public class TestCRLineSeparator extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestCRLineSeparator();
tester.runTests();
}
@Test
public void test() throws IOException {
initFiles(new File(testSrc), new File("src"), "pkg");
javadoc("-d", "out",
"-sourcepath", "src",
"pkg");
checkExit(Exit.OK);
checkOutput("pkg/MyClass.html", true,
"Line 1\n"
+ "Line 2");
}
// recursively copy files from fromDir to toDir, replacing newlines
// with \r
void initFiles(File fromDir, File toDir, String f) throws IOException {
File from_f = new File(fromDir, f);
File to_f = new File(toDir, f);
if (from_f.isDirectory()) {
to_f.mkdirs();
for (String child: from_f.list()) {
initFiles(from_f, to_f, child);
}
} else {
List<String> lines = new ArrayList<>();
try (BufferedReader in = new BufferedReader(new FileReader(from_f))) {
String line;
while ((line = in.readLine()) != null)
lines.add(line);
}
try (BufferedWriter out = new BufferedWriter(new FileWriter(to_f))) {
for (String line: lines) {
out.write(line);
out.write("\r");
}
}
}
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004, 2009, 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.
*/
package pkg;
/**
* Line 1
* Line 2
*/
public class MyClass {}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 2013, 2022, 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 7052170 8047745
* @summary Run a test on -charset to make sure the charset gets generated as a
* part of the meta tag.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestCharset
*/
import javadoc.tester.JavadocTester;
public class TestCharset extends JavadocTester {
public static void main(String... args) throws Exception {
var tester = new TestCharset();
tester.runTests();
}
@Test
public void test() {
javadoc("-d", "out",
"-charset", "ISO-8859-1",
"-sourcepath", testSrc,
"pkg");
checkExit(Exit.OK);
checkOutput("index.html", true,
"""
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">""");
checkOutput("pkg/Foo.html", true,
"""
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">""");
checkOutput("index.html", false,
"""
<meta http-equiv="Content-Type" content="text/html" charset="ISO-8859-1">""");
checkOutput("pkg/Foo.html", false,
"""
<meta http-equiv="Content-Type" content="text/html" charset="ISO-8859-1">""");
}
@Test
public void test1() {
javadoc("-d", "out-1",
"-sourcepath", testSrc,
"pkg");
checkExit(Exit.OK);
checkOutput("index.html", true,
"""
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">""");
checkOutput("pkg/Foo.html", true,
"""
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">""");
}
}

Some files were not shown because too many files have changed in this diff Show more