From a32527133cbc0629ab1fb94f698d936a21f55d90 Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Wed, 2 Aug 2023 00:47:20 +0000 Subject: [PATCH 01/12] 8312814: Compiler crash when template processor type is a captured wildcard Reviewed-by: jlahoda, mcimadamore, vromero --- .../com/sun/tools/javac/comp/TransTypes.java | 1 + .../tools/javac/template/T8312814.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/langtools/tools/javac/template/T8312814.java diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java index 4d1747c7389..36d3a2b24bd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java @@ -838,6 +838,7 @@ else if (tree.sym.kind == VAR) { } public void visitStringTemplate(JCStringTemplate tree) { + tree.processor = translate(tree.processor, erasure(tree.processor.type)); tree.expressions = tree.expressions.stream() .map(e -> translate(e, erasure(e.type))).collect(List.collector()); tree.type = erasure(tree.type); diff --git a/test/langtools/tools/javac/template/T8312814.java b/test/langtools/tools/javac/template/T8312814.java new file mode 100644 index 00000000000..15207828a7d --- /dev/null +++ b/test/langtools/tools/javac/template/T8312814.java @@ -0,0 +1,39 @@ +/* + * 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 T8312814 + * @summary Verify proper behavior of TransType w.r.t. templated Strings + * @enablePreview + * @compile T8312814.java + */ + + +import java.util.List; + +public class T8312814 { + void x(List> list) { + list.get(0).""; + } +} + From 678f67644bdb939792df8b50c49cf04559fcdd74 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Wed, 2 Aug 2023 01:37:40 +0000 Subject: [PATCH 02/12] 8310991: missing @since tags in java.xml Reviewed-by: iris, naoto, lancea --- src/java.xml/share/classes/org/w3c/dom/Attr.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/CDATASection.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/CharacterData.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Comment.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/DOMException.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/DOMImplementation.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Document.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/DocumentFragment.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/DocumentType.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Element.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Entity.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/EntityReference.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/NamedNodeMap.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Node.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/NodeList.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Notation.java | 2 ++ .../share/classes/org/w3c/dom/ProcessingInstruction.java | 2 ++ src/java.xml/share/classes/org/w3c/dom/Text.java | 2 ++ 18 files changed, 36 insertions(+) diff --git a/src/java.xml/share/classes/org/w3c/dom/Attr.java b/src/java.xml/share/classes/org/w3c/dom/Attr.java index 7f3d196d461..54d0997eb38 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Attr.java +++ b/src/java.xml/share/classes/org/w3c/dom/Attr.java @@ -187,6 +187,8 @@ * * *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Attr extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/CDATASection.java b/src/java.xml/share/classes/org/w3c/dom/CDATASection.java index f973003d268..25eb0cd3064 100644 --- a/src/java.xml/share/classes/org/w3c/dom/CDATASection.java +++ b/src/java.xml/share/classes/org/w3c/dom/CDATASection.java @@ -78,6 +78,8 @@ * exception when a character is missing from the encoding, making the task * of ensuring that data is not corrupted on serialization more difficult. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface CDATASection extends Text { } diff --git a/src/java.xml/share/classes/org/w3c/dom/CharacterData.java b/src/java.xml/share/classes/org/w3c/dom/CharacterData.java index 46618c88322..0a70c3b700b 100644 --- a/src/java.xml/share/classes/org/w3c/dom/CharacterData.java +++ b/src/java.xml/share/classes/org/w3c/dom/CharacterData.java @@ -54,6 +54,8 @@ * the following, the term 16-bit units is used whenever necessary to * indicate that indexing on CharacterData is done in 16-bit units. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface CharacterData extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Comment.java b/src/java.xml/share/classes/org/w3c/dom/Comment.java index 61bb67d4ae0..14cb3e1a999 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Comment.java +++ b/src/java.xml/share/classes/org/w3c/dom/Comment.java @@ -54,6 +54,8 @@ * presence of this character sequence must generate a fatal error during * serialization. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Comment extends CharacterData { } diff --git a/src/java.xml/share/classes/org/w3c/dom/DOMException.java b/src/java.xml/share/classes/org/w3c/dom/DOMException.java index 679c6a7c363..b49351ba621 100644 --- a/src/java.xml/share/classes/org/w3c/dom/DOMException.java +++ b/src/java.xml/share/classes/org/w3c/dom/DOMException.java @@ -58,6 +58,8 @@ * methods may return error codes similar to those listed in the * corresponding method descriptions. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public class DOMException extends RuntimeException { public DOMException(short code, String message) { diff --git a/src/java.xml/share/classes/org/w3c/dom/DOMImplementation.java b/src/java.xml/share/classes/org/w3c/dom/DOMImplementation.java index 2bcd5f7d39c..2760c1f1f12 100644 --- a/src/java.xml/share/classes/org/w3c/dom/DOMImplementation.java +++ b/src/java.xml/share/classes/org/w3c/dom/DOMImplementation.java @@ -46,6 +46,8 @@ * for performing operations that are independent of any particular instance * of the document object model. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface DOMImplementation { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Document.java b/src/java.xml/share/classes/org/w3c/dom/Document.java index df10e9d9ae5..e253aec8273 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Document.java +++ b/src/java.xml/share/classes/org/w3c/dom/Document.java @@ -52,6 +52,8 @@ * ownerDocument attribute which associates them with the * Document within whose context they were created. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Document extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/DocumentFragment.java b/src/java.xml/share/classes/org/w3c/dom/DocumentFragment.java index 01c35ef289c..9bffa92ec16 100644 --- a/src/java.xml/share/classes/org/w3c/dom/DocumentFragment.java +++ b/src/java.xml/share/classes/org/w3c/dom/DocumentFragment.java @@ -77,6 +77,8 @@ * interface, such as Node.insertBefore and * Node.appendChild. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface DocumentFragment extends Node { } diff --git a/src/java.xml/share/classes/org/w3c/dom/DocumentType.java b/src/java.xml/share/classes/org/w3c/dom/DocumentType.java index b28bea811b6..75d9c4d9279 100644 --- a/src/java.xml/share/classes/org/w3c/dom/DocumentType.java +++ b/src/java.xml/share/classes/org/w3c/dom/DocumentType.java @@ -51,6 +51,8 @@ *

DOM Level 3 doesn't support editing DocumentType nodes. * DocumentType nodes are read-only. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface DocumentType extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Element.java b/src/java.xml/share/classes/org/w3c/dom/Element.java index ab5087d2c52..142d88490e9 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Element.java +++ b/src/java.xml/share/classes/org/w3c/dom/Element.java @@ -57,6 +57,8 @@ *

Note: In DOM Level 2, the method normalize is * inherited from the Node interface where it was moved. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Element extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Entity.java b/src/java.xml/share/classes/org/w3c/dom/Entity.java index c4e3b8930c7..6007e715e83 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Entity.java +++ b/src/java.xml/share/classes/org/w3c/dom/Entity.java @@ -71,6 +71,8 @@ * they are created using the createEntityReference method of * the Document interface. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Entity extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/EntityReference.java b/src/java.xml/share/classes/org/w3c/dom/EntityReference.java index 65aade6acde..7ae786a5c2d 100644 --- a/src/java.xml/share/classes/org/w3c/dom/EntityReference.java +++ b/src/java.xml/share/classes/org/w3c/dom/EntityReference.java @@ -67,6 +67,8 @@ * 1.0 and XML Schema, the normalization is performed after entity reference * are expanded. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface EntityReference extends Node { } diff --git a/src/java.xml/share/classes/org/w3c/dom/NamedNodeMap.java b/src/java.xml/share/classes/org/w3c/dom/NamedNodeMap.java index c9d3084f151..23a4bed25ed 100644 --- a/src/java.xml/share/classes/org/w3c/dom/NamedNodeMap.java +++ b/src/java.xml/share/classes/org/w3c/dom/NamedNodeMap.java @@ -52,6 +52,8 @@ * and does not imply that the DOM specifies an order to these Nodes. *

NamedNodeMap objects in the DOM are live. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface NamedNodeMap { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Node.java b/src/java.xml/share/classes/org/w3c/dom/Node.java index 2ba7fc12564..244ba3fba59 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Node.java +++ b/src/java.xml/share/classes/org/w3c/dom/Node.java @@ -166,6 +166,8 @@ * * *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Node { // NodeType diff --git a/src/java.xml/share/classes/org/w3c/dom/NodeList.java b/src/java.xml/share/classes/org/w3c/dom/NodeList.java index 20521f1f3f3..5381cd46fc0 100644 --- a/src/java.xml/share/classes/org/w3c/dom/NodeList.java +++ b/src/java.xml/share/classes/org/w3c/dom/NodeList.java @@ -48,6 +48,8 @@ *

The items in the NodeList are accessible via an integral * index, starting from 0. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface NodeList { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Notation.java b/src/java.xml/share/classes/org/w3c/dom/Notation.java index 3b5db96e118..10e6385970c 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Notation.java +++ b/src/java.xml/share/classes/org/w3c/dom/Notation.java @@ -51,6 +51,8 @@ * are therefore readonly. *

A Notation node does not have any parent. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Notation extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/ProcessingInstruction.java b/src/java.xml/share/classes/org/w3c/dom/ProcessingInstruction.java index a8ee739d388..d6a9ec30d12 100644 --- a/src/java.xml/share/classes/org/w3c/dom/ProcessingInstruction.java +++ b/src/java.xml/share/classes/org/w3c/dom/ProcessingInstruction.java @@ -52,6 +52,8 @@ * presence of this character sequence must generate a fatal error during * serialization. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface ProcessingInstruction extends Node { /** diff --git a/src/java.xml/share/classes/org/w3c/dom/Text.java b/src/java.xml/share/classes/org/w3c/dom/Text.java index c603dac3ead..b10b308d85b 100644 --- a/src/java.xml/share/classes/org/w3c/dom/Text.java +++ b/src/java.xml/share/classes/org/w3c/dom/Text.java @@ -65,6 +65,8 @@ * the quotation mark character " or the apostrophe character ' when part of * an attribute. *

See also the Document Object Model (DOM) Level 3 Core Specification. + * + * @since 1.4, DOM Level 2 */ public interface Text extends CharacterData { /** From 440327491f0da2d3fc3c3be684be335efc195451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jeli=C5=84ski?= Date: Wed, 2 Aug 2023 05:45:24 +0000 Subject: [PATCH 03/12] 8313507: Remove pkcs11/Cipher/TestKATForGCM.java from ProblemList Reviewed-by: mullan --- test/jdk/ProblemList.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index cc0680d07b3..e8aae25f5e0 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -609,8 +609,6 @@ sun/security/pkcs11/rsa/TestSignatures.java 8295343 linux-al sun/security/pkcs11/rsa/TestKeyPairGenerator.java 8295343 linux-all sun/security/pkcs11/rsa/TestKeyFactory.java 8295343 linux-all sun/security/pkcs11/KeyStore/Basic.java 8295343 linux-all -sun/security/pkcs11/Cipher/TestKATForGCM.java 8240611 linux-x64,macosx-x64 - ############################################################################ From bd7ff4a2cd416a51475c27919ca199c96f367064 Mon Sep 17 00:00:00 2001 From: Jenny Shivayogi Date: Wed, 2 Aug 2023 07:00:13 +0000 Subject: [PATCH 04/12] 8311821: Simplify ParallelGCThreadsConstraintFunc after CMS removal Reviewed-by: kbarrett, shade, tschatzl --- .../hotspot/jtreg/gc/arguments/TestParallelGCThreads.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java b/test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java index be8c6494b54..6e447f455cf 100644 --- a/test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java +++ b/test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java @@ -113,14 +113,14 @@ public static void testFlags() throws Exception { } } - // 4294967295 == (unsigned int) -1 - // So setting ParallelGCThreads=4294967295 should give back 4294967295 + // Test the max value for ParallelGCThreads + // So setting ParallelGCThreads=2147483647 should give back 2147483647 long count = getParallelGCThreadCount( "-XX:+UseSerialGC", - "-XX:ParallelGCThreads=4294967295", + "-XX:ParallelGCThreads=2147483647", "-XX:+PrintFlagsFinal", "-version"); - Asserts.assertEQ(count, 4294967295L, "Specifying ParallelGCThreads=4294967295 does not set the thread count properly!"); + Asserts.assertEQ(count, 2147483647L, "Specifying ParallelGCThreads=2147483647 does not set the thread count properly!"); } public static long getParallelGCThreadCount(String... flags) throws Exception { From 3dbc460f60b8d96863f6c7c94b5c706300853796 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 2 Aug 2023 07:00:37 +0000 Subject: [PATCH 05/12] 8312591: GCC 6 build failure after JDK-8280982 Reviewed-by: jiefu, prr --- make/modules/java.desktop/lib/Awt2dLibraries.gmk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/make/modules/java.desktop/lib/Awt2dLibraries.gmk b/make/modules/java.desktop/lib/Awt2dLibraries.gmk index a1ba92ba23f..86ed069e345 100644 --- a/make/modules/java.desktop/lib/Awt2dLibraries.gmk +++ b/make/modules/java.desktop/lib/Awt2dLibraries.gmk @@ -245,6 +245,8 @@ ifeq ($(call isTargetOs, windows macosx), false) DISABLED_WARNINGS_gcc_gtk3_interface.c := parentheses type-limits unused-function, \ DISABLED_WARNINGS_gcc_OGLBufImgOps.c := format-nonliteral, \ DISABLED_WARNINGS_gcc_OGLPaints.c := format-nonliteral, \ + DISABLED_WARNINGS_gcc_screencast_pipewire.c := undef, \ + DISABLED_WARNINGS_gcc_screencast_portal.c := undef, \ DISABLED_WARNINGS_gcc_sun_awt_X11_GtkFileDialogPeer.c := parentheses, \ DISABLED_WARNINGS_gcc_X11SurfaceData.c := implicit-fallthrough pointer-to-int-cast, \ DISABLED_WARNINGS_gcc_XlibWrapper.c := type-limits pointer-to-int-cast, \ From c732492fa1d07a28e1ce26549d504444bf263038 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Wed, 2 Aug 2023 10:40:25 +0000 Subject: [PATCH 06/12] 8311989: Test java/lang/Thread/virtual/Reflection.java timed out Reviewed-by: jpai, mchung --- .../java/lang/Thread/virtual/Reflection.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/jdk/java/lang/Thread/virtual/Reflection.java b/test/jdk/java/lang/Thread/virtual/Reflection.java index bfca37a5e43..4dd34e6c726 100644 --- a/test/jdk/java/lang/Thread/virtual/Reflection.java +++ b/test/jdk/java/lang/Thread/virtual/Reflection.java @@ -32,6 +32,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; @@ -146,15 +147,19 @@ void testInvokeStatic6() throws Exception { try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) { Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler); ThreadFactory factory = builder.factory(); + + var ready = new CountDownLatch(1); Thread vthread = factory.newThread(() -> { + ready.countDown(); try { parkMethod.invoke(null); // blocks } catch (Exception e) { } }); vthread.start(); + try { - // give thread time to be scheduled - Thread.sleep(100); + // wait for thread to run + ready.await(); // unpark with another virtual thread, runs on same carrier thread Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread)); @@ -321,17 +326,27 @@ void testNewInstance6() throws Exception { try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) { Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler); ThreadFactory factory = builder.factory(); + + var ready = new CountDownLatch(1); Thread vthread = factory.newThread(() -> { + ready.countDown(); try { ctor.newInstance(); } catch (Exception e) { } }); vthread.start(); - Thread.sleep(100); // give thread time to be scheduled + try { + // wait for thread to run + ready.await(); - // unpark with another virtual thread, runs on same carrier thread - factory.newThread(() -> LockSupport.unpark(vthread)).start(); + // unpark with another virtual thread, runs on same carrier thread + Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread)); + unparker.start(); + unparker.join(); + } finally { + LockSupport.unpark(vthread); // in case test fails + } } } From d19efcad2d0f3d1b73c79416c8be97d66b846931 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 2 Aug 2023 11:21:34 +0000 Subject: [PATCH 07/12] 8313402: C1: Incorrect LoadIndexed value numbering Reviewed-by: phh, thartmann --- .../compiler/c1/TestLoadIndexedMismatch.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/c1/TestLoadIndexedMismatch.java diff --git a/test/hotspot/jtreg/compiler/c1/TestLoadIndexedMismatch.java b/test/hotspot/jtreg/compiler/c1/TestLoadIndexedMismatch.java new file mode 100644 index 00000000000..d16b6b0c684 --- /dev/null +++ b/test/hotspot/jtreg/compiler/c1/TestLoadIndexedMismatch.java @@ -0,0 +1,58 @@ +/* + * Copyright Amazon.com Inc. 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 8313402 + * @summary C1: Incorrect LoadIndexed value numbering + * @requires vm.compiler1.enabled + * @library /compiler/patches /test/lib + * @build java.base/java.lang.Helper + * @run main/othervm -Xbatch -XX:CompileThreshold=100 + * -XX:TieredStopAtLevel=1 + * compiler.c1.TestLoadIndexedMismatch + */ + +package compiler.c1; + +public class TestLoadIndexedMismatch { + static final byte[] ARR = {42, 42}; + static final char EXPECTED_CHAR = (char)(42*256 + 42); + + public static char work() { + // LoadIndexed (B) + byte b = ARR[0]; + // StringUTF16.charAt intrinsic, LoadIndexed (C) + char c = Helper.charAt(ARR, 0); + return c; + } + + public static void main(String[] args) { + for (int i = 0; i < 10_000; i++) { + char c = work(); + if (c != EXPECTED_CHAR) { + throw new IllegalStateException("Read: " + (int)c + ", expected: " + (int)EXPECTED_CHAR); + } + } + } +} From da6848abc534c5f43b1d01828e7cab5920732b04 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Wed, 2 Aug 2023 15:25:59 +0000 Subject: [PATCH 08/12] 8313368: (fc) FileChannel.size returns 0 on block special files Reviewed-by: vtewari, alanb --- .../unix/native/libnio/ch/UnixFileDispatcherImpl.c | 7 ++++++- .../java/nio/channels/FileChannel/BlockDeviceSize.java | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c b/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c index 37412e1e5f8..a24f0503e55 100644 --- a/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c +++ b/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c @@ -45,6 +45,11 @@ #define fstatvfs64 fstatvfs #endif +#if defined(__linux__) +#include +#include +#endif + #include "jni.h" #include "nio.h" #include "nio_util.h" @@ -169,7 +174,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject if (fstat64(fd, &fbuf) < 0) return handle(env, -1, "Size failed"); -#ifdef BLKGETSIZE64 +#if defined(__linux__) if (S_ISBLK(fbuf.st_mode)) { uint64_t size; if (ioctl(fd, BLKGETSIZE64, &size) < 0) diff --git a/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java b/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java index 496312256be..db3c042275f 100644 --- a/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java +++ b/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -22,9 +22,10 @@ */ /* @test - * @bug 8054029 + * @bug 8054029 8313368 * @requires (os.family == "linux") * @summary Block devices should not report size=0 on Linux + * @run main/manual BlockDeviceSize */ import java.io.RandomAccessFile; @@ -56,8 +57,8 @@ public static void main(String[] args) throws Throwable { System.err.println("File " + BLK_FNAME + " not found." + " Skipping test"); } catch (AccessDeniedException ade) { - System.err.println("Access to " + BLK_FNAME + " is denied." + - " Run test as root."); + throw new RuntimeException("Access to " + BLK_FNAME + " is denied." + + " Run test as root.", ade); } } } From 4f0d8fe51af9e1f3c5f973bf68155bfc7048e16e Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Wed, 2 Aug 2023 17:11:22 +0000 Subject: [PATCH 09/12] 8306582: Remove MetaspaceShared::exit_after_static_dump() Reviewed-by: iklam, alanb, ccheung --- src/java.base/share/native/libjli/java.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/native/libjli/java.c b/src/java.base/share/native/libjli/java.c index ce99c181dee..2f9d0718e93 100644 --- a/src/java.base/share/native/libjli/java.c +++ b/src/java.base/share/native/libjli/java.c @@ -85,6 +85,7 @@ static jboolean _is_java_args = JNI_FALSE; static jboolean _have_classpath = JNI_FALSE; static const char *_fVersion; static jboolean _wc_enabled = JNI_FALSE; +static jboolean dumpSharedSpaces = JNI_FALSE; /* -Xshare:dump */ /* * Entries for splash screen environment variables. @@ -455,6 +456,14 @@ JavaMain(void* _args) LEAVE(); } + /* + * -Xshare:dump does not have a main class so the VM can safely exit now + */ + if (dumpSharedSpaces) { + CHECK_EXCEPTION_LEAVE(1); + LEAVE(); + } + /* If the user specified neither a class name nor a JAR file */ if (printXUsage || printUsage || what == 0 || mode == LM_UNKNOWN) { PrintUsage(env, printXUsage); @@ -1432,6 +1441,13 @@ ParseArguments(int *pargc, char ***pargv, } AddOption(arg, NULL); } + + /* + * Check for CDS option + */ + if (JLI_StrCmp(arg, "-Xshare:dump") == 0) { + dumpSharedSpaces = JNI_TRUE; + } } if (*pwhat == NULL && --argc >= 0) { @@ -1440,7 +1456,7 @@ ParseArguments(int *pargc, char ***pargv, if (*pwhat == NULL) { /* LM_UNKNOWN okay for options that exit */ - if (!listModules && !describeModule && !validateModules) { + if (!listModules && !describeModule && !validateModules && !dumpSharedSpaces) { *pret = 1; } } else if (mode == LM_UNKNOWN) { From 68db15b3e4a6e48e8efd35c20bc5e57a8bcfa6d2 Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Wed, 2 Aug 2023 21:01:44 +0000 Subject: [PATCH 10/12] 8312821: Javac accepts char literal as template Reviewed-by: jlahoda --- .../sun/tools/javac/parser/JavaTokenizer.java | 32 +++++++++++++------ .../tools/javac/lexer/JavaLexerTest.java | 3 +- .../tools/javac/unicode/TripleQuote.out | 6 ++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index 6f6c3a192e8..4e0754869cd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -425,9 +425,10 @@ private void scanEmbeddedExpression(int pos, int endPos) { * escape character. Actual conversion of escape sequences takes place * during at the end of readToken. * - * @param pos position of the first character in literal. + * @param pos position of the first character in literal. + * @param isString true if is a string literal */ - private void scanLitChar(int pos) { + private void scanLitChar(int pos, boolean isString) { int backslash = position(); if (acceptThenPut('\\')) { hasEscapeSequences = true; @@ -480,9 +481,13 @@ private void scanLitChar(int pos) { break; case '{': - scanEmbeddedExpression(pos, backslash); - if (hasStringTemplateErrors) { - return; + if (isString) { + scanEmbeddedExpression(pos, backslash); + if (hasStringTemplateErrors) { + return; + } + } else { + lexError(position(), Errors.IllegalEscChar); } break; @@ -546,7 +551,7 @@ private void scanString(int pos) { } } else { // Add character to string buffer. - scanLitChar(pos); + scanLitChar(pos, true); } } } else { @@ -570,7 +575,7 @@ private void scanString(int pos) { break; } else { // Add character to string buffer. - scanLitChar(pos); + scanLitChar(pos, true); } } } @@ -1115,10 +1120,17 @@ public Token readToken() { lexError(pos, Errors.IllegalLineEndInCharLit); } - int errorPos = position(); - scanLitChar(pos); + scanLitChar(pos, false); - if (accept('\'')) { + if (tk == TokenKind.ERROR) { + while (isAvailable() && !is('\'')) { + if (is('\\')) { + next(); + } + next(); + } + accept('\''); + } else if (accept('\'')) { tk = TokenKind.CHARLITERAL; } else { lexError(pos, Errors.UnclosedCharLit); diff --git a/test/langtools/tools/javac/lexer/JavaLexerTest.java b/test/langtools/tools/javac/lexer/JavaLexerTest.java index 52d76b0b552..cdb6049c823 100644 --- a/test/langtools/tools/javac/lexer/JavaLexerTest.java +++ b/test/langtools/tools/javac/lexer/JavaLexerTest.java @@ -102,7 +102,8 @@ public class JavaLexerTest { new TestTuple(EOF, "\\u", ""), new TestTuple(ERROR, "\'\'"), - new TestTuple(ERROR, "\'\\q\'", "\'\\"), + new TestTuple(ERROR, "\'\\q\'", "\'\\q\'"), + new TestTuple(ERROR, "\'\\{1+2}\'", "\'\\{1+2}\'"), }; static class TestTuple { diff --git a/test/langtools/tools/javac/unicode/TripleQuote.out b/test/langtools/tools/javac/unicode/TripleQuote.out index 5fed31c0860..4f82ee78ad6 100644 --- a/test/langtools/tools/javac/unicode/TripleQuote.out +++ b/test/langtools/tools/javac/unicode/TripleQuote.out @@ -1,5 +1,3 @@ TripleQuote.java:12:14: compiler.err.empty.char.lit -TripleQuote.java:12:21: compiler.err.unclosed.char.lit -TripleQuote.java:13:14: compiler.err.empty.char.lit -TripleQuote.java:13:16: compiler.err.unclosed.char.lit -4 errors +TripleQuote.java:13:15: compiler.err.empty.char.lit +2 errors From 6ba6d48a9104313437a4de3ebbddb2c3fa012253 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Wed, 2 Aug 2023 21:59:22 +0000 Subject: [PATCH 11/12] 8313349: Introduce `abstract void HtmlDocletWriter.buildPage()` Reviewed-by: prappo --- .../html/AbstractExecutableMemberWriter.java | 26 +- .../formats/html/AbstractMemberWriter.java | 49 +++- .../html/AbstractOverviewIndexWriter.java | 32 +-- .../formats/html/AllClassesIndexWriter.java | 32 +-- .../formats/html/AllPackagesIndexWriter.java | 26 +- .../html/AnnotationTypeMemberWriter.java | 35 +-- .../doclets/formats/html/ClassUseWriter.java | 55 ++--- .../doclets/formats/html/ClassWriter.java | 19 +- .../formats/html/ConstantsSummaryWriter.java | 11 +- .../formats/html/ConstructorWriter.java | 41 +--- .../formats/html/DeprecatedListWriter.java | 45 ++-- .../doclets/formats/html/DocFilesHandler.java | 223 +++++++++--------- .../formats/html/EnumConstantWriter.java | 37 +-- .../formats/html/ExternalSpecsWriter.java | 28 +-- .../doclets/formats/html/FieldWriter.java | 38 +-- .../doclets/formats/html/HelpWriter.java | 30 +-- .../doclets/formats/html/HtmlDoclet.java | 62 ++--- .../formats/html/HtmlDocletWriter.java | 24 +- .../doclets/formats/html/HtmlIds.java | 14 -- .../formats/html/HtmlIndexBuilder.java | 2 - .../formats/html/IndexRedirectWriter.java | 13 +- .../doclets/formats/html/IndexWriter.java | 55 ++--- .../doclets/formats/html/MethodWriter.java | 36 +-- .../formats/html/ModuleIndexWriter.java | 25 +- .../doclets/formats/html/ModuleWriter.java | 9 +- .../formats/html/NestedClassWriter.java | 7 +- .../formats/html/NewAPIListWriter.java | 42 ++-- .../formats/html/PackageIndexWriter.java | 31 ++- .../formats/html/PackageTreeWriter.java | 21 +- .../formats/html/PackageUseWriter.java | 24 +- .../doclets/formats/html/PackageWriter.java | 12 +- .../formats/html/PreviewListWriter.java | 39 +-- .../doclets/formats/html/PropertyWriter.java | 35 +-- .../doclets/formats/html/SearchWriter.java | 32 +-- .../formats/html/SerialFieldWriter.java | 7 +- .../formats/html/SerialMethodWriter.java | 2 +- .../formats/html/SerializedFormWriter.java | 36 ++- .../formats/html/SubWriterHolderWriter.java | 19 +- .../formats/html/SummaryListWriter.java | 42 +++- .../formats/html/SystemPropertiesWriter.java | 51 ++-- .../doclets/formats/html/TreeWriter.java | 30 +-- .../doclets/formats/html/WriterFactory.java | 145 +++++++++++- .../doclets/formats/html/markup/Entity.java | 1 - .../doclets/formats/html/markup/Head.java | 1 - .../doclets/toolkit/DocFileElement.java | 30 ++- .../internal/doclets/toolkit/util/Utils.java | 5 + 46 files changed, 750 insertions(+), 829 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java index 6435bacb998..4e929130b66 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java @@ -52,20 +52,38 @@ import static jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS_AND_BOUNDS; /** - * Print method and constructor info. + * Abstract "member writer" for executable elements. */ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter { - public AbstractExecutableMemberWriter(SubWriterHolderWriter writer, TypeElement typeElement, + /** + * Creates a writer for executable members, for a given enclosing writer, type element, and kind of member. + * + * @param writer the enclosing "page" writer, with an associated type element + * @param typeElement the type element + * @param kind the kind of member: one of {@link VisibleMemberTable.Kind#CONSTRUCTORS} or {@link VisibleMemberTable.Kind#METHODS} + */ + protected AbstractExecutableMemberWriter(SubWriterHolderWriter writer, TypeElement typeElement, VisibleMemberTable.Kind kind) { super(writer, typeElement, kind); + + // The following would be better before the preceding call to super; see JDK-8300786 + switch (kind) { + case CONSTRUCTORS, METHODS -> { } + default -> throw new IllegalArgumentException(kind.toString()); + } } - public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) { + /** + * Creates a writer for executable members, for a given enclosing writer. + * No type element or kind is provided, limiting the set of methods that can be used. + * + * @param writer the enclosing "page" writer. + */ + protected AbstractExecutableMemberWriter(SubWriterHolderWriter writer) { super(writer); } - /** * Get the type parameters for the executable member. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java index 1e059035f42..59f981d7cac 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java @@ -49,7 +49,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.formats.html.markup.Links; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.Utils; @@ -67,6 +66,8 @@ /** * The base class for member writers. + * + * Two primary methods are defined: {@link #buildSummary(Content)} and {@link #buildDetails(Content)}. */ public abstract class AbstractMemberWriter { @@ -76,7 +77,6 @@ public abstract class AbstractMemberWriter { protected final SubWriterHolderWriter writer; protected final Contents contents; protected final Resources resources; - protected final Links links; protected final HtmlIds htmlIds; protected final TypeElement typeElement; @@ -123,14 +123,33 @@ public abstract class AbstractMemberWriter { ANNOTATION_TYPE_MEMBER, METHODS ); + /** + * Creates a member writer for a given enclosing writer and kind of member. + * + * @param writer the enclosing "page" writer. + * @param kind the kind + */ protected AbstractMemberWriter(ClassWriter writer, VisibleMemberTable.Kind kind) { this(writer, writer.typeElement, kind); } + /** + * Creates a member writer for a given enclosing writer. + * No type element or kind is provided, limiting the set of methods that can be used. + * + * @param writer the writer + */ protected AbstractMemberWriter(SubWriterHolderWriter writer) { this(writer, null, null); } + /** + * Creates a member writer for a given enclosing writer, and optional type element and member kind. + * If no specific type element or kind is provided, methods that require such information + * may throw {@link NullPointerException}. + * + * @param writer the writer + */ protected AbstractMemberWriter(SubWriterHolderWriter writer, TypeElement typeElement, VisibleMemberTable.Kind kind) { @@ -143,7 +162,6 @@ protected AbstractMemberWriter(SubWriterHolderWriter writer, this.utils = configuration.utils; this.contents = configuration.getContents(); this.resources = configuration.docResources; - this.links = writer.links; this.htmlIds = configuration.htmlIds; visibleMemberTable = typeElement == null ? null : configuration.getVisibleMemberTable(typeElement); @@ -158,6 +176,26 @@ protected AbstractMemberWriter(SubWriterHolderWriter writer, */ public abstract void buildDetails(Content target); + /** + * Builds the signature. + * + * @param target the content to which the documentation will be added + */ + protected abstract void buildSignature(Content target); + + /** + * Builds the deprecation info. + * + * @param target the content to which the documentation will be added + */ + protected abstract void buildDeprecationInfo(Content target); + + /** + * Builds the preview info. + * + * @param target the content to which the documentation will be added + */ + protected abstract void buildPreviewInfo(Content target); /** * Builds the "summary" for all members of this kind. @@ -179,7 +217,7 @@ public void buildSummary(Content target) buildInheritedSummary(summaryTreeList); if (!summaryTreeList.isEmpty()) { - Content member = getMemberSummaryHeader(typeElement, target); + Content member = getMemberSummaryHeader(target); summaryTreeList.forEach(member::add); buildSummary(target, member); } @@ -271,12 +309,11 @@ private SortedSet asSortedSet(Collection m /** * Returns the member summary header for the given class. * - * @param typeElement the class the summary belongs to * @param content the content to which the member summary will be added * * @return the member summary header */ - public abstract Content getMemberSummaryHeader(TypeElement typeElement, Content content); + public abstract Content getMemberSummaryHeader(Content content); /** * Adds the given summary to the list of summaries. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractOverviewIndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractOverviewIndexWriter.java index b92b270a399..d46b4c69d82 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractOverviewIndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractOverviewIndexWriter.java @@ -35,7 +35,7 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocPath; /** - * Abstract class to generate the overview files. + * Abstract class to generate the top-level "overview" files. */ public abstract class AbstractOverviewIndexWriter extends HtmlDocletWriter { @@ -46,10 +46,20 @@ public abstract class AbstractOverviewIndexWriter extends HtmlDocletWriter { * @param filename Name of the module index file to be generated. */ public AbstractOverviewIndexWriter(HtmlConfiguration configuration, - DocPath filename) { + DocPath filename) { super(configuration, filename); } + /** + * {@return the page description, for the {@code } element} + */ + protected abstract String getDescription(); + + /** + * {@return the title for the page} + */ + protected abstract String getTitleKey(); + /** * Adds the overview summary comment for this documentation. Add one line * summary at the top of the page and generate a link to the description, @@ -86,16 +96,10 @@ protected void addOverviewTags(Content content) { } } - /** - * Generate and prints the contents in the index file. - * - * @param title the title of the window - * @param description the content for the description META tag - * @throws DocFileIOException if there is a problem building the package index file - */ - protected void buildOverviewIndexFile(String title, String description) - throws DocFileIOException { - String windowOverview = resources.getText(title); + @Override + public void buildPage() throws DocFileIOException { + var titleKey = getTitleKey(); + String windowOverview = resources.getText(titleKey); Content body = getBody(getWindowTitle(windowOverview)); Content main = new ContentBuilder(); addOverviewHeader(main); @@ -105,8 +109,8 @@ protected void buildOverviewIndexFile(String title, String description) .addMainContent(main) .setFooter(getFooter())); printHtmlDocument( - configuration.metakeywords.getOverviewMetaKeywords(title, configuration.getOptions().docTitle()), - description, body); + configuration.metakeywords.getOverviewMetaKeywords(titleKey, configuration.getOptions().docTitle()), + getDescription(), body); } /** diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllClassesIndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllClassesIndexWriter.java index f2145751600..4a39bd0dccc 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllClassesIndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllClassesIndexWriter.java @@ -38,7 +38,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder; import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; @@ -59,38 +58,15 @@ public class AllClassesIndexWriter extends HtmlDocletWriter { * class. * * @param configuration The current configuration - * @param filename Path to the file which is getting generated. * @param indexBuilder Unicode based Index from {@link IndexBuilder} */ - public AllClassesIndexWriter(HtmlConfiguration configuration, - DocPath filename, IndexBuilder indexBuilder) { - super(configuration, filename); + public AllClassesIndexWriter(HtmlConfiguration configuration, IndexBuilder indexBuilder) { + super(configuration, DocPaths.ALLCLASSES_INDEX); this.indexBuilder = indexBuilder; } - /** - * Create AllClassesIndexWriter object. - * - * @param configuration The current configuration - * @param indexBuilder IndexBuilder object for all classes index. - * @throws DocFileIOException - */ - public static void generate(HtmlConfiguration configuration, - IndexBuilder indexBuilder) throws DocFileIOException { - generate(configuration, indexBuilder, DocPaths.ALLCLASSES_INDEX); - } - - private static void generate(HtmlConfiguration configuration, IndexBuilder indexBuilder, - DocPath fileName) throws DocFileIOException { - AllClassesIndexWriter allClassGen = new AllClassesIndexWriter(configuration, - fileName, indexBuilder); - allClassGen.buildAllClassesFile(); - } - - /** - * Print all the classes in the file. - */ - protected void buildAllClassesFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { String label = resources.getText("doclet.All_Classes_And_Interfaces"); Content allClassesContent = new ContentBuilder(); addContents(allClassesContent); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllPackagesIndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllPackagesIndexWriter.java index b0569bc47cb..5581ec03e2a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllPackagesIndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllPackagesIndexWriter.java @@ -27,14 +27,13 @@ import javax.lang.model.element.PackageElement; +import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; /** @@ -46,31 +45,16 @@ public class AllPackagesIndexWriter extends HtmlDocletWriter { * Construct AllPackagesIndexWriter object. * * @param configuration The current configuration - * @param filename Path to the file which is getting generated. - */ - public AllPackagesIndexWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename); - } - - /** - * Create AllPackagesIndexWriter object. - * - * @param configuration The current configuration - * @throws DocFileIOException */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - generate(configuration, DocPaths.ALLPACKAGES_INDEX); - } - - private static void generate(HtmlConfiguration configuration, DocPath fileName) throws DocFileIOException { - AllPackagesIndexWriter allPkgGen = new AllPackagesIndexWriter(configuration, fileName); - allPkgGen.buildAllPackagesFile(); + public AllPackagesIndexWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.ALLPACKAGES_INDEX); } /** * Print all the packages in the file. */ - protected void buildAllPackagesFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { String label = resources.getText("doclet.All_Packages"); Content mainContent = new ContentBuilder(); addPackages(mainContent); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java index 5ca24fac177..2b9c441789d 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java @@ -113,31 +113,19 @@ protected void buildAnnotationTypeMemberChildren(Content annotationContent) { buildDefaultValueInfo(annotationContent); } - /** - * Build the signature. - * - * @param target the content to which the documentation will be added - */ + @Override protected void buildSignature(Content target) { target.add(getSignature(currentMember)); } - /** - * Build the deprecation information. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content annotationContent) { - addDeprecated(currentMember, annotationContent); + @Override + protected void buildDeprecationInfo(Content target) { + addDeprecated(currentMember, target); } - /** - * Build the preview information. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content annotationContent) { - addPreview(currentMember, annotationContent); + @Override + protected void buildPreviewInfo(Content target) { + addPreview(currentMember, target); } /** @@ -171,8 +159,7 @@ protected void buildDefaultValueInfo(Content annotationContent) { } @Override - public Content getMemberSummaryHeader(TypeElement typeElement, - Content content) { + public Content getMemberSummaryHeader(Content content) { switch (kind) { case ANNOTATION_TYPE_MEMBER_REQUIRED -> content.add(selectComment( MarkerComments.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY, @@ -187,10 +174,6 @@ public Content getMemberSummaryHeader(TypeElement typeElement, return c; } - protected Content getMemberHeader() { - return writer.getMemberHeader(); - } - @Override public void buildSummary(Content summariesList, Content content) { writer.addSummary(HtmlStyle.memberSummary, @@ -338,7 +321,7 @@ private TypeMirror getType(Element member) { : member.asType(); } - public void addDefaultValueInfo(Element member, Content annotationContent) { + protected void addDefaultValueInfo(Element member, Content annotationContent) { if (utils.isAnnotationInterface(member.getEnclosingElement())) { ExecutableElement ee = (ExecutableElement) member; AnnotationValue value = ee.getDefaultValue(); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java index a136b690727..322659c6a46 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassUseWriter.java @@ -43,6 +43,7 @@ import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; +import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; @@ -86,14 +87,16 @@ public class ClassUseWriter extends SubWriterHolderWriter { final NestedClassWriter classSubWriter; /** - * Constructor. + * Creates a writer for a page listing the uses of a type element. * - * @param filename the file to be generated. + * @param configuration the configuration + * @param mapper a "mapper" containing the usage information + * @param typeElement the type element */ public ClassUseWriter(HtmlConfiguration configuration, - ClassUseMapper mapper, DocPath filename, + ClassUseMapper mapper, TypeElement typeElement) { - super(configuration, filename); + super(configuration, pathFor(configuration, typeElement)); this.typeElement = typeElement; if (mapper.classToPackageAnnotations.containsKey(typeElement)) { pkgToPackageAnnotations = new TreeSet<>(comparators.classUseComparator()); @@ -138,15 +141,22 @@ public ClassUseWriter(HtmlConfiguration configuration, classSubWriter = new NestedClassWriter(this); } + private static DocPath pathFor(HtmlConfiguration configuration, TypeElement typeElement) { + return configuration.docPaths.forPackage(typeElement) + .resolve(DocPaths.CLASS_USE) + .resolve(configuration.docPaths.forName( typeElement)); + } + /** - * Write out class use pages. + * Write out class use and package use pages. * * @param configuration the configuration for this doclet * @param classTree the class tree hierarchy - * @throws DocFileIOException if there is an error while generating the documentation + * @throws DocletException if there is an error while generating the documentation */ - public static void generate(HtmlConfiguration configuration, ClassTree classTree) throws DocFileIOException { - ClassUseMapper mapper = new ClassUseMapper(configuration, classTree); + public static void generate(HtmlConfiguration configuration, ClassTree classTree) throws DocletException { + var writerFactory = configuration.getWriterFactory(); + var mapper = new ClassUseMapper(configuration, classTree); boolean nodeprecated = configuration.getOptions().noDeprecated(); Utils utils = configuration.utils; for (TypeElement aClass : configuration.getIncludedTypeElements()) { @@ -154,15 +164,16 @@ public static void generate(HtmlConfiguration configuration, ClassTree classTree // as deprecated, do not generate the class-use page. We will still generate // the class-use page if the class is marked as deprecated but the containing // package is not since it could still be linked from that package-use page. - if (!(nodeprecated && - utils.isDeprecated(utils.containingPackage(aClass)))) - ClassUseWriter.generate(configuration, mapper, aClass); + if (!(nodeprecated && utils.isDeprecated(utils.containingPackage(aClass)))) { + writerFactory.newClassUseWriter(aClass, mapper).buildPage(); + } } for (PackageElement pkg : configuration.packages) { // If -nodeprecated option is set and the package is marked // as deprecated, do not generate the package-use page. - if (!(nodeprecated && utils.isDeprecated(pkg))) - PackageUseWriter.generate(configuration, mapper, pkg); + if (!(nodeprecated && utils.isDeprecated(pkg))) { + writerFactory.newPackageUseWriter(pkg, mapper).buildPage(); + } } } @@ -180,27 +191,13 @@ private Map> pkgDivide(Map 0) { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriter.java index 6affe6ff61b..672a6de428e 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriter.java @@ -33,7 +33,6 @@ import java.util.TreeSet; import java.util.stream.Collectors; -import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ModuleElement; @@ -82,7 +81,6 @@ public class ClassWriter extends SubWriterHolderWriter { "java.io.Serializable"); protected final TypeElement typeElement; - protected final VisibleMemberTable visibleMemberTable; protected final ClassTree classTree; protected final PropertyUtils.PropertyHelper pHelper; @@ -99,7 +97,6 @@ public ClassWriter(HtmlConfiguration configuration, TypeElement typeElement, configuration.currentTypeElement = typeElement; this.classTree = classTree; - visibleMemberTable = configuration.getVisibleMemberTable(typeElement); pHelper = new PropertyUtils.PropertyHelper(configuration, typeElement); switch (typeElement.getKind()) { @@ -113,7 +110,8 @@ public PropertyUtils.PropertyHelper getPropertyHelper() { return pHelper; } - public void build() throws DocletException { + @Override + public void buildPage() throws DocletException { buildClassDoc(); } @@ -697,7 +695,7 @@ public Void visitType(TypeElement e, Void p) { } protected void addFunctionalInterfaceInfo (Content target) { - if (isFunctionalInterface()) { + if (utils.isFunctionalInterface(typeElement)) { var dl = HtmlTree.DL(HtmlStyle.notes); dl.add(HtmlTree.DT(contents.functionalInterface)); var dd = new HtmlTree(TagName.DD); @@ -707,17 +705,6 @@ protected void addFunctionalInterfaceInfo (Content target) { } } - public boolean isFunctionalInterface() { - List annotationMirrors = typeElement.getAnnotationMirrors(); - for (AnnotationMirror anno : annotationMirrors) { - if (utils.isFunctionalInterface(anno)) { - return true; - } - } - return false; - } - - protected void addClassDeprecationInfo(Content classInfo) { List deprs = utils.getDeprecatedTrees(typeElement); if (utils.isDeprecated(typeElement)) { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriter.java index 6feded28c07..70825f0e0ef 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriter.java @@ -112,7 +112,8 @@ public ConstantsSummaryWriter(HtmlConfiguration configuration) { this.packageGroupHeadings = new TreeSet<>(utils::compareStrings); } - public void build() throws DocletException { + @Override + public void buildPage() throws DocletException { boolean anyConstants = configuration.packages.stream().anyMatch(this::hasConstantField); if (!anyConstants) { return; @@ -160,7 +161,7 @@ protected void buildContents() { */ protected void buildConstantSummaries() { packageGroupHeadings.clear(); - Content summaries = getConstantSummaries(); + Content summaries = new ContentBuilder(); for (PackageElement aPackage : configuration.packages) { if (hasConstantField(aPackage)) { currentPackage = aPackage; @@ -359,12 +360,6 @@ void addContentsList(Content content) { bodyContents.addMainContent(section); } - //@Override - // TODO: inline? - public Content getConstantSummaries() { - return new ContentBuilder(); - } - void addPackageGroup(String abbrevPackageName, Content toContent) { Content headingContent; HtmlId anchorName; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java index 1bc1b71a6a0..ea79ed09e33 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java @@ -56,9 +56,9 @@ public class ConstructorWriter extends AbstractExecutableMemberWriter { private boolean foundNonPubConstructor = false; /** - * Construct a new ConstructorWriterImpl. + * Construct a new member writer for constructors. * - * @param writer The writer for the class that the constructors belong to. + * @param writer the writer for the class to which the constructors belong */ public ConstructorWriter(ClassWriter writer) { super(writer, writer.typeElement, VisibleMemberTable.Kind.CONSTRUCTORS); @@ -120,31 +120,19 @@ protected void buildConstructorDoc(Content target) { } } - /** - * Build the signature. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildSignature(Content constructorContent) { - constructorContent.add(getSignature(currentConstructor)); + @Override + protected void buildSignature(Content target) { + target.add(getSignature(currentConstructor)); } - /** - * Build the deprecation information. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content constructorContent) { - addDeprecated(currentConstructor, constructorContent); + @Override + protected void buildDeprecationInfo(Content target) { + addDeprecated(currentConstructor, target); } - /** - * Build the preview information. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content constructorContent) { - addPreview(currentConstructor, constructorContent); + @Override + protected void buildPreviewInfo(Content target) { + addPreview(currentConstructor, target); } /** @@ -169,8 +157,7 @@ protected void buildTagInfo(Content constructorContent) { } @Override - public Content getMemberSummaryHeader(TypeElement typeElement, - Content content) { + public Content getMemberSummaryHeader(Content content) { content.add(MarkerComments.START_OF_CONSTRUCTOR_SUMMARY); Content c = new ContentBuilder(); writer.addSummaryHeader(this, c); @@ -297,8 +284,4 @@ protected void addSummaryType(Element member, Content content) { content.add(code); } } - - protected Content getMemberHeader(){ - return writer.getMemberHeader(); - } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DeprecatedListWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DeprecatedListWriter.java index 679322bc049..b670faeade9 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DeprecatedListWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DeprecatedListWriter.java @@ -25,20 +25,19 @@ package jdk.javadoc.internal.doclets.formats.html; -import com.sun.source.doctree.DeprecatedTree; import java.util.List; import javax.lang.model.element.Element; +import com.sun.source.doctree.DeprecatedTree; + +import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlId; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.util.DeprecatedAPIListBuilder; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; /** @@ -53,27 +52,29 @@ public class DeprecatedListWriter extends SummaryListWriter { ModuleElement mdle = (ModuleElement) element; - location = configuration.utils.getLocationForModule(mdle); + location = utils.getLocationForModule(mdle); source = DocPaths.DOC_FILES; } case PACKAGE -> { PackageElement pkg = (PackageElement) element; - location = configuration.utils.getLocationForPackage(pkg); + location = utils.getLocationForPackage(pkg); // Note, given that we have a module-specific location, // we want a module-relative path for the source, and not the // standard path that may include the module directory @@ -97,10 +106,10 @@ public DocFilesHandler(HtmlConfiguration configuration, Element element) { * Copy doc-files directory and its contents from the source * elements directory to the generated documentation directory. * - * @throws DocFileIOException if there is a problem while copying + * @throws DocletException if there is a problem while copying * the documentation files */ - public void copyDocFiles() throws DocFileIOException { + public void copyDocFiles() throws DocletException { boolean first = true; for (DocFile srcdir : DocFile.list(configuration, location, source)) { if (!srcdir.isDirectory()) { @@ -128,7 +137,7 @@ public List getStylesheets() throws DocFileIOException { } private void copyDirectory(DocFile srcdir, final DocPath dstDocPath, - boolean first) throws DocFileIOException { + boolean first) throws DocletException { DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath); if (srcdir.isSameFile(dstdir)) { return; @@ -177,117 +186,36 @@ private boolean isValidFilename(DocFile f) { } } - private void handleHtmlFile(DocFile srcfile, DocPath dstPath) throws DocFileIOException { - Utils utils = configuration.utils; - FileObject fileObject = srcfile.getFileObject(); - DocFileElement dfElement = new DocFileElement(utils, element, fileObject); - - DocPath dfilePath = dstPath.resolve(srcfile.getName()); - PackageElement pkg = dfElement.getPackageElement(); - - HtmlDocletWriter docletWriter = new DocFileWriter(configuration, dfilePath, element, pkg); - - List localTags = getLocalHeaderTags(utils.getPreamble(dfElement)); - Content localTagsContent = docletWriter.commentTagsToContent(dfElement, localTags, false); - - String title = getWindowTitle(docletWriter, dfElement).trim(); - HtmlTree htmlContent = docletWriter.getBody(title); + private void handleHtmlFile(DocFile srcFile, DocPath dstPath) throws DocletException { + var fileObject = srcFile.getFileObject(); + var dfElement = new DocFileElement(utils, element, fileObject); + var path = dstPath.resolve(srcFile.getName()); - List fullBody = utils.getFullBody(dfElement); - Content pageContent = docletWriter.commentTagsToContent(dfElement, fullBody, false); - docletWriter.addTagsInfo(dfElement, pageContent); - - htmlContent.add(new BodyContents() - .setHeader(docletWriter.getHeader(PageMode.DOC_FILE, element)) - .addMainContent(pageContent) - .setFooter(docletWriter.getFooter())); - docletWriter.printHtmlDocument(List.of(), null, localTagsContent, List.of(), htmlContent); + writerFactory.newDocFileWriter(path, dfElement).buildPage(); } - - private List getLocalHeaderTags(List dtrees) { - List localTags = new ArrayList<>(); - DocTreeFactory docTreeFactory = configuration.docEnv.getDocTrees().getDocTreeFactory(); - boolean inHead = false; - boolean inTitle = false; - loop: - for (DocTree dt : dtrees) { - switch (dt.getKind()) { - case START_ELEMENT: - StartElementTree startElem = (StartElementTree)dt; - switch (HtmlTag.get(startElem.getName())) { - case HEAD: - inHead = true; - break; - case META: - break; - case TITLE: - inTitle = true; - break; - default: - if (inHead) { - localTags.add(startElem); - localTags.add(docTreeFactory.newTextTree("\n")); - } - } - break; - case END_ELEMENT: - EndElementTree endElem = (EndElementTree)dt; - switch (HtmlTag.get(endElem.getName())) { - case HEAD: - inHead = false; - break loop; - case TITLE: - inTitle = false; - break; - default: - if (inHead) { - localTags.add(endElem); - localTags.add(docTreeFactory.newTextTree("\n")); - } - } - break; - case ENTITY: - case TEXT: - if (inHead && !inTitle) { - localTags.add(dt); - } - break; - } - } - return localTags; - } - - private String getWindowTitle(HtmlDocletWriter docletWriter, Element element) { - String t = configuration.utils.getHTMLTitle(element); - return docletWriter.getWindowTitle(t); - } - - private static class DocFileWriter extends HtmlDocletWriter { - private final PackageElement pkg; + /** + * A writer to write out the processed form of an HTML file found in the {@code doc-files} subdirectory + * for a module or package. + */ + public static class DocFileWriter extends HtmlDocletWriter { + private final DocFileElement dfElement; /** - * Constructor to construct the HtmlDocletWriter object. + * Constructor. * * @param configuration the configuration of this doclet * @param path the file to be generated - * @param e the anchoring element - * @param pkg the package containing the doc file + * @param dfElement the element representing the doc file */ - public DocFileWriter(HtmlConfiguration configuration, DocPath path, Element e, PackageElement pkg) { + public DocFileWriter(HtmlConfiguration configuration, DocPath path, DocFileElement dfElement) { super(configuration, path); - switch (e.getKind()) { - case PACKAGE: - case MODULE: - break; - default: - throw new AssertionError("unsupported element: " + e.getKind()); - } - this.pkg = pkg; + this.dfElement = dfElement; } @Override protected Navigation getNavBar(PageMode pageMode, Element element) { + var pkg = dfElement.getPackageElement(); Content mdleLinkContent = getModuleLink(utils.elementUtils.getModuleOf(element), contents.moduleLabel); Content pkgLinkContent = getPackageLink(pkg, contents.packageLabel); @@ -295,5 +223,84 @@ protected Navigation getNavBar(PageMode pageMode, Element element) { .setNavLinkModule(mdleLinkContent) .setNavLinkPackage(pkgLinkContent); } + + @Override + public void buildPage() throws DocFileIOException { + + List localTags = getLocalHeaderTags(utils.getPreamble(dfElement)); + Content localTagsContent = commentTagsToContent(dfElement, localTags, false); + + String title = getWindowTitle(this, dfElement).trim(); + HtmlTree htmlContent = getBody(title); + + List fullBody = utils.getFullBody(dfElement); + Content pageContent = commentTagsToContent(dfElement, fullBody, false); + addTagsInfo(dfElement, pageContent); + + htmlContent.add(new BodyContents() + .setHeader(getHeader(PageMode.DOC_FILE, dfElement.getElement())) + .addMainContent(pageContent) + .setFooter(getFooter())); + printHtmlDocument(List.of(), null, localTagsContent, List.of(), htmlContent); + } + + private String getWindowTitle(HtmlDocletWriter docletWriter, Element element) { + String t = configuration.utils.getHTMLTitle(element); + return docletWriter.getWindowTitle(t); + } + + private List getLocalHeaderTags(List dtrees) { + List localTags = new ArrayList<>(); + DocTreeFactory docTreeFactory = configuration.docEnv.getDocTrees().getDocTreeFactory(); + boolean inHead = false; + boolean inTitle = false; + loop: + for (DocTree dt : dtrees) { + switch (dt.getKind()) { + case START_ELEMENT: + StartElementTree startElem = (StartElementTree)dt; + switch (HtmlTag.get(startElem.getName())) { + case HEAD: + inHead = true; + break; + case META: + break; + case TITLE: + inTitle = true; + break; + default: + if (inHead) { + localTags.add(startElem); + localTags.add(docTreeFactory.newTextTree("\n")); + } + } + break; + case END_ELEMENT: + EndElementTree endElem = (EndElementTree)dt; + switch (HtmlTag.get(endElem.getName())) { + case HEAD: + inHead = false; + break loop; + case TITLE: + inTitle = false; + break; + default: + if (inHead) { + localTags.add(endElem); + localTags.add(docTreeFactory.newTextTree("\n")); + } + } + break; + case ENTITY: + case TEXT: + if (inHead && !inTitle) { + localTags.add(dt); + } + break; + } + } + return localTags; + } } + } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java index 2cfb32b4322..ebe82343ce4 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java @@ -67,14 +67,12 @@ public void buildDetails(Content target) { protected void buildEnumConstant(Content target) { var enumConstants = getVisibleMembers(VisibleMemberTable.Kind.ENUM_CONSTANTS); if (!enumConstants.isEmpty()) { - Content enumConstantsDetailsHeader = getEnumConstantsDetailsHeader(typeElement, - target); + Content enumConstantsDetailsHeader = getEnumConstantsDetailsHeader(target); Content memberList = getMemberList(); for (Element enumConstant : enumConstants) { currentElement = (VariableElement)enumConstant; - Content enumConstantContent = getEnumConstantsHeader(currentElement, - memberList); + Content enumConstantContent = getEnumConstantsHeader(currentElement); buildSignature(enumConstantContent); buildDeprecationInfo(enumConstantContent); @@ -90,29 +88,17 @@ protected void buildEnumConstant(Content target) { } } - /** - * Build the signature. - * - * @param target the content to which the documentation will be added - */ + @Override protected void buildSignature(Content target) { target.add(getSignature(currentElement)); } - /** - * Build the deprecation information. - * - * @param target the content to which the documentation will be added - */ + @Override protected void buildDeprecationInfo(Content target) { addDeprecated(currentElement, target); } - /** - * Build the preview information. - * - * @param target the content to which the documentation will be added - */ + @Override protected void buildPreviewInfo(Content target) { addPreview(currentElement, target); } @@ -139,8 +125,7 @@ protected void buildTagInfo(Content target) { } @Override - public Content getMemberSummaryHeader(TypeElement typeElement, - Content content) { + public Content getMemberSummaryHeader(Content content) { content.add(MarkerComments.START_OF_ENUM_CONSTANT_SUMMARY); Content memberContent = new ContentBuilder(); writer.addSummaryHeader(this, memberContent); @@ -153,8 +138,7 @@ public void buildSummary(Content summariesList, Content content) { HtmlIds.ENUM_CONSTANT_SUMMARY, summariesList, content); } - protected Content getEnumConstantsDetailsHeader(TypeElement typeElement, - Content memberDetails) { + protected Content getEnumConstantsDetailsHeader(Content memberDetails) { memberDetails.add(MarkerComments.START_OF_ENUM_CONSTANT_DETAILS); var enumConstantsDetailsContent = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, @@ -163,8 +147,7 @@ protected Content getEnumConstantsDetailsHeader(TypeElement typeElement, return enumConstantsDetailsContent; } - protected Content getEnumConstantsHeader(VariableElement enumConstant, - Content enumConstantsDetails) { + protected Content getEnumConstantsHeader(VariableElement enumConstant) { Content enumConstantsContent = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, Text.of(name(enumConstant))); @@ -252,8 +235,4 @@ protected Content getSummaryLink(Element member) { String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName(); return writer.getDocLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, member, name); } - - protected Content getMemberHeader(){ - return writer.getMemberHeader(); - } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ExternalSpecsWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ExternalSpecsWriter.java index 22f4db20ba3..36e01faa703 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ExternalSpecsWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ExternalSpecsWriter.java @@ -56,7 +56,6 @@ import jdk.javadoc.internal.doclets.toolkit.DocletElement; import jdk.javadoc.internal.doclets.toolkit.OverviewElement; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; @@ -68,8 +67,6 @@ */ public class ExternalSpecsWriter extends HtmlDocletWriter { - private final Navigation navBar; - /** * Cached contents of {@code ...} tags of the HTML pages. */ @@ -79,32 +76,25 @@ public class ExternalSpecsWriter extends HtmlDocletWriter { * Constructs ExternalSpecsWriter object. * * @param configuration The current configuration - * @param filename Path to the file which is getting generated. */ - public ExternalSpecsWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename); - this.navBar = new Navigation(null, configuration, PageMode.EXTERNAL_SPECS, path); - } - - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - generate(configuration, DocPaths.EXTERNAL_SPECS); + public ExternalSpecsWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.EXTERNAL_SPECS, false); } - private static void generate(HtmlConfiguration configuration, DocPath fileName) throws DocFileIOException { + /** + * Prints all the "external specs" to the file. + */ + @Override + public void buildPage() throws DocFileIOException { boolean hasExternalSpecs = configuration.mainIndex != null && !configuration.mainIndex.getItems(DocTree.Kind.SPEC).isEmpty(); if (!hasExternalSpecs) { return; } - ExternalSpecsWriter w = new ExternalSpecsWriter(configuration, fileName); - w.buildExternalSpecsPage(); + + writeGenerating(); configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.EXTERNAL_SPECS); - } - /** - * Prints all the "external specs" to the file. - */ - protected void buildExternalSpecsPage() throws DocFileIOException { checkUniqueItems(); String title = resources.getText("doclet.External_Specifications"); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java index e97239340aa..2cddb68f2b2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java @@ -97,31 +97,19 @@ protected void buildFieldDoc(Content target) { } } - /** - * Build the signature. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildSignature(Content fieldContent) { - fieldContent.add(getSignature(currentElement)); + @Override + protected void buildSignature(Content target) { + target.add(getSignature(currentElement)); } - /** - * Build the deprecation information. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content fieldContent) { - addDeprecated(currentElement, fieldContent); + @Override + protected void buildDeprecationInfo(Content target) { + addDeprecated(currentElement, target); } - /** - * Build the preview information. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content fieldContent) { - addPreview(currentElement, fieldContent); + @Override + protected void buildPreviewInfo(Content target) { + addPreview(currentElement, target); } /** @@ -145,10 +133,8 @@ protected void buildTagInfo(Content fieldContent) { addTags(currentElement, fieldContent); } - @Override - public Content getMemberSummaryHeader(TypeElement typeElement, - Content content) { + public Content getMemberSummaryHeader(Content content) { content.add(MarkerComments.START_OF_FIELD_SUMMARY); Content memberContent = new ContentBuilder(); writer.addSummaryHeader(this, memberContent); @@ -283,8 +269,4 @@ protected Content getSummaryLink(Element member) { String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName(); return writer.getDocLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, member, name); } - - protected Content getMemberHeader(){ - return writer.getMemberHeader(); - } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HelpWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HelpWriter.java index 2848fff194e..2461567d932 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HelpWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HelpWriter.java @@ -62,11 +62,9 @@ public class HelpWriter extends HtmlDocletWriter { /** * Constructor to construct HelpWriter object. * @param configuration the configuration - * @param filename File to be generated. */ - public HelpWriter(HtmlConfiguration configuration, - DocPath filename) { - super(configuration, filename); + public HelpWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.HELP_DOC); // yes, INDEX is correct in the following line overviewLink = links.createLink(DocPaths.INDEX, resources.getText("doclet.Overview")); @@ -78,27 +76,8 @@ public HelpWriter(HtmlConfiguration configuration, indexLink = links.createLink(dp, resources.getText("doclet.Index")); } - /** - * Construct the HelpWriter object and then use it to generate the help - * file. The name of the generated file is "help-doc.html". The help file - * will get generated if and only if "-helpfile" and "-nohelp" is not used - * on the command line. - * - * @param configuration the configuration - * @throws DocFileIOException if there is a problem while generating the documentation - */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - DocPath filename = DocPaths.HELP_DOC; - HelpWriter helpgen = new HelpWriter(configuration, filename); - helpgen.generateHelpFile(); - } - - /** - * Generate the help file contents. - * - * @throws DocFileIOException if there is a problem while generating the documentation - */ - protected void generateHelpFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { String title = resources.getText("doclet.Window_Help_title"); HtmlTree body = getBody(getWindowTitle(title)); ContentBuilder helpFileContent = new ContentBuilder(); @@ -208,7 +187,6 @@ private Content getNavigationSection(HtmlTree mainTOC) { return content; } - /** * Creates the page-specific help, adding an entry into the main table-of-contents. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java index f644483dffb..de78ee052f6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java @@ -32,6 +32,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; +import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -216,8 +217,8 @@ protected void generateOtherFiles(ClassTree classTree) throws DocletException { super.generateOtherFiles(classTree); - writerFactory.newConstantsSummaryWriter().build(); - writerFactory.newSerializedFormWriter().build(); + writerFactory.newConstantsSummaryWriter().buildPage(); + writerFactory.newSerializedFormWriter().buildPage(); var options = configuration.getOptions(); if (options.linkSource()) { @@ -245,44 +246,49 @@ protected void generateOtherFiles(ClassTree classTree) } if (options.createTree()) { - TreeWriter.generate(configuration, classTree); + writerFactory.newTreeWriter(classTree).buildPage(); } - if (configuration.conditionalPages.contains((HtmlConfiguration.ConditionalPage.DEPRECATED))) { - DeprecatedListWriter.generate(configuration); - } - - if (configuration.conditionalPages.contains((HtmlConfiguration.ConditionalPage.PREVIEW))) { - PreviewListWriter.generate(configuration); - } - - if (configuration.conditionalPages.contains((HtmlConfiguration.ConditionalPage.NEW))) { - NewAPIListWriter.generate(configuration); + for (var cp : EnumSet.of( + HtmlConfiguration.ConditionalPage.DEPRECATED, + HtmlConfiguration.ConditionalPage.PREVIEW, + HtmlConfiguration.ConditionalPage.NEW)) { + if (configuration.conditionalPages.contains(cp)) { + var w = switch (cp) { + case DEPRECATED -> writerFactory.newDeprecatedListWriter(); + case NEW -> writerFactory.newNewAPIListWriter(); + case PREVIEW -> writerFactory.newPreviewListWriter(); + default -> throw new AssertionError(); + }; + w.buildPage(); + } } if (options.createOverview()) { - if (configuration.showModules) { - ModuleIndexWriter.generate(configuration); - } else { - PackageIndexWriter.generate(configuration); - } + var w = configuration.showModules + ? writerFactory.newModuleIndexWriter() + : writerFactory.newPackageIndexWriter(); + w.buildPage(); } if (options.createIndex()) { if (!options.noExternalSpecsPage()){ - ExternalSpecsWriter.generate(configuration); + writerFactory.newExternalSpecsWriter().buildPage(); } - SystemPropertiesWriter.generate(configuration); + writerFactory.newSystemPropertiesWriter().buildPage(); + configuration.mainIndex.addElements(); IndexBuilder allClassesIndex = new IndexBuilder(configuration, nodeprecated, true); allClassesIndex.addElements(); - AllClassesIndexWriter.generate(configuration, allClassesIndex); + + writerFactory.newAllClassesIndexWriter(allClassesIndex).buildPage(); if (!configuration.packages.isEmpty()) { - AllPackagesIndexWriter.generate(configuration); + writerFactory.newAllPackagesIndexWriter().buildPage(); } + configuration.mainIndex.createSearchIndexFiles(); IndexWriter.generate(configuration); - SearchWriter.generate(configuration); + writerFactory.newSearchWriter().buildPage(); } if (options.createOverview()) { @@ -292,8 +298,10 @@ protected void generateOtherFiles(ClassTree classTree) } if (options.helpFile().isEmpty() && !options.noHelp()) { - HelpWriter.generate(configuration); + var w = writerFactory.newHelpWriter(); + w.buildPage(); } + // If a stylesheet file is not specified, copy the default stylesheet // and replace newline with platform-specific newline. DocFile f; @@ -399,7 +407,7 @@ protected void generateClassFiles(SortedSet typeElems, ClassTree cl !(configuration.isGeneratedDoc(te) && utils.isIncluded(te))) { continue; } - writerFactory.newClassWriter(te, classTree).build(); + writerFactory.newClassWriter(te, classTree).buildPage(); } } @@ -408,7 +416,7 @@ protected void generateModuleFiles() throws DocletException { if (configuration.showModules) { List mdles = new ArrayList<>(configuration.modulePackages.keySet()); for (ModuleElement mdle : mdles) { - writerFactory.newModuleWriter(mdle).build(); + writerFactory.newModuleWriter(mdle).buildPage(); } } } @@ -423,7 +431,7 @@ protected void generatePackageFiles(ClassTree classTree) throws DocletException // deprecated, do not generate the package-summary.html, package-frame.html // and package-tree.html pages for that package. if (!(options.noDeprecated() && utils.isDeprecated(pkg))) { - writerFactory.newPackageWriter(pkg).build(); + writerFactory.newPackageWriter(pkg).buildPage(); if (options.createTree()) { PackageTreeWriter.generate(configuration, pkg, options.noDeprecated()); } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java index 7d210d2d1ba..c9ee4b1a450 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java @@ -94,6 +94,7 @@ import jdk.javadoc.internal.doclets.formats.html.markup.TextBuilder; import jdk.javadoc.internal.doclets.formats.html.taglets.Taglet; import jdk.javadoc.internal.doclets.formats.html.taglets.TagletWriter; +import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.Messages; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; @@ -115,11 +116,10 @@ /** - * Class for the Html Format Code Generation specific to JavaDoc. - * This Class contains methods related to the Html Code Generation which - * are used extensively while generating the entire documentation. + * The base class for classes that write complete HTML pages to be included in the overall API documentation. + * The primary method is {@link #buildPage()}. */ -public class HtmlDocletWriter { +public abstract class HtmlDocletWriter { /** * Relative path from the file getting generated to the destination @@ -137,12 +137,6 @@ public class HtmlDocletWriter { */ public final DocPath path; - /** - * Name of the file getting generated. If the file getting generated is - * "java/lang/Object.html", then the filename is "Object.html". - */ - public final DocPath filename; - /** * The global configuration information for this run. */ @@ -209,7 +203,7 @@ public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path) { * @param path the file to be generated. * @param generating whether to write a "Geneterating ..." message to the console */ - public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path, boolean generating) { + protected HtmlDocletWriter(HtmlConfiguration configuration, DocPath path, boolean generating) { this.configuration = configuration; this.options = configuration.getOptions(); this.contents = configuration.getContents(); @@ -221,7 +215,6 @@ public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path, boolean g this.htmlIds = configuration.htmlIds; this.path = path; this.pathToRoot = path.parent().invert(); - this.filename = path.basename(); this.docPaths = configuration.docPaths; this.mainBodyScript = new Script(); @@ -230,6 +223,13 @@ public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path, boolean g } } + /** + * The top-level method to generate and write the page represented by this writer. + * + * @throws DocletException if a problem occurs while building or writing the page + */ + public abstract void buildPage() throws DocletException; + /** * Writes a "Generating _file_" message to the console */ diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIds.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIds.java index 0491cbdc727..8e14d02b4e0 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIds.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIds.java @@ -106,8 +106,6 @@ public class HtmlIds { static final HtmlId SERVICES = HtmlId.of("services-summary"); static final HtmlId SKIP_NAVBAR_TOP = HtmlId.of("skip-navbar-top"); static final HtmlId UNNAMED_PACKAGE_ANCHOR = HtmlId.of("unnamed-package"); - - private static final String ENUM_CONSTANTS_INHERITANCE = "enum-constants-inherited-from-class-"; private static final String FIELDS_INHERITANCE = "fields-inherited-from-class-"; private static final String METHODS_INHERITANCE = "methods-inherited-from-class-"; private static final String NESTED_CLASSES_INHERITANCE = "nested-classes-inherited-from-class-"; @@ -323,17 +321,6 @@ HtmlId forInheritedFields(TypeElement element) { return forInherited(FIELDS_INHERITANCE, element); } - /** - * Returns an id for the list of enum constants inherited from a class or interface. - * - * @param element the class or interface - * - * @return the id - */ - HtmlId forInheritedEnumConstants(TypeElement element) { - return forInherited(ENUM_CONSTANTS_INHERITANCE, element); - } - /** * Returns an id for the list of methods inherited from a class or interface. * @@ -487,7 +474,6 @@ public static HtmlId forTabPanel(HtmlId tableId) { return HtmlId.of(tableId.name() + ".tabpanel"); } - /** * Returns an id for the "preview" section for an element. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIndexBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIndexBuilder.java index e45e3b33f70..2c8576f7d40 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIndexBuilder.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIndexBuilder.java @@ -83,7 +83,6 @@ public void addElements() { return; } - Map duplicateLabelCheck = new HashMap<>(); for (Character ch : getFirstCharacters()) { for (IndexItem item : getItems(ch)) { @@ -149,7 +148,6 @@ private void addContainingInfo(IndexItem item, boolean addModuleInfo) { } } - /** * Generates the set of index files used by interactive search. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java index 8a42bb63b77..7ce0b639266 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java @@ -57,22 +57,19 @@ public static void generate(HtmlConfiguration configuration) public static void generate(HtmlConfiguration configuration, DocPath fileName, DocPath target) throws DocFileIOException { - IndexRedirectWriter indexRedirect = new IndexRedirectWriter(configuration, fileName, target); - indexRedirect.generateIndexFile(); + var indexRedirect = new IndexRedirectWriter(configuration, fileName, target); + indexRedirect.buildPage(); } - private DocPath target; + private final DocPath target; private IndexRedirectWriter(HtmlConfiguration configuration, DocPath filename, DocPath target) { super(configuration, filename); this.target = target; } - /** - * Generate an index file that redirects to an alternate file. - * @throws DocFileIOException if there is a problem generating the file - */ - private void generateIndexFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { Head head = new Head(path, configuration.getDocletVersion(), configuration.getBuildDate()) .setTimestamp(!options.noTimestamp()) .setDescription("index redirect") diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexWriter.java index d7ba0ceece8..ff95926395a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexWriter.java @@ -46,6 +46,7 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.Text; +import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; @@ -63,6 +64,8 @@ public class IndexWriter extends HtmlDocletWriter { protected final IndexBuilder mainIndex; protected final boolean splitIndex; + protected final List allFirstCharacters; + protected final List displayFirstCharacters; /** * Generates the main index of all documented elements, terms defined in some documentation @@ -72,9 +75,10 @@ public class IndexWriter extends HtmlDocletWriter { * initial letter; otherwise, a single page is generated for all items in the index. * * @param configuration the configuration - * @throws DocFileIOException if an error occurs while writing the files + * @throws DocletException if an error occurs while writing the files */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { + public static void generate(HtmlConfiguration configuration) throws DocletException { + var writerFactory = configuration.getWriterFactory(); IndexBuilder mainIndex = configuration.mainIndex; List firstCharacters = mainIndex.getFirstCharacters(); if (configuration.getOptions().splitIndex()) { @@ -82,12 +86,10 @@ public static void generate(HtmlConfiguration configuration) throws DocFileIOExc while (iter.hasNext()) { Character ch = iter.next(); DocPath file = DocPaths.INDEX_FILES.resolve(DocPaths.indexN(iter.nextIndex())); - IndexWriter writer = new IndexWriter(configuration, file); - writer.generateIndexFile(firstCharacters, List.of(ch)); + writerFactory.newIndexWriter(file, firstCharacters, List.of(ch)).buildPage(); } } else { - IndexWriter writer = new IndexWriter(configuration, DocPaths.INDEX_ALL); - writer.generateIndexFile(firstCharacters, firstCharacters); + writerFactory.newIndexWriter(DocPaths.INDEX_ALL, firstCharacters, firstCharacters).buildPage(); } } @@ -96,22 +98,25 @@ public static void generate(HtmlConfiguration configuration) throws DocFileIOExc * * @param configuration the current configuration * @param path the file to be generated + * @param allFirstCharacters the initial characters of all index items + * @param displayFirstCharacters the initial characters of the index items to appear on this page */ - protected IndexWriter(HtmlConfiguration configuration, DocPath path) { + protected IndexWriter(HtmlConfiguration configuration, DocPath path, + List allFirstCharacters, List displayFirstCharacters) { super(configuration, path); this.mainIndex = configuration.mainIndex; this.splitIndex = configuration.getOptions().splitIndex(); + this.allFirstCharacters = allFirstCharacters; + this.displayFirstCharacters = displayFirstCharacters; } /** * Generates a page containing some or all of the overall index. * - * @param allFirstCharacters the initial characters of all index items - * @param displayFirstCharacters the initial characters of the index items to appear on this page * @throws DocFileIOException if an error occurs while writing the page */ - protected void generateIndexFile(List allFirstCharacters, - List displayFirstCharacters) throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { String title = splitIndex ? resources.getText("doclet.Window_Split_Index", displayFirstCharacters.get(0)) : resources.getText("doclet.Window_Single_Index"); @@ -189,43 +194,35 @@ protected void addElementDescription(IndexItem item, Content target) { Element element = item.getElement(); String label = item.getLabel(); switch (element.getKind()) { - case MODULE: + case MODULE -> { dt = HtmlTree.DT(getModuleLink((ModuleElement) element, Text.of(label))); dt.add(" - ").add(contents.module_).add(" " + label); - break; + } - case PACKAGE: + case PACKAGE -> { dt = HtmlTree.DT(getPackageLink((PackageElement) element, Text.of(label))); if (configuration.showModules) { item.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(element))); } dt.add(" - ").add(contents.package_).add(" " + label); - break; + } - case CLASS: - case ENUM: - case RECORD: - case ANNOTATION_TYPE: - case INTERFACE: + case CLASS, ENUM, RECORD, ANNOTATION_TYPE, INTERFACE -> { dt = HtmlTree.DT(getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS_IN_LABEL, (TypeElement) element).style(HtmlStyle.typeNameLink))); dt.add(" - "); addClassInfo((TypeElement) element, dt); - break; + } - case CONSTRUCTOR: - case METHOD: - case FIELD: - case ENUM_CONSTANT: + case CONSTRUCTOR, METHOD, FIELD, ENUM_CONSTANT -> { TypeElement containingType = item.getContainingTypeElement(); dt = HtmlTree.DT(getDocLink(HtmlLinkInfo.Kind.PLAIN, containingType, element, - label, HtmlStyle.memberNameLink)); + label, HtmlStyle.memberNameLink)); dt.add(" - "); addMemberDesc(element, containingType, dt); - break; + } - default: - throw new Error(); + default -> throw new Error(); } target.add(dt); var dd = new HtmlTree(TagName.DD); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java index e1974a05858..cf7d9c15f47 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java @@ -119,31 +119,19 @@ protected void buildMethodDoc(Content detailsList) { } } - /** - * Build the signature. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildSignature(Content methodContent) { - methodContent.add(getSignature(currentMethod)); + @Override + protected void buildSignature(Content target) { + target.add(getSignature(currentMethod)); } - /** - * Build the deprecation information. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content methodContent) { - addDeprecated(currentMethod, methodContent); + @Override + protected void buildDeprecationInfo(Content target) { + addDeprecated(currentMethod, target); } - /** - * Build the preview information. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content methodContent) { - addPreview(currentMethod, methodContent); + @Override + protected void buildPreviewInfo(Content target) { + addPreview(currentMethod, target); } /** @@ -174,7 +162,7 @@ protected void buildTagInfo(Content methodContent) { } @Override - public Content getMemberSummaryHeader(TypeElement typeElement, Content target) { + public Content getMemberSummaryHeader(Content target) { target.add(MarkerComments.START_OF_METHOD_SUMMARY); Content memberContent = new ContentBuilder(); writer.addSummaryHeader(this, memberContent); @@ -434,8 +422,4 @@ protected Content getReturnType(ExecutableElement method) { } return new ContentBuilder(); } - - protected Content getMemberHeader(){ - return writer.getMemberHeader(); - } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java index 93152c49a61..abe6159d1af 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java @@ -34,8 +34,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; /** @@ -52,23 +50,20 @@ public class ModuleIndexWriter extends AbstractOverviewIndexWriter { * Construct the ModuleIndexWriter. * * @param configuration the configuration object - * @param filename the name of the generated file */ - public ModuleIndexWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename); + public ModuleIndexWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.INDEX); modules = configuration.modules; } - /** - * Generate the module index page. - * - * @param configuration the current configuration of the doclet. - * @throws DocFileIOException if there is a problem generating the module index page - */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - DocPath filename = DocPaths.INDEX; - ModuleIndexWriter mdlgen = new ModuleIndexWriter(configuration, filename); - mdlgen.buildOverviewIndexFile("doclet.Window_Overview_Summary", "module index"); + @Override + public String getDescription() { + return "module index"; + } + + @Override + public String getTitleKey() { + return "doclet.Window_Overview_Summary"; } /** diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java index db38bbbaaa2..de91439cd30 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java @@ -165,12 +165,8 @@ public ModuleWriter(HtmlConfiguration configuration, ModuleElement mdle) { computeModulesData(); } - /** - * Build the module summary. - * - * @throws DocletException if there is a problem while building the documentation - */ - public void build() throws DocletException { + @Override + public void buildPage() throws DocletException { buildModuleDoc(); } @@ -681,6 +677,7 @@ public void addPackageSummary(HtmlTree li) { row.add(getPackageExportOpensTo(entry.openedTo)); } Content summary = new ContentBuilder(); + // TODO: consider deprecation info, addPackageDeprecationInfo addPreviewSummary(pkg, summary); addSummaryComment(pkg, summary); row.add(summary); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java index e2a4e7fb0eb..7f67e37840d 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java @@ -57,9 +57,12 @@ public void buildDetails(Content target) { throw new UnsupportedOperationException(); } + protected void buildSignature(Content target) { } + protected void buildDeprecationInfo(Content target) { } + protected void buildPreviewInfo(Content target) { } + @Override - public Content getMemberSummaryHeader(TypeElement typeElement, - Content content) { + public Content getMemberSummaryHeader(Content content) { content.add(MarkerComments.START_OF_NESTED_CLASS_SUMMARY); Content memberContent = new ContentBuilder(); writer.addSummaryHeader(this, memberContent); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NewAPIListWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NewAPIListWriter.java index ae3b3f1f482..901b5e6e8c4 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NewAPIListWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NewAPIListWriter.java @@ -25,9 +25,12 @@ package jdk.javadoc.internal.doclets.formats.html; +import java.util.List; + import javax.lang.model.element.Element; import com.sun.source.doctree.DocTree; + import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlId; @@ -35,13 +38,9 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.NewAPIBuilder; -import java.util.List; - import static com.sun.source.doctree.DocTree.Kind.SINCE; /** @@ -54,23 +53,28 @@ public class NewAPIListWriter extends SummaryListWriter { * * @param configuration the configuration for this doclet */ - public NewAPIListWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename, configuration.newAPIPageBuilder); + public NewAPIListWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.NEW_LIST, configuration.newAPIPageBuilder); } - /** - * If the "New API" page is configured this method instantiates a NewAPIListWriter - * and generates the file. - * - * @param configuration the current configuration of the doclet. - * @throws DocFileIOException if there is a problem writing the new API list - */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - if (configuration.conditionalPages.contains(HtmlConfiguration.ConditionalPage.NEW)) { - NewAPIListWriter writer = new NewAPIListWriter(configuration, DocPaths.NEW_LIST); - writer.generateSummaryListFile(PageMode.NEW, "new elements", - Text.of(getHeading(configuration)), "doclet.Window_New_List"); - } + @Override + protected PageMode getPageMode() { + return PageMode.NEW; + } + + @Override + protected String getDescription() { + return "new elements"; + } + + @Override + protected Content getHeadContent() { + return Text.of(getHeading(configuration)); + } + + @Override + protected String getTitleKey() { + return "doclet.Window_New_List"; } @Override diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java index dcce9d709d2..ef7f25e7388 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java @@ -25,15 +25,15 @@ package jdk.javadoc.internal.doclets.formats.html; -import java.util.*; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; import javax.lang.model.element.PackageElement; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.Group; @@ -43,7 +43,7 @@ public class PackageIndexWriter extends AbstractOverviewIndexWriter { /** - * A Set of Packages to be documented. + * The Set of Packages to be documented. */ protected SortedSet packages; @@ -53,24 +53,21 @@ public class PackageIndexWriter extends AbstractOverviewIndexWriter { * the order of groups specified by the user. * * @param configuration the configuration for this doclet - * @param filename the path of the page to be generated * @see Group */ - public PackageIndexWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename); + public PackageIndexWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.INDEX); packages = configuration.packages; } - /** - * Generate the package index page. - * - * @param configuration the current configuration of the doclet. - * @throws DocFileIOException if there is a problem generating the package index page - */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - DocPath filename = DocPaths.INDEX; - PackageIndexWriter packgen = new PackageIndexWriter(configuration, filename); - packgen.buildOverviewIndexFile("doclet.Window_Overview_Summary", "package index"); + @Override + public String getDescription() { + return "package index"; + } + + @Override + public String getTitleKey() { + return "doclet.Window_Overview_Summary"; } /** diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageTreeWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageTreeWriter.java index b3ffa7a2cd1..5627ebdcc5a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageTreeWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageTreeWriter.java @@ -28,14 +28,13 @@ import javax.lang.model.element.Element; import javax.lang.model.element.PackageElement; +import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; @@ -55,12 +54,12 @@ public class PackageTreeWriter extends AbstractTreeWriter { /** * Constructor. * @param configuration the configuration - * @param path the docpath to generate files into * @param packageElement the current package */ - public PackageTreeWriter(HtmlConfiguration configuration, DocPath path, PackageElement packageElement) { - super(configuration, path, - new ClassTree(configuration.typeElementCatalog.allClasses(packageElement), configuration)); + public PackageTreeWriter(HtmlConfiguration configuration, PackageElement packageElement) { + super(configuration, + configuration.docPaths.forPackage(packageElement).resolve(DocPaths.PACKAGE_TREE), + new ClassTree(configuration.typeElementCatalog.allClasses(packageElement), configuration)); this.packageElement = packageElement; } @@ -77,9 +76,10 @@ public PackageTreeWriter(HtmlConfiguration configuration, DocPath path, PackageE public static void generate(HtmlConfiguration configuration, PackageElement pkg, boolean noDeprecated) throws DocFileIOException { - DocPath path = configuration.docPaths.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE); - PackageTreeWriter packgen = new PackageTreeWriter(configuration, path, pkg); - packgen.generatePackageTreeFile(); + if (!(noDeprecated && configuration.utils.isDeprecated(pkg))) { + var packgen = new PackageTreeWriter(configuration, pkg); + packgen.buildPage(); + } } /** @@ -87,7 +87,8 @@ public static void generate(HtmlConfiguration configuration, * * @throws DocFileIOException if there is a problem generating the package tree file */ - protected void generatePackageTreeFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { HtmlTree body = getPackageTreeHeader(); Content mainContent = new ContentBuilder(); Content headContent = packageElement.isUnnamed() diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java index cfc61034005..cdd531af4a0 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java @@ -59,13 +59,12 @@ public class PackageUseWriter extends SubWriterHolderWriter { * * @param configuration the configuration * @param mapper a mapper to provide details of where elements are used - * @param filename the file to be generated * @param pkgElement the package element to be documented */ public PackageUseWriter(HtmlConfiguration configuration, - ClassUseMapper mapper, DocPath filename, + ClassUseMapper mapper, PackageElement pkgElement) { - super(configuration, configuration.docPaths.forPackage(pkgElement).resolve(filename)); + super(configuration, pathFor(configuration, pkgElement)); this.packageElement = pkgElement; // by examining all classes in this package, find what packages @@ -89,27 +88,16 @@ public PackageUseWriter(HtmlConfiguration configuration, } } - /** - * Generate a class page. - * - * @param configuration the current configuration of the doclet. - * @param mapper the mapping of the class usage. - * @param pkgElement the package being documented. - * @throws DocFileIOException if there is a problem generating the package use page - */ - public static void generate(HtmlConfiguration configuration, - ClassUseMapper mapper, PackageElement pkgElement) - throws DocFileIOException { - DocPath filename = DocPaths.PACKAGE_USE; - PackageUseWriter pkgusegen = new PackageUseWriter(configuration, mapper, filename, pkgElement); - pkgusegen.generatePackageUseFile(); + private static DocPath pathFor(HtmlConfiguration configuration, PackageElement packageElement) { + return configuration.docPaths.forPackage(packageElement).resolve(DocPaths.PACKAGE_USE); } /** * Generate the package use list. * @throws DocFileIOException if there is a problem generating the package use page */ - protected void generatePackageUseFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { HtmlTree body = getBody(); Content mainContent = new ContentBuilder(); if (usingPackageToUsedClasses.isEmpty()) { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java index 038f4c5292d..66a686bea08 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java @@ -100,12 +100,8 @@ public PackageWriter(HtmlConfiguration configuration, PackageElement packageElem computePackageData(); } - /** - * Build the package summary. - * - * @throws DocletException if there is a problem while building the documentation - */ - public void build() throws DocletException { + @Override + public void buildPage() throws DocletException { buildPackageDoc(); } @@ -174,7 +170,6 @@ protected void buildAllClassesAndInterfacesSummary(Content summariesList) { addAllClassesAndInterfacesSummary(summariesList); } - /** * Build the description of the summary. * @@ -328,7 +323,6 @@ protected void addRelatedPackagesSummary(Content summaryContent) { summaryContent, showModules); } - /** * Add all types to the content. * @@ -369,7 +363,7 @@ public void addAllClassesAndInterfacesSummary(Content target) { } } - public void addPackageSummary(List packages, Content label, + protected void addPackageSummary(List packages, Content label, TableHeader tableHeader, Content summaryContent, boolean showModules) { if (!packages.isEmpty()) { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PreviewListWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PreviewListWriter.java index 1e19b69a8c8..6003d3215f2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PreviewListWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PreviewListWriter.java @@ -38,8 +38,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.PreviewAPIListBuilder; @@ -53,26 +51,29 @@ public class PreviewListWriter extends SummaryListWriter * Constructor. * * @param configuration the configuration for this doclet - * @param filename the file to be generated */ - public PreviewListWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename, configuration.previewAPIListBuilder); + public PreviewListWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.PREVIEW_LIST, configuration.previewAPIListBuilder); } - /** - * Get list of all the preview elements. - * Then instantiate PreviewListWriter and generate File. - * - * @param configuration the current configuration of the doclet. - * @throws DocFileIOException if there is a problem writing the preview list - */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - if (configuration.conditionalPages.contains(HtmlConfiguration.ConditionalPage.PREVIEW)) { - DocPath filename = DocPaths.PREVIEW_LIST; - PreviewListWriter depr = new PreviewListWriter(configuration, filename); - depr.generateSummaryListFile(PageMode.PREVIEW, "preview elements", - configuration.contents.previewAPI, "doclet.Window_Preview_List"); - } + @Override + protected PageMode getPageMode() { + return PageMode.PREVIEW; + } + + @Override + protected String getDescription() { + return "preview elements"; + } + + @Override + protected Content getHeadContent() { + return configuration.contents.previewAPI; + } + + @Override + protected String getTitleKey() { + return "doclet.Window_Preview_List"; } @Override diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java index b650a54f4d6..26d45d715a2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java @@ -80,6 +80,8 @@ protected void buildPropertyDoc(Content detailsList) { Content propertyContent = getPropertyHeaderContent(currentProperty); buildSignature(propertyContent); + buildDeprecationInfo(propertyContent); + buildPreviewInfo(propertyContent); buildPropertyComments(propertyContent); buildTagInfo(propertyContent); @@ -90,31 +92,19 @@ protected void buildPropertyDoc(Content detailsList) { } } - /** - * Build the signature. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildSignature(Content propertyContent) { - propertyContent.add(getSignature(currentProperty)); + @Override + protected void buildSignature(Content target) { + target.add(getSignature(currentProperty)); } - /** - * Build the deprecation information. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content propertyContent) { - addDeprecated(currentProperty, propertyContent); + @Override + protected void buildDeprecationInfo(Content target) { + addDeprecated(currentProperty, target); } - /** - * Build the preview information. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content propertyContent) { - addPreview(currentProperty, propertyContent); + @Override + protected void buildPreviewInfo(Content target) { + addPreview(currentProperty, target); } /** @@ -156,9 +146,8 @@ protected void buildTagInfo(Content propertyContent) { } } - @Override - public Content getMemberSummaryHeader(TypeElement typeElement, Content content) { + public Content getMemberSummaryHeader(Content content) { content.add(MarkerComments.START_OF_PROPERTY_SUMMARY); Content memberContent = new ContentBuilder(); writer.addSummaryHeader(this, memberContent); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchWriter.java index 1e07f01deca..2e268101dd2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchWriter.java @@ -25,17 +25,16 @@ package jdk.javadoc.internal.doclets.formats.html; +import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlId; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; -import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; +import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; /** @@ -46,32 +45,13 @@ public class SearchWriter extends HtmlDocletWriter { /** * Constructor to construct SearchWriter object. * @param configuration the configuration - * @param filename file to be generated */ - public SearchWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename); + public SearchWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.SEARCH_PAGE); } - /** - * Constructs the SearchWriter object and then use it to generate the search - * file. The name of the generated file is "search.html". The search file - * will get generated if and only if "-noindex" is not used on the command line. - * - * @param configuration the configuration - * @throws DocFileIOException if there is a problem while generating the documentation - */ - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - DocPath filename = DocPaths.SEARCH_PAGE; - SearchWriter searchWriter = new SearchWriter(configuration, filename); - searchWriter.generateSearchFile(); - } - - /** - * Generates the search file contents. - * - * @throws DocFileIOException if there is a problem while generating the documentation - */ - protected void generateSearchFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { String title = resources.getText("doclet.Window_Search_title"); HtmlTree body = getBody(getWindowTitle(title)); ContentBuilder searchFileContent = new ContentBuilder(); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java index c709c963cff..758e0ee5214 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java @@ -26,7 +26,6 @@ package jdk.javadoc.internal.doclets.formats.html; import java.util.List; -import java.util.SortedSet; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; @@ -53,15 +52,11 @@ public SerialFieldWriter(SubWriterHolderWriter writer, TypeElement typeElement) super(writer, typeElement); } - public SortedSet members(TypeElement te) { - return utils.serializableFields(te); - } - protected Content getSerializableFieldsHeader() { return HtmlTree.UL(HtmlStyle.blockList); } - protected Content getFieldsContentHeader(boolean isLastContent) { + protected Content getFieldsContentHeader() { return new HtmlTree(TagName.LI).setStyle(HtmlStyle.blockList); } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java index caa400c9470..4af46f3ea01 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java @@ -49,7 +49,7 @@ protected Content getSerializableMethodsHeader() { return HtmlTree.UL(HtmlStyle.blockList); } - protected Content getMethodsContentHeader(boolean isLastContent) { + protected Content getMethodsContentHeader() { return new HtmlTree(TagName.LI); } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java index f1189c034ec..a0cbd4c5102 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java @@ -103,15 +103,11 @@ public SerializedFormWriter(HtmlConfiguration configuration) { configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.SERIALIZED_FORM); } - /** - * Build the serialized form. - * - * @throws DocletException if there is a problem while building the documentation - */ - void build() throws DocletException { - SortedSet rootclasses = new TreeSet<>(utils.comparators.generalPurposeComparator()); - rootclasses.addAll(configuration.getIncludedTypeElements()); - if (!serialClassFoundToDocument(rootclasses)) { + @Override + public void buildPage() throws DocletException { + var rootClasses = new TreeSet(utils.comparators.generalPurposeComparator()); + rootClasses.addAll(configuration.getIncludedTypeElements()); + if (!serialClassFoundToDocument(rootClasses)) { //Nothing to document. return; } @@ -250,9 +246,9 @@ protected void buildClassContent(Content target) { */ protected void buildSerializableMethods(Content target) { Content serializableMethodsHeader = methodWriter.getSerializableMethodsHeader(); - for (var i = utils.serializationMethods(currentTypeElement).iterator(); i.hasNext(); ) { - currentMember = i.next(); - Content methodsContent = methodWriter.getMethodsContentHeader(!i.hasNext()); + for (var executableElement : utils.serializationMethods(currentTypeElement)) { + currentMember = executableElement; + Content methodsContent = methodWriter.getMethodsContentHeader(); buildMethodSubHeader(methodsContent); buildDeprecatedMethodInfo(methodsContent); @@ -360,7 +356,7 @@ public void buildFieldSerializationOverview(TypeElement typeElement, Content cla // information to be printed. if (fieldWriter.shouldPrintOverview(ve)) { Content serializableFieldsHeader = fieldWriter.getSerializableFieldsHeader(); - Content fieldsOverviewContent = fieldWriter.getFieldsContentHeader(true); + Content fieldsOverviewContent = fieldWriter.getFieldsContentHeader(); fieldWriter.addMemberDeprecatedInfo(ve, fieldsOverviewContent); if (!options.noComment()) { fieldWriter.addMemberDescription(ve, fieldsOverviewContent); @@ -383,10 +379,10 @@ protected void buildSerializableFields(Content target) { Collection members = utils.serializableFields(currentTypeElement); if (!members.isEmpty()) { Content serializableFieldsHeader = fieldWriter.getSerializableFieldsHeader(); - for (var i = members.iterator(); i.hasNext();) { - currentMember = i.next(); + for (var member : members) { + currentMember = member; if (!utils.definesSerializableFields(currentTypeElement)) { - Content fieldsContent = fieldWriter.getFieldsContentHeader(!i.hasNext()); + Content fieldsContent = fieldWriter.getFieldsContentHeader(); buildFieldSubHeader(fieldsContent); buildFieldDeprecationInfo(fieldsContent); @@ -451,7 +447,7 @@ protected void buildSerialFieldTagsInfo(Content target) { for (SerialFieldTree tag : tags) { if (tag.getName() == null || tag.getType() == null) // ignore malformed @serialField tags continue; - Content fieldsContent = fieldWriter.getFieldsContentHeader(tag.equals(tags.last())); + Content fieldsContent = fieldWriter.getFieldsContentHeader(); TypeMirror type = ch.getReferencedType(tag); fieldWriter.addMemberHeader(type, tag.getName().getName().toString(), fieldsContent); fieldWriter.addMemberDescription(field, tag, fieldsContent); @@ -531,10 +527,10 @@ private static boolean serialDocInclude(Utils utils, Element element) { List serial = utils.getSerialTrees(element); if (!serial.isEmpty()) { // look for `@serial include|exclude` - String serialtext = Utils.toLowerCase(serial.get(0).toString()); - if (serialtext.contains("exclude")) { + var serialText = Utils.toLowerCase(serial.get(0).toString()); + if (serialText.contains("exclude")) { return false; - } else if (serialtext.contains("include")) { + } else if (serialText.contains("include")) { return true; } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SubWriterHolderWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SubWriterHolderWriter.java index 6cb71c49851..379bd72209f 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SubWriterHolderWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SubWriterHolderWriter.java @@ -42,7 +42,7 @@ /** * This abstract class exists to provide functionality needed in the - * the formatting of member information. Since AbstractSubWriter and its + * the formatting of member information. Since AbstractMemberWriter and its * subclasses control this, they would be the logical place to put this. * However, because each member type has its own subclass, subclassing * can not be used effectively to change formatting. The concrete @@ -192,22 +192,6 @@ public void addClassContent(Content source) { bodyContents.addMainContent(source); } - /** - * Add the annotation content. - * - * @param source annotation content which will be added to the documentation - */ - public void addAnnotationContent(Content source) { - addClassContent(source); - } - - /** - * {@return the member header} - */ - public Content getMemberHeader() { - return HtmlTree.UL(HtmlStyle.blockList); - } - /** * Returns a list to be used for the list of summaries for members of a given kind. * @@ -227,7 +211,6 @@ public Content getSummariesListItem(Content content) { return HtmlTree.LI(content); } - /** * Returns a list to be used for the list of details for members of a given kind. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SummaryListWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SummaryListWriter.java index 100c2454807..a4e43dffb76 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SummaryListWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SummaryListWriter.java @@ -46,6 +46,11 @@ /** * Base class for generating a summary page that lists elements with a common characteristic, * such as deprecated elements, preview elements, and so on. + * + * Note: the use of "Summary" in this context is distinct from the use of "summary" in the + * context of {@link AbstractMemberWriter#buildSummary(Content)}. + * + * @param a builder, to determine the elements to be included in the summary */ public abstract class SummaryListWriter extends SubWriterHolderWriter { @@ -100,22 +105,37 @@ public SummaryListWriter(HtmlConfiguration configuration, DocPath filename, B bu this.builder = builder; } + /** + * {@return the page mode to use} + */ + protected abstract PageMode getPageMode(); + + /** + * {@return the page descrition, for the {@code } element} + */ + protected abstract String getDescription(); + + /** + * {@return the heading for the page} + */ + protected abstract Content getHeadContent(); + + /** + * {@return the title for the page} + */ + protected abstract String getTitleKey(); + /** * Generate the API summary. * - * @param pageMode page mode to use - * @param description page description - * @param headContent page heading content - * @param titleKey page title resource key * @throws DocFileIOException if there is a problem writing the summary list */ - protected void generateSummaryListFile(PageMode pageMode, String description, - Content headContent, String titleKey) - throws DocFileIOException { - HtmlTree body = getHeader(pageMode, titleKey); + @Override + public void buildPage() throws DocFileIOException { + HtmlTree body = getHeader(getPageMode(), getTitleKey()); Content content = new ContentBuilder(); var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, - HtmlStyle.title, headContent); + HtmlStyle.title, getHeadContent()); content.add(HtmlTree.DIV(HtmlStyle.header, heading)); addContentSelectors(content); content.add(HtmlTree.HEADING_TITLE(Headings.CONTENT_HEADING, contents.contentsHeading)); @@ -147,7 +167,7 @@ protected void generateSummaryListFile(PageMode pageMode, String description, """).asContent()); bodyContents.setFooter(getFooter()); body.add(bodyContents); - printHtmlDocument(null, description, body); + printHtmlDocument(null, getDescription(), body); } /** @@ -181,9 +201,9 @@ public Content getContentsList() { } /** + * {@return the header for the API Summary listing} * @param pageMode page mode to use * @param titleKey page title resource key - * {@return the header for the API Summary listing} */ public HtmlTree getHeader(PageMode pageMode, String titleKey) { String title = resources.getText(titleKey); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SystemPropertiesWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SystemPropertiesWriter.java index 983fc6db0d4..b4b92566200 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SystemPropertiesWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SystemPropertiesWriter.java @@ -25,28 +25,32 @@ package jdk.javadoc.internal.doclets.formats.html; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; +import java.util.WeakHashMap; +import java.util.stream.Collectors; + +import javax.lang.model.element.Element; + import com.sun.source.doctree.DocTree; + +import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; -import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; +import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.DocletElement; import jdk.javadoc.internal.doclets.toolkit.OverviewElement; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; -import javax.lang.model.element.Element; -import java.nio.file.Path; -import java.util.*; -import java.util.Map.Entry; - import static java.util.stream.Collectors.groupingBy; -import java.util.stream.Collectors; -import java.util.ArrayList; /** * Generates the file with the summary of all the system properties. @@ -62,37 +66,22 @@ public class SystemPropertiesWriter extends HtmlDocletWriter { * Constructs SystemPropertiesWriter object. * * @param configuration The current configuration - * @param filename Path to the file which is getting generated. */ - public SystemPropertiesWriter(HtmlConfiguration configuration, DocPath filename) { - super(configuration, filename); + public SystemPropertiesWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.SYSTEM_PROPERTIES, false); } - public static void generate(HtmlConfiguration configuration) throws DocFileIOException { - generate(configuration, DocPaths.SYSTEM_PROPERTIES); - } - - private static void generate(HtmlConfiguration configuration, DocPath fileName) throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { boolean hasSystemProperties = configuration.mainIndex != null && !configuration.mainIndex.getItems(DocTree.Kind.SYSTEM_PROPERTY).isEmpty(); if (!hasSystemProperties) { - // Cannot defer this check any further, because of the super() call - // that prints out notices on creating files, etc. - // - // There is probably a better place for this kind of checks (see how - // this is achieved in other "optional" pages, like Constant Values - // and Serialized Form). return; } - SystemPropertiesWriter systemPropertiesGen = new SystemPropertiesWriter(configuration, fileName); - systemPropertiesGen.buildSystemPropertiesPage(); + + writeGenerating(); configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.SYSTEM_PROPERTIES); - } - /** - * Prints all the system properties to the file. - */ - protected void buildSystemPropertiesPage() throws DocFileIOException { String title = resources.getText("doclet.systemProperties"); HtmlTree body = getBody(getWindowTitle(title)); Content mainContent = new ContentBuilder(); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TreeWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TreeWriter.java index 0b0b25fe808..c5e0329e9e6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TreeWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TreeWriter.java @@ -63,38 +63,18 @@ public class TreeWriter extends AbstractTreeWriter { /** * Constructor to construct TreeWriter object. * - * @param configuration the current configuration of the doclet. - * @param filename String filename + * @param configuration the current configuration of the doclet * @param classTree the tree being built. */ - public TreeWriter(HtmlConfiguration configuration, DocPath filename, ClassTree classTree) { - super(configuration, filename, classTree); + public TreeWriter(HtmlConfiguration configuration, ClassTree classTree) { + super(configuration, DocPaths.OVERVIEW_TREE, classTree); packages = configuration.packages; classesOnly = packages.isEmpty(); this.bodyContents = new BodyContents(); } - /** - * Create a TreeWriter object and use it to generate the - * "overview-tree.html" file. - * - * @param configuration the configuration for this doclet - * @param classTree the class tree being documented. - * @throws DocFileIOException if there is a problem generating the overview tree page - */ - public static void generate(HtmlConfiguration configuration, - ClassTree classTree) throws DocFileIOException { - DocPath filename = DocPaths.OVERVIEW_TREE; - TreeWriter treegen = new TreeWriter(configuration, filename, classTree); - treegen.generateTreeFile(); - } - - /** - * Generate the interface hierarchy and class hierarchy. - * - * @throws DocFileIOException if there is a problem generating the overview tree page - */ - public void generateTreeFile() throws DocFileIOException { + @Override + public void buildPage() throws DocFileIOException { HtmlTree body = getBody(); Content headContent = contents.hierarchyForAllPackages; var heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactory.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactory.java index 5e6f1f4f9d2..d3704f856a2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactory.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactory.java @@ -26,16 +26,22 @@ package jdk.javadoc.internal.doclets.formats.html; +import java.util.List; + import javax.lang.model.element.Element; import javax.lang.model.element.ModuleElement; import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; +import jdk.javadoc.internal.doclets.toolkit.DocFileElement; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; +import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper; +import jdk.javadoc.internal.doclets.toolkit.util.DocPath; +import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** - * The factory that returns HTML writers. + * The factory that returns HTML writers, to be used to generate pages in the overall API documentation. */ public class WriterFactory { @@ -46,39 +52,152 @@ public WriterFactory(HtmlConfiguration configuration) { } /** - * {@return a new {@link ConstantsSummaryWriter}} + * {@return a new writer for the page for a module} */ - public ConstantsSummaryWriter newConstantsSummaryWriter() { - return new ConstantsSummaryWriter(configuration); + public HtmlDocletWriter newModuleWriter(ModuleElement mdle) { + return new ModuleWriter(configuration, mdle); } /** - * {@return a new {@link PackageWriter}} + * {@return a new writer for the "module index" page} */ - public PackageWriter newPackageWriter(PackageElement packageElement) { + public HtmlDocletWriter newModuleIndexWriter() { + return new ModuleIndexWriter(configuration); + } + + /** + * {@return a new writer for the page for a package} + */ + public HtmlDocletWriter newPackageWriter(PackageElement packageElement) { return new PackageWriter(configuration, packageElement); } /** - * {@return a new {@link ModuleWriter}} + * {@return a new writer for the "package index" page} */ - public ModuleWriter newModuleWriter(ModuleElement mdle) { - return new ModuleWriter(configuration, mdle); + public HtmlDocletWriter newPackageIndexWriter() { + return new PackageIndexWriter(configuration); + } + + /** + * {@return a new writer for the "package use" page for a package} + */ + public HtmlDocletWriter newPackageUseWriter(PackageElement packageElement, ClassUseMapper mapper) { + return new PackageUseWriter(configuration, mapper, packageElement); } /** - * {@return a new {@link ClassWriter}} + * {@return a new writer for the page for a class or other type element} */ - public ClassWriter newClassWriter(TypeElement typeElement, ClassTree classTree) { + public HtmlDocletWriter newClassWriter(TypeElement typeElement, ClassTree classTree) { return new ClassWriter(configuration, typeElement, classTree); } + + /** + * {@return a new writer for the "class use" page for a class or other type element} + */ + public HtmlDocletWriter newClassUseWriter(TypeElement typeElement, ClassUseMapper mapper) { + return new ClassUseWriter(configuration, mapper, typeElement); + } + + /** + * {@return a new writer for the list of "all classes"} + */ + public HtmlDocletWriter newAllClassesIndexWriter(IndexBuilder indexBuilder) { + return new AllClassesIndexWriter(configuration, indexBuilder); + } + + /** + * {@return a new writer for the list of "all packages"} + */ + public HtmlDocletWriter newAllPackagesIndexWriter() { + return new AllPackagesIndexWriter(configuration); + } + + /** + * {@return a new writer for the "constants summary" page} + */ + public HtmlDocletWriter newConstantsSummaryWriter() { + return new ConstantsSummaryWriter(configuration); + } + + /** + * {@return a new writer for the page giving the API that has been deprecated in recent releases} + */ + public HtmlDocletWriter newDeprecatedListWriter() { + return new DeprecatedListWriter(configuration); + } + + /** + * {@return a new writer for a "doc-file" page} + */ + public HtmlDocletWriter newDocFileWriter(DocPath path, DocFileElement dfElement) { + return new DocFilesHandler.DocFileWriter(configuration, path, dfElement); + } + + /** + * {@return a new writer for the page listing external specifications referenced in the API} + */ + public HtmlDocletWriter newExternalSpecsWriter() { + return new ExternalSpecsWriter(configuration); + } + + /** + * {@return a new writer for the "help" page} + */ + public HtmlDocletWriter newHelpWriter() { + return new HelpWriter(configuration); + } + /** - * {@return a new {@link SerializedFormWriter}} + * {@return a new writer for an "index" page} */ - public SerializedFormWriter newSerializedFormWriter() { + public HtmlDocletWriter newIndexWriter(DocPath path, List allFirstCharacters, List displayFirstCharacters) { + return new IndexWriter(configuration, path, allFirstCharacters, displayFirstCharacters); + } + + /** + * {@return a new writer for the list of new API in recent releases} + */ + public HtmlDocletWriter newNewAPIListWriter() { + return new NewAPIListWriter(configuration); + } + + /** + * {@return a new writer for the list of preview API in this release} + */ + public HtmlDocletWriter newPreviewListWriter() { + return new PreviewListWriter(configuration); + } + + /** + * {@return a new writer for the "search" page} + */ + public HtmlDocletWriter newSearchWriter() { + return new SearchWriter(configuration); + } + + /** + * {@return a new writer for the page giving the serialized forms of classes and other type elements} + */ + public HtmlDocletWriter newSerializedFormWriter() { return new SerializedFormWriter(configuration); } + /** + * {@return a new writer for the page listing system properties referenced in the API} + */ + public HtmlDocletWriter newSystemPropertiesWriter() { + return new SystemPropertiesWriter(configuration); + } + + /** + * {@return a new writer for the page showing the hierarchy of classes and their superclasses} + */ + public HtmlDocletWriter newTreeWriter(ClassTree classTree) { + return new TreeWriter(configuration, classTree); + } + /** * Returns a new member writer for the members of a given class and given kind. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Entity.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Entity.java index 6ee4e157762..50ee53a2c75 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Entity.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Entity.java @@ -71,7 +71,6 @@ public int charCount() { return 1; } - /** * Escapes the special HTML characters in a given string using the appropriate * entities. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java index 60366487565..eeec1b182a4 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java @@ -304,7 +304,6 @@ private Content toContent() { return head; } - private Comment getGeneratedBy(boolean timestamp, ZonedDateTime buildDate) { String text = "Generated by javadoc"; // marker string, deliberately not localized text += " (" + docletVersion.feature() + ")"; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java index 39b87925d6e..3975bd7f3d9 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java @@ -38,27 +38,43 @@ */ public class DocFileElement implements DocletElement { + private final Element element; private final PackageElement packageElement; private final FileObject fo; + /** + * Creates a pseudo-element that wraps a {@code doc-files} HTML file. + * + * @param utils the standard utilities class + * @param element the module element or package element that "owns" the {@code doc-files} subdirectory + * @param fo the file object + * + * @throws IllegalArgumentException if the given element is not a module element or package element + */ public DocFileElement(Utils utils, Element element, FileObject fo) { + this.element = element; this.fo = fo; - switch(element.getKind()) { - case MODULE: + switch (element.getKind()) { + case MODULE -> { ModuleElement moduleElement = (ModuleElement) element; packageElement = utils.elementUtils.getPackageElement(moduleElement, ""); - break; + } - case PACKAGE: + case PACKAGE -> packageElement = (PackageElement) element; - break; - default: - throw new AssertionError("unknown kind: " + element.getKind()); + default -> throw new IllegalArgumentException(element.getKind() + ":" + element); } } + /** + * {@return the element that "owns" the {@code doc-files} directory} + */ + public Element getElement() { + return element; + } + @Override public PackageElement getPackageElement() { return packageElement; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java index 37e554b6d17..76963686e8a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java @@ -380,6 +380,11 @@ public boolean isFunctionalInterface(AnnotationMirror amirror) { .compareTo(SourceVersion.RELEASE_8) >= 0; } + public boolean isFunctionalInterface(TypeElement typeElement) { + return typeElement.getAnnotationMirrors().stream() + .anyMatch(this::isFunctionalInterface); + } + public boolean isUndocumentedEnclosure(TypeElement enclosingTypeElement) { return (isPackagePrivate(enclosingTypeElement) || isPrivate(enclosingTypeElement) || hasHiddenTag(enclosingTypeElement)) From c48068188c3071f3c2dababe72e308231033a478 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 2 Aug 2023 23:37:35 +0000 Subject: [PATCH 12/12] 8313576: GCC 7 reports compiler warning in bundled freetype 2.13.0 Reviewed-by: shade, prr --- make/modules/java.desktop/lib/Awt2dLibraries.gmk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/make/modules/java.desktop/lib/Awt2dLibraries.gmk b/make/modules/java.desktop/lib/Awt2dLibraries.gmk index 86ed069e345..2956076599f 100644 --- a/make/modules/java.desktop/lib/Awt2dLibraries.gmk +++ b/make/modules/java.desktop/lib/Awt2dLibraries.gmk @@ -448,6 +448,7 @@ else LIBFREETYPE_LIBS := -lfreetype endif + # gcc_ftobjs.c := maybe-uninitialized required for GCC 7 builds. $(eval $(call SetupJdkLibrary, BUILD_LIBFREETYPE, \ NAME := freetype, \ OPTIMIZATION := HIGHEST, \ @@ -456,6 +457,7 @@ else EXTRA_HEADER_DIRS := $(BUILD_LIBFREETYPE_HEADER_DIRS), \ DISABLED_WARNINGS_microsoft := 4267 4244 4996, \ DISABLED_WARNINGS_gcc := dangling-pointer stringop-overflow, \ + DISABLED_WARNINGS_gcc_ftobjs.c := maybe-uninitialized, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ ))