From 3c644dc586e8990607923a2cb56656d0d6bf45e4 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons <jjg@openjdk.org> Date: Fri, 21 Jul 2023 18:51:06 +0000 Subject: [PATCH] 8312044: Simplify toolkit Builder/Writer world Reviewed-by: prappo --- .../html/AbstractExecutableMemberWriter.java | 1 - .../formats/html/AbstractMemberWriter.java | 104 +- .../html/AbstractOverviewIndexWriter.java | 1 - .../formats/html/AbstractTreeWriter.java | 1 - .../formats/html/AllClassesIndexWriter.java | 7 +- .../formats/html/AllPackagesIndexWriter.java | 1 - ...l.java => AnnotationTypeMemberWriter.java} | 150 ++- .../doclets/formats/html/ClassUseWriter.java | 17 +- .../doclets/formats/html/ClassWriter.java | 1093 +++++++++++++++++ .../doclets/formats/html/ClassWriterImpl.java | 470 ------- .../formats/html/ConstantsSummaryWriter.java | 488 ++++++++ .../html/ConstantsSummaryWriterImpl.java | 260 ---- ...WriterImpl.java => ConstructorWriter.java} | 143 ++- .../{toolkit => formats/html}/Content.java | 2 +- .../doclets/formats/html/Contents.java | 3 +- .../formats/html/DeprecatedListWriter.java | 1 - ...sHandlerImpl.java => DocFilesHandler.java} | 8 +- ...riterImpl.java => EnumConstantWriter.java} | 130 +- .../formats/html/ExternalSpecsWriter.java | 53 +- ...{FieldWriterImpl.java => FieldWriter.java} | 132 +- .../doclets/formats/html/HelpWriter.java | 1 - .../formats/html/HtmlConfiguration.java | 21 +- .../doclets/formats/html/HtmlDoclet.java | 21 +- .../formats/html/HtmlDocletWriter.java | 35 +- .../doclets/formats/html/HtmlLinkFactory.java | 1 - .../doclets/formats/html/HtmlLinkInfo.java | 3 +- .../formats/html/IndexRedirectWriter.java | 1 - .../doclets/formats/html/IndexWriter.java | 1 - ...ethodWriterImpl.java => MethodWriter.java} | 157 ++- .../formats/html/ModuleIndexWriter.java | 1 - ...oduleWriterImpl.java => ModuleWriter.java} | 138 ++- .../doclets/formats/html/Navigation.java | 5 +- ...WriterImpl.java => NestedClassWriter.java} | 9 +- .../formats/html/NewAPIListWriter.java | 1 - .../formats/html/PackageIndexWriter.java | 1 - .../formats/html/PackageTreeWriter.java | 1 - .../formats/html/PackageUseWriter.java | 1 - ...kageWriterImpl.java => PackageWriter.java} | 147 ++- .../formats/html/PreviewListWriter.java | 1 - ...rtyWriterImpl.java => PropertyWriter.java} | 146 ++- .../doclets/formats/html/SearchWriter.java | 1 - ...ieldWriter.java => SerialFieldWriter.java} | 34 +- ...hodWriter.java => SerialMethodWriter.java} | 33 +- .../html/SerializedFormWriter.java} | 293 +++-- .../html/SerializedFormWriterImpl.java | 244 ---- .../doclets/formats/html/Signatures.java | 5 +- .../formats/html/SourceToHTMLConverter.java | 1 - .../formats/html/SubWriterHolderWriter.java | 7 +- .../formats/html/SummaryListWriter.java | 13 +- .../formats/html/SystemPropertiesWriter.java | 1 - .../internal/doclets/formats/html/Table.java | 1 - .../doclets/formats/html/TableHeader.java | 1 - .../doclets/formats/html/TreeWriter.java | 1 - .../doclets/formats/html/WriterFactory.java | 133 ++ .../formats/html/WriterFactoryImpl.java | 162 --- .../formats/html/markup/BodyContents.java | 2 +- .../doclets/formats/html/markup/Comment.java | 2 +- .../formats/html/markup/ContentBuilder.java | 2 +- .../doclets/formats/html/markup/Entity.java | 2 +- .../doclets/formats/html/markup/Head.java | 2 +- .../formats/html/markup/HtmlDocument.java | 2 +- .../doclets/formats/html/markup/HtmlTree.java | 2 +- .../doclets/formats/html/markup/Links.java | 2 +- .../doclets/formats/html/markup/RawHtml.java | 2 +- .../doclets/formats/html/markup/Script.java | 5 +- .../doclets/formats/html/markup/Text.java | 2 +- .../formats/html/markup/TextBuilder.java | 2 +- .../formats/html/taglets/BaseTaglet.java | 2 +- .../html/taglets/DeprecatedTaglet.java | 2 +- .../formats/html/taglets/DocRootTaglet.java | 2 +- .../formats/html/taglets/IndexTaglet.java | 2 +- .../html/taglets/InheritDocTaglet.java | 2 +- .../formats/html/taglets/LinkTaglet.java | 6 +- .../formats/html/taglets/LiteralTaglet.java | 2 +- .../formats/html/taglets/ParamTaglet.java | 2 +- .../formats/html/taglets/ReturnTaglet.java | 2 +- .../formats/html/taglets/SeeTaglet.java | 12 +- .../formats/html/taglets/SimpleTaglet.java | 8 +- .../formats/html/taglets/SnippetTaglet.java | 2 +- .../formats/html/taglets/SpecTaglet.java | 2 +- .../formats/html/taglets/SummaryTaglet.java | 2 +- .../html/taglets/SystemPropertyTaglet.java | 2 +- .../doclets/formats/html/taglets/Taglet.java | 2 +- .../formats/html/taglets/TagletWriter.java | 2 +- .../formats/html/taglets/ThrowsTaglet.java | 2 +- .../formats/html/taglets/UserTaglet.java | 2 +- .../formats/html/taglets/ValueTaglet.java | 2 +- .../doclets/toolkit/AbstractDoclet.java | 10 +- .../toolkit/AnnotationTypeMemberWriter.java | 119 -- .../doclets/toolkit/BaseConfiguration.java | 25 - .../internal/doclets/toolkit/ClassWriter.java | 228 ---- .../toolkit/ConstantsSummaryWriter.java | 129 -- .../doclets/toolkit/ConstructorWriter.java | 107 -- .../doclets/toolkit/DocFilesHandler.java | 39 - .../doclets/toolkit/EnumConstantWriter.java | 111 -- .../internal/doclets/toolkit/FieldWriter.java | 106 -- .../doclets/toolkit/MemberSummaryWriter.java | 114 -- .../doclets/toolkit/MemberWriter.java | 47 - .../doclets/toolkit/MethodWriter.java | 108 -- .../doclets/toolkit/ModuleSummaryWriter.java | 121 -- .../doclets/toolkit/NestedClassWriter.java | 32 - .../doclets/toolkit/PackageSummaryWriter.java | 127 -- .../doclets/toolkit/PropertyUtils.java | 105 ++ .../doclets/toolkit/PropertyWriter.java | 99 -- .../doclets/toolkit/SerializedFormWriter.java | 303 ----- .../doclets/toolkit/WriterFactory.java | 180 --- .../toolkit/builders/AbstractBuilder.java | 108 -- .../builders/AbstractMemberBuilder.java | 94 -- .../builders/AnnotationTypeMemberBuilder.java | 209 ---- .../toolkit/builders/BuilderFactory.java | 199 --- .../toolkit/builders/ClassBuilder.java | 476 ------- .../builders/ConstantsSummaryBuilder.java | 314 ----- .../toolkit/builders/ConstructorBuilder.java | 188 --- .../toolkit/builders/EnumConstantBuilder.java | 191 --- .../toolkit/builders/FieldBuilder.java | 190 --- .../builders/MemberSummaryBuilder.java | 448 ------- .../toolkit/builders/MethodBuilder.java | 196 --- .../builders/ModuleSummaryBuilder.java | 181 --- .../builders/PackageSummaryBuilder.java | 189 --- .../toolkit/builders/PropertyBuilder.java | 211 ---- .../toolkit/builders/package-info.java | 35 - .../jdk/javadoc/internal/package-info.java | 14 +- .../doclet/testMetadata/TestMetadata.java | 22 +- 123 files changed, 3226 insertions(+), 6923 deletions(-) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{AnnotationTypeMemberWriterImpl.java => AnnotationTypeMemberWriter.java} (67%) create mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java create mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriterImpl.java rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{ConstructorWriterImpl.java => ConstructorWriter.java} (60%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/{toolkit => formats/html}/Content.java (99%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{DocFilesHandlerImpl.java => DocFilesHandler.java} (97%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{EnumConstantWriterImpl.java => EnumConstantWriter.java} (60%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{FieldWriterImpl.java => FieldWriter.java} (64%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{MethodWriterImpl.java => MethodWriter.java} (73%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{ModuleWriterImpl.java => ModuleWriter.java} (90%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{NestedClassWriterImpl.java => NestedClassWriter.java} (93%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{PackageWriterImpl.java => PackageWriter.java} (79%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{PropertyWriterImpl.java => PropertyWriter.java} (62%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{HtmlSerialFieldWriter.java => SerialFieldWriter.java} (83%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/{HtmlSerialMethodWriter.java => SerialMethodWriter.java} (81%) rename src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/{toolkit/builders/SerializedFormBuilder.java => formats/html/SerializedFormWriter.java} (67%) delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java create mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactory.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AnnotationTypeMemberWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ClassWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstantsSummaryWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstructorWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFilesHandler.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/EnumConstantWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/FieldWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberSummaryWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MethodWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ModuleSummaryWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/NestedClassWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PackageSummaryWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractMemberBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeMemberBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstantsSummaryBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstructorBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/EnumConstantBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/FieldBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MemberSummaryBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MethodBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PropertyBuilder.java delete mode 100644 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/package-info.java 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 64e7448be8f..406d163219c 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 @@ -43,7 +43,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.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import static jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo.Kind.LINK_TYPE_PARAMS; import static jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS; 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 c00a00c008a..347bcff1175 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 @@ -42,16 +42,14 @@ 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.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.MemberWriter; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.Utils; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** * The base class for member writers. */ -public abstract class AbstractMemberWriter implements MemberSummaryWriter, MemberWriter { +public abstract class AbstractMemberWriter { protected final HtmlConfiguration configuration; protected final HtmlOptions options; @@ -80,6 +78,33 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe this(writer, null); } + /** + * 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); + /** + * Adds the given summary to the list of summaries. + * + * @param summariesList the list of summaries + * @param content the summary + */ + public abstract void addSummary(Content summariesList, Content content); + + /** + * Returns a list of visible elements of the specified kind in this + * type element. + * @param kind of members + * @return a list of members + */ + protected List<Element> getVisibleMembers(VisibleMemberTable.Kind kind) { + return configuration.getVisibleMemberTable(typeElement).getVisibleMembers(kind); + } + /* ----- abstracts ----- */ /** @@ -340,11 +365,17 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe } } - @Override + /** + * Adds the member summary for the given class and member. + * + * @param tElement the class the summary belongs to + * @param member the member that is documented + * @param firstSentenceTrees the tags for the sentence being documented + */ public void addMemberSummary(TypeElement tElement, Element member, List<? extends DocTree> firstSentenceTrees) { if (tElement != typeElement) { - throw new IllegalStateException(); + throw new IllegalStateException(tElement + ", " + typeElement); } var table = getSummaryTable(); List<Content> rowContents = new ArrayList<>(); @@ -361,26 +392,50 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe table.addRow(member, rowContents); } - @Override + /** + * Adds the inherited member summary for the given class and member. + * + * @param tElement the class the inherited member belongs to + * @param member the inherited member that is being documented + * @param isFirst true if this is the first member in the list + * @param isLast true if this is the last member in the list + * @param content the content to which the links will be added + */ public void addInheritedMemberSummary(TypeElement tElement, - Element nestedClass, boolean isFirst, boolean isLast, + Element member, boolean isFirst, boolean isLast, Content content) { - writer.addInheritedMemberSummary(this, tElement, nestedClass, isFirst, content); + writer.addInheritedMemberSummary(this, tElement, member, isFirst, content); } - @Override + /** + * Returns the inherited member summary header for the given class. + * + * @param tElement the class the summary belongs to + * + * @return the inherited member summary header + */ public Content getInheritedSummaryHeader(TypeElement tElement) { Content c = writer.getMemberInherited(); writer.addInheritedSummaryHeader(this, tElement, c); return c; } - @Override + /** + * Returns the inherited summary links. + * + * @return the inherited summary links + */ public Content getInheritedSummaryLinks() { return new HtmlTree(TagName.CODE); } - @Override + /** + * Returns the summary table for the given class. + * + * @param tElement the class the summary table belongs to + * + * @return the summary table + */ public Content getSummaryTable(TypeElement tElement) { if (tElement != typeElement) { throw new IllegalStateException(); @@ -388,18 +443,33 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe return getSummaryTable(); } - @Override + /** + * Returns the member content. + * + * @param memberContent the content representing the member + * + * @return the member content + */ public Content getMember(Content memberContent) { return writer.getMember(memberContent); } - @Override - public Content getMemberList() { + /** + * {@return a list to add member items to} + * + * @see #getMemberListItem(Content) + */ + protected Content getMemberList() { return writer.getMemberList(); } - @Override - public Content getMemberListItem(Content memberContent) { + /** + * {@return a member item} + * + * @param memberContent the member to represent as an item + * @see #getMemberList() + */ + protected Content getMemberListItem(Content memberContent) { return writer.getMemberListItem(memberContent); } 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 343eac6914b..b92b270a399 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 @@ -31,7 +31,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.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractTreeWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractTreeWriter.java index 7443de707fa..2968ce29897 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractTreeWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractTreeWriter.java @@ -28,7 +28,6 @@ package jdk.javadoc.internal.doclets.formats.html; 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.TagName; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree.Hierarchy; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 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 f20222a11e1..f2145751600 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 @@ -37,7 +37,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.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; @@ -117,10 +116,10 @@ public class AllClassesIndexWriter extends HtmlDocletWriter { .setId(HtmlIds.ALL_CLASSES_TABLE) .setDefaultTab(contents.allClassesAndInterfacesLabel) .addTab(contents.interfaces, utils::isPlainInterface) - .addTab(contents.classes, e -> utils.isNonThrowableClass(e)) + .addTab(contents.classes, utils::isNonThrowableClass) .addTab(contents.enums, utils::isEnum) - .addTab(contents.records, e -> utils.isRecord(e)) - .addTab(contents.exceptionClasses, e -> utils.isThrowable(e)) + .addTab(contents.records, utils::isRecord) + .addTab(contents.exceptionClasses, utils::isThrowable) .addTab(contents.annotationTypes, utils::isAnnotationInterface); for (Character unicode : indexBuilder.getFirstCharacters()) { for (IndexItem indexItem : indexBuilder.getItems(unicode)) { 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 fae37013e03..b0569bc47cb 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 @@ -33,7 +33,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.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java similarity index 67% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java index 0b9d3893a79..ad39bceea8b 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeMemberWriter.java @@ -37,16 +37,15 @@ 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.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeMemberWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; +import jdk.javadoc.internal.doclets.toolkit.BaseOptions; +import jdk.javadoc.internal.doclets.toolkit.DocletException; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** * Writes annotation interface member documentation in HTML format. */ -public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter - implements AnnotationTypeMemberWriter, MemberSummaryWriter { +public class AnnotationTypeMemberWriter extends AbstractMemberWriter { /** * We generate separate summaries for required and optional annotation interface members, @@ -61,12 +60,18 @@ public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter private final Kind kind; + /** + * The index of the current member that is being documented at this point + * in time. + */ + protected Element currentMember; + /** * Constructs a new AnnotationTypeMemberWriterImpl for any kind of member. * * @param writer The writer for the class that the member belongs to. */ - public AnnotationTypeMemberWriterImpl(SubWriterHolderWriter writer) { + public AnnotationTypeMemberWriter(SubWriterHolderWriter writer) { super(writer); this.kind = Kind.ANY; } @@ -78,13 +83,110 @@ public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter * @param annotationType the AnnotationType that holds this member. * @param kind the kind of annotation interface members to handle. */ - public AnnotationTypeMemberWriterImpl(SubWriterHolderWriter writer, - TypeElement annotationType, - Kind kind) { + public AnnotationTypeMemberWriter(SubWriterHolderWriter writer, + TypeElement annotationType, + Kind kind) { super(writer, annotationType); this.kind = kind; } + public void build(Content target) throws DocletException { + buildAnnotationTypeMember(target); + } + + /** + * Build the member documentation. + * + * @param target the content to which the documentation will be added + */ + protected void buildAnnotationTypeMember(Content target) { + // In contrast to the annotation interface member summaries the details generated + // by this builder share a single list for both required and optional members. + var members = getVisibleMembers(VisibleMemberTable.Kind.ANNOTATION_TYPE_MEMBER); + if (!members.isEmpty()) { + addAnnotationDetailsMarker(target); + Content annotationDetailsHeader = getAnnotationDetailsHeader(); + Content memberList = getMemberList(); + + for (Element member : members) { + currentMember = member; + Content annotationContent = getAnnotationHeaderContent(currentMember); + + buildAnnotationTypeMemberChildren(annotationContent); + + memberList.add(writer.getMemberListItem(annotationContent)); + } + Content annotationDetails = getAnnotationDetails(annotationDetailsHeader, memberList); + target.add(annotationDetails); + } + } + + protected void buildAnnotationTypeMemberChildren(Content annotationContent) { + buildSignature(annotationContent); + buildDeprecationInfo(annotationContent); + buildPreviewInfo(annotationContent); + buildMemberComments(annotationContent); + buildTagInfo(annotationContent); + buildDefaultValueInfo(annotationContent); + } + + /** + * Build the signature. + * + * @param target the content to which the documentation will be added + */ + 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); + } + + /** + * Build the preview information. + * + * @param annotationContent the content to which the documentation will be added + */ + protected void buildPreviewInfo(Content annotationContent) { + addPreview(currentMember, annotationContent); + } + + /** + * Build the comments for the member. Do nothing if + * {@link BaseOptions#noComment()} is set to true. + * + * @param annotationContent the content to which the documentation will be added + */ + protected void buildMemberComments(Content annotationContent) { + if (!options.noComment()) { + addComments(currentMember, annotationContent); + } + } + + /** + * Build the tag information. + * + * @param annotationContent the content to which the documentation will be added + */ + protected void buildTagInfo(Content annotationContent) { + addTags(currentMember, annotationContent); + } + + /** + * Build the default value for this optional member. + * + * @param annotationContent the content to which the documentation will be added + */ + protected void buildDefaultValueInfo(Content annotationContent) { + addDefaultValueInfo(currentMember, annotationContent); + } + @Override public Content getMemberSummaryHeader(TypeElement typeElement, Content content) { @@ -102,8 +204,7 @@ public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter return c; } - @Override - public Content getMemberHeader() { + protected Content getMemberHeader() { return writer.getMemberHeader(); } @@ -118,15 +219,13 @@ public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter summariesList, content); } - @Override - public void addAnnotationDetailsMarker(Content memberDetails) { + protected void addAnnotationDetailsMarker(Content memberDetails) { memberDetails.add(selectComment( MarkerComments.START_OF_ANNOTATION_TYPE_DETAILS, MarkerComments.START_OF_ANNOTATION_INTERFACE_DETAILS)); } - @Override - public Content getAnnotationDetailsHeader() { + protected Content getAnnotationDetailsHeader() { Content memberDetails = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, contents.annotationTypeDetailsLabel); @@ -134,8 +233,7 @@ public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter return memberDetails; } - @Override - public Content getAnnotationHeaderContent(Element member) { + protected Content getAnnotationHeaderContent(Element member) { Content content = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, Text.of(name(member))); @@ -144,36 +242,30 @@ public class AnnotationTypeMemberWriterImpl extends AbstractMemberWriter .setId(htmlIds.forMember(typeElement, (ExecutableElement) member)); } - @Override - public Content getSignature(Element member) { + protected Content getSignature(Element member) { return new Signatures.MemberSignature(member, this) .setType(getType(member)) .setAnnotations(writer.getAnnotationInfo(member, true)) .toContent(); } - @Override - public void addDeprecated(Element member, Content target) { + protected void addDeprecated(Element member, Content target) { addDeprecatedInfo(member, target); } - @Override - public void addPreview(Element member, Content content) { + protected void addPreview(Element member, Content content) { addPreviewInfo(member, content); } - @Override - public void addComments(Element member, Content annotationContent) { + protected void addComments(Element member, Content annotationContent) { addComment(member, annotationContent); } - @Override - public void addTags(Element member, Content annotationContent) { + protected void addTags(Element member, Content annotationContent) { writer.addTagsInfo(member, annotationContent); } - @Override - public Content getAnnotationDetails(Content annotationDetailsHeader, Content annotationDetails) { + protected Content getAnnotationDetails(Content annotationDetailsHeader, Content annotationDetails) { Content c = new ContentBuilder(annotationDetailsHeader, annotationDetails); return getMember(HtmlTree.SECTION(HtmlStyle.memberDetails, c)); } 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 6009d11d15b..0be5dba6980 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,7 +43,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.Navigation.PageMode; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; @@ -81,10 +80,10 @@ public class ClassUseWriter extends SubWriterHolderWriter { final Map<PackageElement, List<Element>> pkgToConstructorArgTypeParameter; final Map<PackageElement, List<Element>> pkgToConstructorThrows; final SortedSet<PackageElement> pkgSet; - final MethodWriterImpl methodSubWriter; - final ConstructorWriterImpl constrSubWriter; - final FieldWriterImpl fieldSubWriter; - final NestedClassWriterImpl classSubWriter; + final MethodWriter methodSubWriter; + final ConstructorWriter constrSubWriter; + final FieldWriter fieldSubWriter; + final NestedClassWriter classSubWriter; /** * Constructor. @@ -132,11 +131,11 @@ public class ClassUseWriter extends SubWriterHolderWriter { + pkgSet + " with: " + mapper.classToPackage.get(this.typeElement)); } - methodSubWriter = new MethodWriterImpl(this); - constrSubWriter = new ConstructorWriterImpl(this); + methodSubWriter = new MethodWriter(this); + constrSubWriter = new ConstructorWriter(this); constrSubWriter.setFoundNonPubConstructor(true); - fieldSubWriter = new FieldWriterImpl(this); - classSubWriter = new NestedClassWriterImpl(this); + fieldSubWriter = new FieldWriter(this); + classSubWriter = new NestedClassWriter(this); } /** 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 new file mode 100644 index 00000000000..4028285de15 --- /dev/null +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriter.java @@ -0,0 +1,1093 @@ +/* + * Copyright (c) 1997, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.javadoc.internal.doclets.formats.html; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.SortedSet; +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; +import javax.lang.model.element.Name; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.SimpleElementVisitor8; + +import com.sun.source.doctree.DeprecatedTree; +import com.sun.source.doctree.DocTree; + +import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; +import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; +import jdk.javadoc.internal.doclets.formats.html.markup.Entity; +import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; +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.TagName; +import jdk.javadoc.internal.doclets.formats.html.markup.Text; +import jdk.javadoc.internal.doclets.toolkit.CommentUtils; +import jdk.javadoc.internal.doclets.toolkit.DocletException; +import jdk.javadoc.internal.doclets.toolkit.PropertyUtils; +import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; +import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; +import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; +import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; +import jdk.javadoc.internal.doclets.toolkit.util.DocPath; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; + +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.ANNOTATION_TYPE_MEMBER_OPTIONAL; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.ANNOTATION_TYPE_MEMBER_REQUIRED; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.CONSTRUCTORS; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.ENUM_CONSTANTS; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.FIELDS; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.METHODS; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.NESTED_CLASSES; +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.PROPERTIES; + +/** + * Generate the Class Information Page. + * + * @see javax.lang.model.element.TypeElement + */ +public class ClassWriter extends SubWriterHolderWriter { + + private static final Set<String> suppressSubtypesSet + = Set.of("java.lang.Object", + "org.omg.CORBA.Object"); + + private static final Set<String> suppressImplementingSet + = Set.of("java.lang.Cloneable", + "java.lang.constant.Constable", + "java.lang.constant.ConstantDesc", + "java.io.Serializable"); + + protected final TypeElement typeElement; + protected final VisibleMemberTable visibleMemberTable; + + protected final ClassTree classTree; + + private final Comparator<Element> summariesComparator; + private final PropertyUtils.PropertyHelper pHelper; + + /** + * @param configuration the configuration data for the doclet + * @param typeElement the class being documented. + * @param classTree the class tree for the given class. + */ + public ClassWriter(HtmlConfiguration configuration, TypeElement typeElement, + ClassTree classTree) { + super(configuration, configuration.docPaths.forClass(typeElement)); + this.typeElement = typeElement; + configuration.currentTypeElement = typeElement; + this.classTree = classTree; + + visibleMemberTable = configuration.getVisibleMemberTable(typeElement); + summariesComparator = utils.comparators.makeIndexElementComparator(); + pHelper = new PropertyUtils.PropertyHelper(configuration, typeElement); + + switch (typeElement.getKind()) { + case ENUM -> setEnumDocumentation(typeElement); + case RECORD -> setRecordDocumentation(typeElement); + } + } + + public void build() throws DocletException { + buildClassDoc(); + } + + /** + * Handles the {@literal <TypeElement>} tag. + * + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildClassDoc() throws DocletException { + String key = switch (typeElement.getKind()) { + case INTERFACE -> "doclet.Interface"; + case ENUM -> "doclet.Enum"; + case RECORD -> "doclet.RecordClass"; + case ANNOTATION_TYPE -> "doclet.AnnotationType"; + case CLASS -> "doclet.Class"; + default -> throw new IllegalStateException(typeElement.getKind() + " " + typeElement); + }; + Content content = getHeader(resources.getText(key) + " " + utils.getSimpleName(typeElement)); + Content classContent = getClassContentHeader(); + + buildClassTree(classContent); + buildClassInfo(classContent); + buildMemberSummary(classContent); + buildMemberDetails(classContent); + + addClassContent(classContent); + addFooter(); + printDocument(content); + copyDocFiles(); + } + + /** + * Build the class inheritance tree documentation. + * + * @param classContent the content to which the documentation will be added + */ + protected void buildClassTree(Content classContent) { + addClassTree(classContent); + } + + /** + * Build the class information documentation. + * + * @param target the content to which the documentation will be added + */ + protected void buildClassInfo(Content target) { + Content c = getOutputInstance(); + buildParamInfo(c); + buildSuperInterfacesInfo(c); + buildImplementedInterfacesInfo(c); + buildSubClassInfo(c); + buildSubInterfacesInfo(c); + buildInterfaceUsageInfo(c); + buildNestedClassInfo(c); + buildFunctionalInterfaceInfo(c); + buildClassSignature(c); + buildDeprecationInfo(c); + buildClassDescription(c); + buildClassTagInfo(c); + + target.add(getClassInfo(c)); + } + + /** + * Build the type parameters and state components of this class. + * + * @param target the content to which the documentation will be added + */ + protected void buildParamInfo(Content target) { + addParamInfo(target); + } + + /** + * If this is an interface, list all superinterfaces. + * + * @param target the content to which the documentation will be added + */ + protected void buildSuperInterfacesInfo(Content target) { + addSuperInterfacesInfo(target); + } + + /** + * If this is a class, list all interfaces implemented by this class. + * + * @param target the content to which the documentation will be added + */ + protected void buildImplementedInterfacesInfo(Content target) { + addImplementedInterfacesInfo(target); + } + + /** + * List all the classes that extend this one. + * + * @param target the content to which the documentation will be added + */ + protected void buildSubClassInfo(Content target) { + addSubClassInfo(target); + } + + /** + * List all the interfaces that extend this one. + * + * @param target the content to which the documentation will be added + */ + protected void buildSubInterfacesInfo(Content target) { + addSubInterfacesInfo(target); + } + + /** + * If this is an interface, list all classes that implement this interface. + * + * @param target the content to which the documentation will be added + */ + protected void buildInterfaceUsageInfo(Content target) { + addInterfaceUsageInfo(target); + } + + /** + * If this is a functional interface, display appropriate message. + * + * @param target the content to which the documentation will be added + */ + protected void buildFunctionalInterfaceInfo(Content target) { + addFunctionalInterfaceInfo(target); + } + + /** + * If this class is deprecated, build the appropriate information. + * + * @param target the content to which the documentation will be added + */ + protected void buildDeprecationInfo(Content target) { + addClassDeprecationInfo(target); + } + + /** + * If this is an inner class or interface, list the enclosing class or interface. + * + * @param target the content to which the documentation will be added + */ + protected void buildNestedClassInfo(Content target) { + addNestedClassInfo(target); + } + + /** + * Copy the doc files. + * + * @throws DocFileIOException if there is a problem while copying the files + */ + private void copyDocFiles() throws DocletException { + PackageElement containingPackage = utils.containingPackage(typeElement); + var containingPackagesSeen = configuration.getContainingPackagesSeen(); + if ((configuration.packages == null || + !configuration.packages.contains(containingPackage)) && + !containingPackagesSeen.contains(containingPackage)) { + //Only copy doc files dir if the containing package is not + //documented AND if we have not documented a class from the same + //package already. Otherwise, we are making duplicate copies. + var docFilesHandler = configuration + .getWriterFactory() + .getDocFilesHandler(containingPackage); + docFilesHandler.copyDocFiles(); + containingPackagesSeen.add(containingPackage); + } + } + + /** + * Build the signature of the current class. + * + * @param target the content to which the documentation will be added + */ + protected void buildClassSignature(Content target) { + addClassSignature(target); + } + + /** + * Build the class description. + * + * @param target the content to which the documentation will be added + */ + protected void buildClassDescription(Content target) { + addClassDescription(target); + } + + /** + * Build the tag information for the current class. + * + * @param target the content to which the documentation will be added + */ + protected void buildClassTagInfo(Content target) { + addClassTagInfo(target); + } + + /** + * Build the member summary contents of the page. + * + * @param classContent the content to which the documentation will be added + */ + protected void buildMemberSummary(Content classContent) { + Content summariesList = getSummariesList(); + buildSummaries(summariesList); + classContent.add(getMemberSummary(summariesList)); + } + + protected void buildSummaries(Content target) { + buildPropertiesSummary(target); + buildNestedClassesSummary(target); + buildEnumConstantsSummary(target); + buildAnnotationTypeRequiredMemberSummary(target); + buildAnnotationTypeOptionalMemberSummary(target); + buildFieldsSummary(target); + buildConstructorsSummary(target); + buildMethodsSummary(target); + } + + /** + * Builds the summary for any optional members of an annotation type. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildAnnotationTypeOptionalMemberSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(ANNOTATION_TYPE_MEMBER_OPTIONAL); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getAnnotationTypeOptionalMemberWriter(this); + addSummary(writer, ANNOTATION_TYPE_MEMBER_OPTIONAL, false, summariesList); + } + + /** + * Builds the summary for any required members of an annotation type. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildAnnotationTypeRequiredMemberSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(ANNOTATION_TYPE_MEMBER_REQUIRED); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getAnnotationTypeRequiredMemberWriter(this); + addSummary(writer, ANNOTATION_TYPE_MEMBER_REQUIRED, false, summariesList); + } + + /** + * Builds the summary for any enum constants of an enum type. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildEnumConstantsSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(ENUM_CONSTANTS); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getEnumConstantWriter(this); + addSummary(writer, ENUM_CONSTANTS, false, summariesList); + } + + /** + * Builds the summary for any fields. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildFieldsSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(FIELDS); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getFieldWriter(this); + addSummary(writer, FIELDS, true, summariesList); + } + + /** + * Builds the summary for any properties. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildPropertiesSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(PROPERTIES); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getPropertyWriter(this); + addSummary(writer, PROPERTIES, true, summariesList); + } + + /** + * Builds the summary for any nested classes. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildNestedClassesSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(NESTED_CLASSES); + var writerFactory = configuration.getWriterFactory(); + var writer = new NestedClassWriter(this, typeElement); // TODO: surprising omission from WriterFactory + addSummary(writer, NESTED_CLASSES, true, summariesList); + } + + /** + * Builds the summary for any methods. + * + * @param summariesList the content to which the documentation will be added + */ + protected void buildMethodsSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(METHODS); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getMethodWriter(this); + addSummary(writer, METHODS, true, summariesList); + } + + /** + * Builds the summary for any constructors. + * + * @param summariesList the content to which the documentation will be added + */ + protected void buildConstructorsSummary(Content summariesList) { +// MemberSummaryWriter writer = memberSummaryWriters.get(CONSTRUCTORS); + var writerFactory = configuration.getWriterFactory(); + var writer = writerFactory.getConstructorWriter(this); + addSummary(writer, CONSTRUCTORS, false, summariesList); + } + + + /** + * Adds the summary for the documentation. + * + * @param writer the writer for this member summary + * @param kind the kind of members to document + * @param showInheritedSummary true if a summary of any inherited elements should be documented + * @param summariesList the list of summaries to which the summary will be added + */ + private void addSummary(AbstractMemberWriter writer, + VisibleMemberTable.Kind kind, + boolean showInheritedSummary, + Content summariesList) + { + // TODO: could infer the writer from the kind + // TODO: why LinkedList? + List<Content> summaryTreeList = new LinkedList<>(); + buildSummary(writer, kind, summaryTreeList); + if (showInheritedSummary) + buildInheritedSummary(writer, kind, summaryTreeList); + if (!summaryTreeList.isEmpty()) { + Content member = writer.getMemberSummaryHeader(typeElement, summariesList); + summaryTreeList.forEach(member::add); + writer.addSummary(summariesList, member); + } + } + + /** + * Build the member summary for the given members. + * + * @param writer the summary writer to write the output. + * @param kind the kind of members to summarize. + * @param summaryTreeList the list of contents to which the documentation will be added + */ + private void buildSummary(AbstractMemberWriter writer, + VisibleMemberTable.Kind kind, List<Content> summaryTreeList) { + SortedSet<? extends Element> members = asSortedSet(visibleMemberTable.getVisibleMembers(kind)); + if (!members.isEmpty()) { + for (Element member : members) { + final Element property = pHelper.getPropertyElement(member); + if (property != null && member instanceof ExecutableElement ee) { + configuration.cmtUtils.updatePropertyMethodComment(ee, property); + } + if (utils.isMethod(member)) { + var docFinder = utils.docFinder(); + Optional<List<? extends DocTree>> r = docFinder.search((ExecutableElement) member, (m -> { + var firstSentenceTrees = utils.getFirstSentenceTrees(m); + Optional<List<? extends DocTree>> optional = firstSentenceTrees.isEmpty() ? Optional.empty() : Optional.of(firstSentenceTrees); + return DocFinder.Result.fromOptional(optional); + })).toOptional(); + // The fact that we use `member` for possibly unrelated tags is suspicious + writer.addMemberSummary(typeElement, member, r.orElse(List.of())); + } else { + writer.addMemberSummary(typeElement, member, utils.getFirstSentenceTrees(member)); + } + } + summaryTreeList.add(writer.getSummaryTable(typeElement)); + } + } + + /** + * Build the inherited member summary for the given methods. + * + * @param writer the writer for this member summary. + * @param kind the kind of members to document. + * @param targets the list of contents to which the documentation will be added + */ + private void buildInheritedSummary(AbstractMemberWriter writer, + VisibleMemberTable.Kind kind, List<Content> targets) { + SortedSet<? extends Element> inheritedMembersFromMap = asSortedSet(visibleMemberTable.getAllVisibleMembers(kind)); + + for (TypeElement inheritedClass : visibleMemberTable.getVisibleTypeElements()) { + if (!(utils.isPublic(inheritedClass) || utils.isLinkable(inheritedClass))) { + continue; + } + if (Objects.equals(inheritedClass, typeElement)) { + continue; + } + if (utils.hasHiddenTag(inheritedClass)) { + continue; + } + + List<? extends Element> members = inheritedMembersFromMap.stream() + .filter(e -> Objects.equals(utils.getEnclosingTypeElement(e), inheritedClass)) + .toList(); + + if (!members.isEmpty()) { + SortedSet<Element> inheritedMembers = new TreeSet<>(summariesComparator); + inheritedMembers.addAll(members); + Content inheritedHeader = writer.getInheritedSummaryHeader(inheritedClass); + Content links = writer.getInheritedSummaryLinks(); + addSummaryFootNote(inheritedClass, inheritedMembers, links, writer); + inheritedHeader.add(links); + targets.add(inheritedHeader); + } + } + } + + private void addSummaryFootNote(TypeElement inheritedClass, Iterable<Element> inheritedMembers, + Content links, AbstractMemberWriter writer) { + boolean isFirst = true; + for (var iterator = inheritedMembers.iterator(); iterator.hasNext(); ) { + var member = iterator.next(); + TypeElement t = utils.isUndocumentedEnclosure(inheritedClass) + ? typeElement : inheritedClass; + writer.addInheritedMemberSummary(t, member, isFirst, !iterator.hasNext(), links); + isFirst = false; + } + } + + private SortedSet<? extends Element> asSortedSet(Collection<? extends Element> members) { + SortedSet<Element> out = new TreeSet<>(summariesComparator); + out.addAll(members); + return out; + } + + /** + * Build the member details contents of the page. + * + * @param classContent the content to which the documentation will be added + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildMemberDetails(Content classContent) throws DocletException { + Content detailsList = getDetailsList(); + + buildEnumConstantsDetails(detailsList); + buildPropertyDetails(detailsList); + buildFieldDetails(detailsList); + buildConstructorDetails(detailsList); + buildAnnotationTypeMemberDetails(detailsList); + buildMethodDetails(detailsList); + + classContent.add(getMemberDetails(detailsList)); + } + + /** + * Build the enum constants documentation. + * + * @param detailsList the content to which the documentation will be added + */ + protected void buildEnumConstantsDetails(Content detailsList) { + var writerFactory = configuration.getWriterFactory(); + var enumConstantWriter = writerFactory.getEnumConstantWriter(this); + enumConstantWriter.build(detailsList); + } + + /** + * Build the field documentation. + * + * @param detailsList the content to which the documentation will be added + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildFieldDetails(Content detailsList) throws DocletException { + var writerFactory = configuration.getWriterFactory(); + var fieldWriter = writerFactory.getFieldWriter(this); + fieldWriter.build(detailsList); + } + + /** + * Build the property documentation. + * + * @param detailsList the content to which the documentation will be added + */ + public void buildPropertyDetails( Content detailsList) { + var writerFactory = configuration.getWriterFactory(); + var propertyWriter = writerFactory.getPropertyWriter(this); + propertyWriter.build(detailsList); + } + + /** + * Build the constructor documentation. + * + * @param detailsList the content to which the documentation will be added + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildConstructorDetails(Content detailsList) throws DocletException { + var writerFactory = configuration.getWriterFactory(); + var constructorWriter = writerFactory.getConstructorWriter(this); + constructorWriter.build(detailsList); + } + + /** + * Build the method documentation. + * + * @param detailsList the content to which the documentation will be added + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildMethodDetails(Content detailsList) throws DocletException { + var writerFactory = configuration.getWriterFactory(); + var methodWriter = writerFactory.getMethodWriter(this); + methodWriter.build(detailsList); + } + + /** + * Build the annotation type optional member documentation. + * + * @param target the content to which the documentation will be added + * @throws DocletException if there is a problem building the documentation + */ + protected void buildAnnotationTypeMemberDetails(Content target) + throws DocletException { + var writerFactory = configuration.getWriterFactory(); + var annotationTypeMemberWriter = writerFactory.getAnnotationTypeMemberWriter(this); + annotationTypeMemberWriter.build(target); + } + + /** + * The documentation for values() and valueOf() in Enums are set by the + * doclet only iff the user or overridden methods are missing. + * @param elem the enum element + */ + private void setEnumDocumentation(TypeElement elem) { + CommentUtils cmtUtils = configuration.cmtUtils; + for (ExecutableElement ee : utils.getMethods(elem)) { + if (!utils.getFullBody(ee).isEmpty()) // ignore if already set + continue; + Name name = ee.getSimpleName(); + if (name.contentEquals("values") && ee.getParameters().isEmpty()) { + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setEnumValuesTree(ee); + } else if (name.contentEquals("valueOf") && ee.getParameters().size() == 1) { + // TODO: check parameter type + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setEnumValueOfTree(ee); + } + } + } + + /** + * Sets the documentation as needed for the mandated parts of a record type. + * This includes the canonical constructor, methods like {@code equals}, + * {@code hashCode}, {@code toString}, the accessor methods, and the underlying + * field. + * @param elem the record element + */ + + private void setRecordDocumentation(TypeElement elem) { + CommentUtils cmtUtils = configuration.cmtUtils; + Set<Name> componentNames = elem.getRecordComponents().stream() + .map(Element::getSimpleName) + .collect(Collectors.toSet()); + + for (ExecutableElement ee : utils.getConstructors(elem)) { + if (utils.isCanonicalRecordConstructor(ee)) { + if (utils.getFullBody(ee).isEmpty()) { + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setRecordConstructorTree(ee); + } + // only one canonical constructor; no need to keep looking + break; + } + } + + var fields = utils.isSerializable(elem) + ? utils.getFieldsUnfiltered(elem) + : utils.getFields(elem); + for (VariableElement ve : fields) { + // The fields for the record component cannot be declared by the + // user and so cannot have any pre-existing comment. + Name name = ve.getSimpleName(); + if (componentNames.contains(name)) { + utils.removeCommentHelper(ve); // purge previous entry + cmtUtils.setRecordFieldTree(ve); + } + } + + TypeMirror objectType = utils.getObjectType(); + + for (ExecutableElement ee : utils.getMethods(elem)) { + if (!utils.getFullBody(ee).isEmpty()) { + continue; + } + + Name name = ee.getSimpleName(); + List<? extends VariableElement> params = ee.getParameters(); + if (name.contentEquals("equals")) { + if (params.size() == 1 && utils.typeUtils.isSameType(params.get(0).asType(), objectType)) { + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setRecordEqualsTree(ee); + } + } else if (name.contentEquals("hashCode")) { + if (params.isEmpty()) { + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setRecordHashCodeTree(ee); + } + } else if (name.contentEquals("toString")) { + if (params.isEmpty()) { + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setRecordToStringTree(ee); + } + } else if (componentNames.contains(name)) { + if (params.isEmpty()) { + utils.removeCommentHelper(ee); // purge previous entry + cmtUtils.setRecordAccessorTree(ee); + } + } + } + + } + + // TODO: inline this + public Content getOutputInstance() { + return new ContentBuilder(); + } + + protected Content getHeader(String header) { + HtmlTree body = getBody(getWindowTitle(utils.getSimpleName(typeElement))); + var div = HtmlTree.DIV(HtmlStyle.header); + if (configuration.showModules) { + ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(typeElement); + var classModuleLabel = HtmlTree.SPAN(HtmlStyle.moduleLabelInType, contents.moduleLabel); + var moduleNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classModuleLabel); + moduleNameDiv.add(Entity.NO_BREAK_SPACE); + moduleNameDiv.add(getModuleLink(mdle, + Text.of(mdle.getQualifiedName()))); + div.add(moduleNameDiv); + } + PackageElement pkg = utils.containingPackage(typeElement); + if (!pkg.isUnnamed()) { + var classPackageLabel = HtmlTree.SPAN(HtmlStyle.packageLabelInType, contents.packageLabel); + var pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classPackageLabel); + pkgNameDiv.add(Entity.NO_BREAK_SPACE); + Content pkgNameContent = getPackageLink(pkg, getLocalizedPackageName(pkg)); + pkgNameDiv.add(pkgNameContent); + div.add(pkgNameDiv); + } + HtmlLinkInfo linkInfo = new HtmlLinkInfo(configuration, + HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS_AND_BOUNDS, typeElement) + .linkToSelf(false); // Let's not link to ourselves in the header + var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, + HtmlStyle.title, Text.of(header)); + heading.add(getTypeParameterLinks(linkInfo)); + div.add(heading); + bodyContents.setHeader(getHeader(PageMode.CLASS, typeElement)) + .addMainContent(MarkerComments.START_OF_CLASS_DATA) + .addMainContent(div); + return body; + } + + protected Content getClassContentHeader() { + return getContentHeader(); + } + + @Override + protected Navigation getNavBar(PageMode pageMode, Element element) { + Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(element), + contents.moduleLabel); + return super.getNavBar(pageMode, element) + .setNavLinkModule(linkContent) + .setSubNavLinks(() -> { + List<Content> list = new ArrayList<>(); + VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); + Set<VisibleMemberTable.Kind> summarySet = + VisibleMemberTable.Kind.forSummariesOf(element.getKind()); + for (VisibleMemberTable.Kind kind : summarySet) { + list.add(links.createLink(HtmlIds.forMemberSummary(kind), + contents.getNavLinkLabelContent(kind), vmt.hasVisibleMembers(kind))); + } + return list; + }); + } + + protected void addFooter() { + bodyContents.addMainContent(MarkerComments.END_OF_CLASS_DATA); + bodyContents.setFooter(getFooter()); + } + + protected void printDocument(Content content) throws DocFileIOException { + String description = getDescription("declaration", typeElement); + PackageElement pkg = utils.containingPackage(typeElement); + List<DocPath> localStylesheets = getLocalStylesheets(pkg); + content.add(bodyContents); + printHtmlDocument(configuration.metakeywords.getMetaKeywords(typeElement), + description, localStylesheets, content); + } + + protected Content getClassInfo(Content classInfo) { + return getMember(HtmlIds.CLASS_DESCRIPTION, HtmlStyle.classDescription, classInfo); + } + + @Override + public TypeElement getCurrentPageElement() { + return typeElement; + } + + protected void addClassSignature(Content classInfo) { + classInfo.add(new HtmlTree(TagName.HR)); + classInfo.add(new Signatures.TypeSignature(typeElement, this) + .toContent()); + } + + protected void addClassDescription(Content classInfo) { + addPreviewInfo(classInfo); + if (!options.noComment()) { + // generate documentation for the class. + if (!utils.getFullBody(typeElement).isEmpty()) { + addInlineComment(typeElement, classInfo); + } + } + } + + private void addPreviewInfo(Content content) { + addPreviewInfo(typeElement, content); + } + + protected void addClassTagInfo(Content classInfo) { + if (!options.noComment()) { + // Print Information about all the tags here + addTagsInfo(typeElement, classInfo); + } + } + + /** + * Get the class inheritance tree for the given class. + * + * @param type the class to get the inheritance tree for + * @return the class inheritance tree + */ + private Content getClassInheritanceTreeContent(TypeMirror type) { + TypeMirror sup; + HtmlTree classTree = null; + do { + sup = utils.getFirstVisibleSuperClass(type); + var entry = HtmlTree.DIV(HtmlStyle.inheritance, getClassHelperContent(type)); + if (classTree != null) + entry.add(classTree); + classTree = entry; + type = sup; + } while (sup != null); + classTree.put(HtmlAttr.TITLE, contents.getContent("doclet.Inheritance_Tree").toString()); + return classTree; + } + + /** + * Get the class helper for the given class. + * + * @param type the class to get the helper for + * @return the class helper + */ + private Content getClassHelperContent(TypeMirror type) { + Content result = new ContentBuilder(); + if (utils.typeUtils.isSameType(type, typeElement.asType())) { + Content typeParameters = getTypeParameterLinks( + new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, + typeElement)); + if (configuration.shouldExcludeQualifier(utils.containingPackage(typeElement).toString())) { + result.add(utils.asTypeElement(type).getSimpleName()); + result.add(typeParameters); + } else { + result.add(utils.asTypeElement(type).getQualifiedName()); + result.add(typeParameters); + } + } else { + Content link = getLink(new HtmlLinkInfo(configuration, + HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, type) + .label(configuration.getClassName(utils.asTypeElement(type)))); + result.add(link); + } + return result; + } + + protected void addClassTree(Content target) { + if (!utils.isClass(typeElement)) { + return; + } + target.add(getClassInheritanceTreeContent(typeElement.asType())); + } + + protected void addParamInfo(Content target) { + if (utils.hasBlockTag(typeElement, DocTree.Kind.PARAM)) { + var t = configuration.tagletManager.getTaglet(DocTree.Kind.PARAM); + Content paramInfo = t.getAllBlockTagOutput(typeElement, getTagletWriterInstance(false)); + if (!paramInfo.isEmpty()) { + target.add(HtmlTree.DL(HtmlStyle.notes, paramInfo)); + } + } + } + + protected void addSubClassInfo(Content target) { + if (utils.isClass(typeElement)) { + for (String s : suppressSubtypesSet) { + if (typeElement.getQualifiedName().contentEquals(s)) { + return; // Don't generate the list, too huge + } + } + Set<TypeElement> subclasses = classTree.hierarchy(typeElement).subtypes(typeElement); + if (!subclasses.isEmpty()) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(contents.subclassesLabel)); + dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.PLAIN, subclasses))); + target.add(dl); + } + } + } + + protected void addSubInterfacesInfo(Content target) { + if (utils.isPlainInterface(typeElement)) { + Set<TypeElement> subInterfaces = classTree.hierarchy(typeElement).allSubtypes(typeElement); + if (!subInterfaces.isEmpty()) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(contents.subinterfacesLabel)); + dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, subInterfaces))); + target.add(dl); + } + } + } + + protected void addInterfaceUsageInfo(Content target) { + if (!utils.isPlainInterface(typeElement)) { + return; + } + for (String s : suppressImplementingSet) { + if (typeElement.getQualifiedName().contentEquals(s)) { + return; // Don't generate the list, too huge + } + } + Set<TypeElement> implcl = classTree.implementingClasses(typeElement); + if (!implcl.isEmpty()) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(contents.implementingClassesLabel)); + dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.PLAIN, implcl))); + target.add(dl); + } + } + + protected void addImplementedInterfacesInfo(Content target) { + SortedSet<TypeMirror> interfaces = new TreeSet<>(comparators.makeTypeMirrorClassUseComparator()); + interfaces.addAll(utils.getAllInterfaces(typeElement)); + if (utils.isClass(typeElement) && !interfaces.isEmpty()) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(contents.allImplementedInterfacesLabel)); + dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, interfaces))); + target.add(dl); + } + } + + protected void addSuperInterfacesInfo(Content target) { + SortedSet<TypeMirror> interfaces = + new TreeSet<>(comparators.makeTypeMirrorIndexUseComparator()); + interfaces.addAll(utils.getAllInterfaces(typeElement)); + + if (utils.isPlainInterface(typeElement) && !interfaces.isEmpty()) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(contents.allSuperinterfacesLabel)); + dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, interfaces))); + target.add(dl); + } + } + + protected void addNestedClassInfo(final Content target) { + Element outerClass = typeElement.getEnclosingElement(); + if (outerClass == null) + return; + new SimpleElementVisitor8<Void, Void>() { + @Override + public Void visitType(TypeElement e, Void p) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(utils.isPlainInterface(e) + ? contents.enclosingInterfaceLabel + : contents.enclosingClassLabel)); + dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, List.of(e)))); + target.add(dl); + return null; + } + }.visit(outerClass); + } + + protected void addFunctionalInterfaceInfo (Content target) { + if (isFunctionalInterface()) { + var dl = HtmlTree.DL(HtmlStyle.notes); + dl.add(HtmlTree.DT(contents.functionalInterface)); + var dd = new HtmlTree(TagName.DD); + dd.add(contents.functionalInterfaceMessage); + dl.add(dd); + target.add(dl); + } + } + + public boolean isFunctionalInterface() { + List<? extends AnnotationMirror> annotationMirrors = typeElement.getAnnotationMirrors(); + for (AnnotationMirror anno : annotationMirrors) { + if (utils.isFunctionalInterface(anno)) { + return true; + } + } + return false; + } + + + protected void addClassDeprecationInfo(Content classInfo) { + List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(typeElement); + if (utils.isDeprecated(typeElement)) { + var deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(typeElement)); + var div = HtmlTree.DIV(HtmlStyle.deprecationBlock, deprLabel); + if (!deprs.isEmpty()) { + CommentHelper ch = utils.getCommentHelper(typeElement); + DocTree dt = deprs.get(0); + List<? extends DocTree> commentTags = ch.getBody(dt); + if (!commentTags.isEmpty()) { + addInlineDeprecatedComment(typeElement, deprs.get(0), div); + } + } + classInfo.add(div); + } + } + + /** + * Get the links to the given classes. + * + * @param context the id of the context where the links will be added + * @param list the classes + * @return the links + */ + private Content getClassLinks(HtmlLinkInfo.Kind context, Collection<?> list) { + Content content = new ContentBuilder(); + boolean isFirst = true; + for (Object type : list) { + if (!isFirst) { + content.add(Text.of(", ")); + } else { + isFirst = false; + } + // TODO: should we simply split this method up to avoid instanceof ? + if (type instanceof TypeElement te) { + Content link = getLink( + new HtmlLinkInfo(configuration, context, te)); + content.add(HtmlTree.CODE(link)); + } else { + Content link = getLink( + new HtmlLinkInfo(configuration, context, ((TypeMirror)type))); + content.add(HtmlTree.CODE(link)); + } + } + return content; + } + + /** + * Return the TypeElement being documented. + * + * @return the TypeElement being documented. + */ + public TypeElement getTypeElement() { + return typeElement; + } + + protected Content getMemberDetails(Content content) { + var section = HtmlTree.SECTION(HtmlStyle.details, content); + // The following id is required by the Navigation bar + if (utils.isAnnotationInterface(typeElement)) { + section.setId(HtmlIds.ANNOTATION_TYPE_ELEMENT_DETAIL); + } + return section; + } +} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java deleted file mode 100644 index 8884cc3d6dd..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java +++ /dev/null @@ -1,470 +0,0 @@ -/* - * Copyright (c) 1997, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.formats.html; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.lang.model.element.AnnotationMirror; -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 javax.lang.model.type.TypeMirror; -import javax.lang.model.util.SimpleElementVisitor8; - -import com.sun.source.doctree.DeprecatedTree; -import com.sun.source.doctree.DocTree; - -import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; -import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; -import jdk.javadoc.internal.doclets.formats.html.markup.Entity; -import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; -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.TagName; -import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.ClassWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; -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.VisibleMemberTable; - -/** - * Generate the Class Information Page. - * - * @see javax.lang.model.element.TypeElement - */ -public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWriter { - - private static final Set<String> suppressSubtypesSet - = Set.of("java.lang.Object", - "org.omg.CORBA.Object"); - - private static final Set<String> suppressImplementingSet - = Set.of("java.lang.Cloneable", - "java.lang.constant.Constable", - "java.lang.constant.ConstantDesc", - "java.io.Serializable"); - - protected final TypeElement typeElement; - - protected final ClassTree classTree; - - /** - * @param configuration the configuration data for the doclet - * @param typeElement the class being documented. - * @param classTree the class tree for the given class. - */ - public ClassWriterImpl(HtmlConfiguration configuration, TypeElement typeElement, - ClassTree classTree) { - super(configuration, configuration.docPaths.forClass(typeElement)); - this.typeElement = typeElement; - configuration.currentTypeElement = typeElement; - this.classTree = classTree; - } - - @Override - public Content getOutputInstance() { - return new ContentBuilder(); - } - - @Override - public Content getHeader(String header) { - HtmlTree body = getBody(getWindowTitle(utils.getSimpleName(typeElement))); - var div = HtmlTree.DIV(HtmlStyle.header); - if (configuration.showModules) { - ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(typeElement); - var classModuleLabel = HtmlTree.SPAN(HtmlStyle.moduleLabelInType, contents.moduleLabel); - var moduleNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classModuleLabel); - moduleNameDiv.add(Entity.NO_BREAK_SPACE); - moduleNameDiv.add(getModuleLink(mdle, - Text.of(mdle.getQualifiedName()))); - div.add(moduleNameDiv); - } - PackageElement pkg = utils.containingPackage(typeElement); - if (!pkg.isUnnamed()) { - var classPackageLabel = HtmlTree.SPAN(HtmlStyle.packageLabelInType, contents.packageLabel); - var pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classPackageLabel); - pkgNameDiv.add(Entity.NO_BREAK_SPACE); - Content pkgNameContent = getPackageLink(pkg, getLocalizedPackageName(pkg)); - pkgNameDiv.add(pkgNameContent); - div.add(pkgNameDiv); - } - HtmlLinkInfo linkInfo = new HtmlLinkInfo(configuration, - HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS_AND_BOUNDS, typeElement) - .linkToSelf(false); // Let's not link to ourselves in the header - var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, - HtmlStyle.title, Text.of(header)); - heading.add(getTypeParameterLinks(linkInfo)); - div.add(heading); - bodyContents.setHeader(getHeader(PageMode.CLASS, typeElement)) - .addMainContent(MarkerComments.START_OF_CLASS_DATA) - .addMainContent(div); - return body; - } - - @Override - public Content getClassContentHeader() { - return getContentHeader(); - } - - @Override - protected Navigation getNavBar(PageMode pageMode, Element element) { - Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(element), - contents.moduleLabel); - return super.getNavBar(pageMode, element) - .setNavLinkModule(linkContent) - .setSubNavLinks(() -> { - List<Content> list = new ArrayList<>(); - VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); - Set<VisibleMemberTable.Kind> summarySet = - VisibleMemberTable.Kind.forSummariesOf(element.getKind()); - for (VisibleMemberTable.Kind kind : summarySet) { - list.add(links.createLink(HtmlIds.forMemberSummary(kind), - contents.getNavLinkLabelContent(kind), vmt.hasVisibleMembers(kind))); - } - return list; - }); - } - - @Override - public void addFooter() { - bodyContents.addMainContent(MarkerComments.END_OF_CLASS_DATA); - bodyContents.setFooter(getFooter()); - } - - @Override - public void printDocument(Content content) throws DocFileIOException { - String description = getDescription("declaration", typeElement); - PackageElement pkg = utils.containingPackage(typeElement); - List<DocPath> localStylesheets = getLocalStylesheets(pkg); - content.add(bodyContents); - printHtmlDocument(configuration.metakeywords.getMetaKeywords(typeElement), - description, localStylesheets, content); - } - - @Override - public Content getClassInfo(Content classInfo) { - return getMember(HtmlIds.CLASS_DESCRIPTION, HtmlStyle.classDescription, classInfo); - } - - @Override - public TypeElement getCurrentPageElement() { - return typeElement; - } - - @Override - public void addClassSignature(Content classInfo) { - classInfo.add(new HtmlTree(TagName.HR)); - classInfo.add(new Signatures.TypeSignature(typeElement, this) - .toContent()); - } - - - @Override - public void addClassDescription(Content classInfo) { - addPreviewInfo(classInfo); - if (!options.noComment()) { - // generate documentation for the class. - if (!utils.getFullBody(typeElement).isEmpty()) { - addInlineComment(typeElement, classInfo); - } - } - } - - private void addPreviewInfo(Content content) { - addPreviewInfo(typeElement, content); - } - - @Override - public void addClassTagInfo(Content classInfo) { - if (!options.noComment()) { - // Print Information about all the tags here - addTagsInfo(typeElement, classInfo); - } - } - - /** - * Get the class inheritance tree for the given class. - * - * @param type the class to get the inheritance tree for - * @return the class inheritance tree - */ - private Content getClassInheritanceTreeContent(TypeMirror type) { - TypeMirror sup; - HtmlTree classTree = null; - do { - sup = utils.getFirstVisibleSuperClass(type); - var entry = HtmlTree.DIV(HtmlStyle.inheritance, getClassHelperContent(type)); - if (classTree != null) - entry.add(classTree); - classTree = entry; - type = sup; - } while (sup != null); - classTree.put(HtmlAttr.TITLE, contents.getContent("doclet.Inheritance_Tree").toString()); - return classTree; - } - - /** - * Get the class helper for the given class. - * - * @param type the class to get the helper for - * @return the class helper - */ - private Content getClassHelperContent(TypeMirror type) { - Content result = new ContentBuilder(); - if (utils.typeUtils.isSameType(type, typeElement.asType())) { - Content typeParameters = getTypeParameterLinks( - new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, - typeElement)); - if (configuration.shouldExcludeQualifier(utils.containingPackage(typeElement).toString())) { - result.add(utils.asTypeElement(type).getSimpleName()); - result.add(typeParameters); - } else { - result.add(utils.asTypeElement(type).getQualifiedName()); - result.add(typeParameters); - } - } else { - Content link = getLink(new HtmlLinkInfo(configuration, - HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, type) - .label(configuration.getClassName(utils.asTypeElement(type)))); - result.add(link); - } - return result; - } - - @Override - public void addClassTree(Content target) { - if (!utils.isClass(typeElement)) { - return; - } - target.add(getClassInheritanceTreeContent(typeElement.asType())); - } - - @Override - public void addParamInfo(Content target) { - if (utils.hasBlockTag(typeElement, DocTree.Kind.PARAM)) { - var t = configuration.tagletManager.getTaglet(DocTree.Kind.PARAM); - Content paramInfo = t.getAllBlockTagOutput(typeElement, getTagletWriterInstance(false)); - if (!paramInfo.isEmpty()) { - target.add(HtmlTree.DL(HtmlStyle.notes, paramInfo)); - } - } - } - - @Override - public void addSubClassInfo(Content target) { - if (utils.isClass(typeElement)) { - for (String s : suppressSubtypesSet) { - if (typeElement.getQualifiedName().contentEquals(s)) { - return; // Don't generate the list, too huge - } - } - Set<TypeElement> subclasses = classTree.hierarchy(typeElement).subtypes(typeElement); - if (!subclasses.isEmpty()) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(contents.subclassesLabel)); - dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.PLAIN, subclasses))); - target.add(dl); - } - } - } - - @Override - public void addSubInterfacesInfo(Content target) { - if (utils.isPlainInterface(typeElement)) { - Set<TypeElement> subInterfaces = classTree.hierarchy(typeElement).allSubtypes(typeElement); - if (!subInterfaces.isEmpty()) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(contents.subinterfacesLabel)); - dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, subInterfaces))); - target.add(dl); - } - } - } - - @Override - public void addInterfaceUsageInfo(Content target) { - if (!utils.isPlainInterface(typeElement)) { - return; - } - for (String s : suppressImplementingSet) { - if (typeElement.getQualifiedName().contentEquals(s)) { - return; // Don't generate the list, too huge - } - } - Set<TypeElement> implcl = classTree.implementingClasses(typeElement); - if (!implcl.isEmpty()) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(contents.implementingClassesLabel)); - dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.PLAIN, implcl))); - target.add(dl); - } - } - - @Override - public void addImplementedInterfacesInfo(Content target) { - SortedSet<TypeMirror> interfaces = new TreeSet<>(comparators.makeTypeMirrorClassUseComparator()); - interfaces.addAll(utils.getAllInterfaces(typeElement)); - if (utils.isClass(typeElement) && !interfaces.isEmpty()) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(contents.allImplementedInterfacesLabel)); - dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, interfaces))); - target.add(dl); - } - } - - @Override - public void addSuperInterfacesInfo(Content target) { - SortedSet<TypeMirror> interfaces = - new TreeSet<>(comparators.makeTypeMirrorIndexUseComparator()); - interfaces.addAll(utils.getAllInterfaces(typeElement)); - - if (utils.isPlainInterface(typeElement) && !interfaces.isEmpty()) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(contents.allSuperinterfacesLabel)); - dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS, interfaces))); - target.add(dl); - } - } - - @Override - public void addNestedClassInfo(final Content target) { - Element outerClass = typeElement.getEnclosingElement(); - if (outerClass == null) - return; - new SimpleElementVisitor8<Void, Void>() { - @Override - public Void visitType(TypeElement e, Void p) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(utils.isPlainInterface(e) - ? contents.enclosingInterfaceLabel - : contents.enclosingClassLabel)); - dl.add(HtmlTree.DD(getClassLinks(HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, List.of(e)))); - target.add(dl); - return null; - } - }.visit(outerClass); - } - - @Override - public void addFunctionalInterfaceInfo (Content target) { - if (isFunctionalInterface()) { - var dl = HtmlTree.DL(HtmlStyle.notes); - dl.add(HtmlTree.DT(contents.functionalInterface)); - var dd = new HtmlTree(TagName.DD); - dd.add(contents.functionalInterfaceMessage); - dl.add(dd); - target.add(dl); - } - } - - public boolean isFunctionalInterface() { - List<? extends AnnotationMirror> annotationMirrors = typeElement.getAnnotationMirrors(); - for (AnnotationMirror anno : annotationMirrors) { - if (utils.isFunctionalInterface(anno)) { - return true; - } - } - return false; - } - - - @Override - public void addClassDeprecationInfo(Content classInfo) { - List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(typeElement); - if (utils.isDeprecated(typeElement)) { - var deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(typeElement)); - var div = HtmlTree.DIV(HtmlStyle.deprecationBlock, deprLabel); - if (!deprs.isEmpty()) { - CommentHelper ch = utils.getCommentHelper(typeElement); - DocTree dt = deprs.get(0); - List<? extends DocTree> commentTags = ch.getBody(dt); - if (!commentTags.isEmpty()) { - addInlineDeprecatedComment(typeElement, deprs.get(0), div); - } - } - classInfo.add(div); - } - } - - /** - * Get the links to the given classes. - * - * @param context the id of the context where the links will be added - * @param list the classes - * @return the links - */ - private Content getClassLinks(HtmlLinkInfo.Kind context, Collection<?> list) { - Content content = new ContentBuilder(); - boolean isFirst = true; - for (Object type : list) { - if (!isFirst) { - content.add(Text.of(", ")); - } else { - isFirst = false; - } - // TODO: should we simply split this method up to avoid instanceof ? - if (type instanceof TypeElement te) { - Content link = getLink( - new HtmlLinkInfo(configuration, context, te)); - content.add(HtmlTree.CODE(link)); - } else { - Content link = getLink( - new HtmlLinkInfo(configuration, context, ((TypeMirror)type))); - content.add(HtmlTree.CODE(link)); - } - } - return content; - } - - /** - * Return the TypeElement being documented. - * - * @return the TypeElement being documented. - */ - @Override - public TypeElement getTypeElement() { - return typeElement; - } - - @Override - public Content getMemberDetails(Content content) { - var section = HtmlTree.SECTION(HtmlStyle.details, content); - // The following id is required by the Navigation bar - if (utils.isAnnotationInterface(typeElement)) { - section.setId(HtmlIds.ANNOTATION_TYPE_ELEMENT_DETAIL); - } - return section; - } -} 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 new file mode 100644 index 00000000000..62de9508364 --- /dev/null +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriter.java @@ -0,0 +1,488 @@ +/* + * Copyright (c) 2001, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.javadoc.internal.doclets.formats.html; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; + +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.Entity; +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.Text; +import jdk.javadoc.internal.doclets.toolkit.DocletException; +import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; +import jdk.javadoc.internal.doclets.toolkit.util.DocLink; +import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; +import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; + + +/** + * Write the Constants Summary Page in HTML format. + */ +public class ConstantsSummaryWriter extends HtmlDocletWriter { + + /** + * The maximum number of package directories shown in the headings of + * the constant values contents list and headings. + */ + private static final int MAX_CONSTANT_VALUE_INDEX_LENGTH = 2; + + /** + * The current class being documented. + */ + private TypeElement currentTypeElement; + + private final TableHeader constantsTableHeader; + + /** + * The HTML tree for constant values summary currently being written. + */ + private HtmlTree summarySection; + + private final BodyContents bodyContents = new BodyContents(); + + private boolean hasConstants = false; + + + /** + * The set of type elements that have constant fields. + */ + protected final Set<TypeElement> typeElementsWithConstFields; + + /** + * The set of package-group headings. + */ + protected final Set<String> packageGroupHeadings; + + private PackageElement currentPackage; + private TypeElement currentClass; // FIXME: dup of currentTypeElement + + + /** + * Construct a ConstantsSummaryWriter. + * @param configuration the configuration used in this run + * of the standard doclet. + */ + public ConstantsSummaryWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.CONSTANT_VALUES, false); + constantsTableHeader = new TableHeader( + contents.modifierAndTypeLabel, contents.constantFieldLabel, contents.valueLabel); + + this.typeElementsWithConstFields = new HashSet<>(); + this.packageGroupHeadings = new TreeSet<>(utils::compareStrings); + } + + public void build() throws DocletException { + boolean anyConstants = configuration.packages.stream().anyMatch(this::hasConstantField); + if (!anyConstants) { + return; + } + + configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.CONSTANT_VALUES); + writeGenerating(); + + buildConstantSummary(); + } + + /** + * Builds the constant summary page. + * + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildConstantSummary() throws DocletException { + Content content = getHeader(); + + buildContents(); + buildConstantSummaries(); + + addFooter(); + printDocument(content); + } + + /** + * Builds the list of contents for the groups of packages appearing in the constants summary page. + */ + protected void buildContents() { + Content contentList = getContentsHeader(); + packageGroupHeadings.clear(); + for (PackageElement pkg : configuration.packages) { + String abbrevPackageName = getAbbrevPackageName(pkg); + if (hasConstantField(pkg) && !packageGroupHeadings.contains(abbrevPackageName)) { + addLinkToPackageContent(abbrevPackageName, contentList); + packageGroupHeadings.add(abbrevPackageName); + } + } + addContentsList(contentList); + } + + /** + * Builds the summary for each documented package. + */ + protected void buildConstantSummaries() { + packageGroupHeadings.clear(); + Content summaries = getConstantSummaries(); + for (PackageElement aPackage : configuration.packages) { + if (hasConstantField(aPackage)) { + currentPackage = aPackage; + //Build the documentation for the current package. + buildPackageHeader(summaries); + buildClassConstantSummary(); + } + } + addConstantSummaries(summaries); + } + + /** + * Builds the header for the given package. + * + * @param target the content to which the package header will be added + */ + protected void buildPackageHeader(Content target) { + String abbrevPkgName = getAbbrevPackageName(currentPackage); + if (!packageGroupHeadings.contains(abbrevPkgName)) { + addPackageGroup(abbrevPkgName, target); + packageGroupHeadings.add(abbrevPkgName); + } + } + + /** + * Builds the summary for the current class. + */ + protected void buildClassConstantSummary() { + SortedSet<TypeElement> classes = !currentPackage.isUnnamed() + ? utils.getAllClasses(currentPackage) + : configuration.typeElementCatalog.allUnnamedClasses(); + Content classConstantHeader = getClassConstantHeader(); + for (TypeElement te : classes) { + if (!typeElementsWithConstFields.contains(te) || + !utils.isIncluded(te)) { + continue; + } + currentClass = te; + //Build the documentation for the current class. + + buildConstantMembers(classConstantHeader); + + } + addClassConstant(classConstantHeader); + } + + /** + * Builds the summary of constant members in the class. + * + * @param target the content to which the table of constant members will be added + */ + protected void buildConstantMembers(Content target) { + new ConstantFieldBuilder(currentClass).buildMembersSummary(target); + } + + /** + * {@return true if the given package has constant fields to document} + * + * @param pkg the package to be checked + */ + private boolean hasConstantField(PackageElement pkg) { + SortedSet<TypeElement> classes = !pkg.isUnnamed() + ? utils.getAllClasses(pkg) + : configuration.typeElementCatalog.allUnnamedClasses(); + boolean found = false; + for (TypeElement te : classes) { + if (utils.isIncluded(te) && hasConstantField(te)) { + found = true; + } + } + return found; + } + + /** + * {@return true if the given class has constant fields to document} + * + * @param typeElement the class to be checked + */ + private boolean hasConstantField(TypeElement typeElement) { + VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); + List<? extends Element> fields = vmt.getVisibleMembers(VisibleMemberTable.Kind.FIELDS); + for (Element f : fields) { + VariableElement field = (VariableElement)f; + if (field.getConstantValue() != null) { + typeElementsWithConstFields.add(typeElement); + return true; + } + } + return false; + } + + /** + * {@return the abbreviated name for a package, containing the leading segments of the name} + * + * @param pkg the package + */ + public String getAbbrevPackageName(PackageElement pkg) { + if (pkg.isUnnamed()) { + return ""; + } + + String packageName = utils.getPackageName(pkg); + int index = -1; + for (int j = 0; j < MAX_CONSTANT_VALUE_INDEX_LENGTH; j++) { + index = packageName.indexOf(".", index + 1); + } + return index == -1 ? packageName : packageName.substring(0, index); + } + + /** + * Builder for the table of fields with constant values. + */ + private class ConstantFieldBuilder { + + /** + * The type element that we are examining constants for. + */ + protected TypeElement typeElement; + + /** + * Constructs a {@code ConstantFieldBuilder}. + * @param typeElement the type element that we are examining constants for + */ + public ConstantFieldBuilder(TypeElement typeElement) { + this.typeElement = typeElement; + } + + /** + * Builds the table of constants for a given class. + * + * @param target the content to which the table of class constants will be added + */ + protected void buildMembersSummary(Content target) { + SortedSet<VariableElement> members = members(); + if (!members.isEmpty()) { + addConstantMembers(typeElement, members, target); + } + } + + /** + * {@return a set of visible constant fields for the given type} + */ + protected SortedSet<VariableElement> members() { + VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); + List<Element> members = new ArrayList<>(); + members.addAll(vmt.getVisibleMembers(VisibleMemberTable.Kind.FIELDS)); + members.addAll(vmt.getVisibleMembers(VisibleMemberTable.Kind.ENUM_CONSTANTS)); + SortedSet<VariableElement> includes = + new TreeSet<>(utils.comparators.makeGeneralPurposeComparator()); + for (Element element : members) { + VariableElement member = (VariableElement)element; + if (member.getConstantValue() != null) { + includes.add(member); + } + } + return includes; + } + } + + Content getHeader() { + String label = resources.getText("doclet.Constants_Summary"); + HtmlTree body = getBody(getWindowTitle(label)); + bodyContents.setHeader(getHeader(PageMode.CONSTANT_VALUES)); + return body; + } + + Content getContentsHeader() { + return HtmlTree.UL(HtmlStyle.contentsList); + } + + void addLinkToPackageContent(String abbrevPackageName, Content content) { + //add link to summary + Content link; + if (abbrevPackageName.isEmpty()) { + link = links.createLink(HtmlIds.UNNAMED_PACKAGE_ANCHOR, + contents.defaultPackageLabel, ""); + } else { + Content packageNameContent = Text.of(abbrevPackageName + ".*"); + link = links.createLink(DocLink.fragment(abbrevPackageName), + packageNameContent, ""); + } + content.add(HtmlTree.LI(link)); + } + + void addContentsList(Content content) { + Content titleContent = contents.constantsSummaryTitle; + var pHeading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, + HtmlStyle.title, titleContent); + var div = HtmlTree.DIV(HtmlStyle.header, pHeading); + bodyContents.addMainContent(div); + Content headingContent = contents.contentsHeading; + var heading = HtmlTree.HEADING_TITLE(Headings.CONTENT_HEADING, + headingContent); + var section = HtmlTree.SECTION(HtmlStyle.packages, heading); + section.add(content); + bodyContents.addMainContent(section); + } + + //@Override + // TODO: inline? + public Content getConstantSummaries() { + return new ContentBuilder(); + } + + void addPackageGroup(String abbrevPackageName, Content toContent) { + Content headingContent; + HtmlId anchorName; + if (abbrevPackageName.isEmpty()) { + anchorName = HtmlIds.UNNAMED_PACKAGE_ANCHOR; + headingContent = contents.defaultPackageLabel; + } else { + anchorName = htmlIds.forPackageName(abbrevPackageName); + headingContent = new ContentBuilder( + getPackageLabel(abbrevPackageName), + Text.of(".*")); + } + var heading = HtmlTree.HEADING_TITLE( + Headings.ConstantsSummary.PACKAGE_HEADING, + headingContent); + summarySection = HtmlTree.SECTION(HtmlStyle.constantsSummary, heading) + .setId(anchorName); + + toContent.add(summarySection); + } + + Content getClassConstantHeader() { + return HtmlTree.UL(HtmlStyle.blockList); + } + + void addClassConstant(Content fromClassConstant) { + summarySection.add(fromClassConstant); + hasConstants = true; + } + + void addConstantMembers(TypeElement typeElement, Collection<VariableElement> fields, + Content target) { + currentTypeElement = typeElement; + + //generate links backward only to public classes. + Content classLink = (utils.isPublic(typeElement) || utils.isProtected(typeElement)) ? + getLink(new HtmlLinkInfo(configuration, + HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS_IN_LABEL, typeElement)) : + Text.of(utils.getFullyQualifiedName(typeElement)); + + PackageElement enclosingPackage = utils.containingPackage(typeElement); + Content caption = new ContentBuilder(); + if (!enclosingPackage.isUnnamed()) { + caption.add(enclosingPackage.getQualifiedName()); + caption.add("."); + } + caption.add(classLink); + + var table = new Table<Void>(HtmlStyle.summaryTable) + .setCaption(caption) + .setHeader(constantsTableHeader) + .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); + + for (VariableElement field : fields) { + table.addRow(getTypeColumn(field), getNameColumn(field), getValue(field)); + } + target.add(HtmlTree.LI(table)); + } + + /** + * Get the type column for the constant summary table row. + * + * @param member the field to be documented. + * @return the type column of the constant table row + */ + private Content getTypeColumn(VariableElement member) { + Content typeContent = new ContentBuilder(); + var code = new HtmlTree(TagName.CODE) + .setId(htmlIds.forMember(currentTypeElement, member)); + for (Modifier mod : member.getModifiers()) { + code.add(Text.of(mod.toString())) + .add(Entity.NO_BREAK_SPACE); + } + Content type = getLink(new HtmlLinkInfo(configuration, + HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, member.asType())); + code.add(type); + typeContent.add(code); + return typeContent; + } + + /** + * Get the name column for the constant summary table row. + * + * @param member the field to be documented. + * @return the name column of the constant table row + */ + private Content getNameColumn(VariableElement member) { + Content nameContent = getDocLink(HtmlLinkInfo.Kind.PLAIN, + member, member.getSimpleName()); + return HtmlTree.CODE(nameContent); + } + + /** + * Get the value column for the constant summary table row. + * + * @param member the field to be documented. + * @return the value column of the constant table row + */ + private Content getValue(VariableElement member) { + String value = utils.constantValueExpression(member); + return HtmlTree.CODE(Text.of(value)); + } + + void addConstantSummaries(Content content) { + bodyContents.addMainContent(content); + } + + void addFooter() { + bodyContents.setFooter(getFooter()); + } + + void printDocument(Content content) throws DocFileIOException { + content.add(bodyContents); + printHtmlDocument(null, "summary of constants", content); + + if (hasConstants && configuration.mainIndex != null) { + configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS, + resources.getText("doclet.Constants_Summary"), path)); + } + } +} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriterImpl.java deleted file mode 100644 index 03154ca8ff7..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstantsSummaryWriterImpl.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 2001, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.formats.html; - -import java.util.Collection; - -import javax.lang.model.element.Modifier; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; - -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.Entity; -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.Text; -import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocLink; -import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; -import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; - - -/** - * Write the Constants Summary Page in HTML format. - */ -public class ConstantsSummaryWriterImpl extends HtmlDocletWriter implements ConstantsSummaryWriter { - - /** - * The current class being documented. - */ - private TypeElement currentTypeElement; - - private final TableHeader constantsTableHeader; - - /** - * The HTML tree for constant values summary currently being written. - */ - private HtmlTree summarySection; - - private final BodyContents bodyContents = new BodyContents(); - - private boolean hasConstants = false; - - /** - * Construct a ConstantsSummaryWriter. - * @param configuration the configuration used in this run - * of the standard doclet. - */ - public ConstantsSummaryWriterImpl(HtmlConfiguration configuration) { - super(configuration, DocPaths.CONSTANT_VALUES); - constantsTableHeader = new TableHeader( - contents.modifierAndTypeLabel, contents.constantFieldLabel, contents.valueLabel); - configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.CONSTANT_VALUES); - } - - @Override - public Content getHeader() { - String label = resources.getText("doclet.Constants_Summary"); - HtmlTree body = getBody(getWindowTitle(label)); - bodyContents.setHeader(getHeader(PageMode.CONSTANT_VALUES)); - return body; - } - - @Override - public Content getContentsHeader() { - return HtmlTree.UL(HtmlStyle.contentsList); - } - - @Override - public void addLinkToPackageContent(String abbrevPackageName, Content content) { - //add link to summary - Content link; - if (abbrevPackageName.isEmpty()) { - link = links.createLink(HtmlIds.UNNAMED_PACKAGE_ANCHOR, - contents.defaultPackageLabel, ""); - } else { - Content packageNameContent = Text.of(abbrevPackageName + ".*"); - link = links.createLink(DocLink.fragment(abbrevPackageName), - packageNameContent, ""); - } - content.add(HtmlTree.LI(link)); - } - - @Override - public void addContentsList(Content content) { - Content titleContent = contents.constantsSummaryTitle; - var pHeading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, - HtmlStyle.title, titleContent); - var div = HtmlTree.DIV(HtmlStyle.header, pHeading); - bodyContents.addMainContent(div); - Content headingContent = contents.contentsHeading; - var heading = HtmlTree.HEADING_TITLE(Headings.CONTENT_HEADING, - headingContent); - var section = HtmlTree.SECTION(HtmlStyle.packages, heading); - section.add(content); - bodyContents.addMainContent(section); - } - - @Override - public Content getConstantSummaries() { - return new ContentBuilder(); - } - - @Override - public void addPackageGroup(String abbrevPackageName, Content toContent) { - Content headingContent; - HtmlId anchorName; - if (abbrevPackageName.isEmpty()) { - anchorName = HtmlIds.UNNAMED_PACKAGE_ANCHOR; - headingContent = contents.defaultPackageLabel; - } else { - anchorName = htmlIds.forPackageName(abbrevPackageName); - headingContent = new ContentBuilder( - getPackageLabel(abbrevPackageName), - Text.of(".*")); - } - var heading = HtmlTree.HEADING_TITLE( - Headings.ConstantsSummary.PACKAGE_HEADING, - headingContent); - summarySection = HtmlTree.SECTION(HtmlStyle.constantsSummary, heading) - .setId(anchorName); - - toContent.add(summarySection); - } - - @Override - public Content getClassConstantHeader() { - return HtmlTree.UL(HtmlStyle.blockList); - } - - @Override - public void addClassConstant(Content fromClassConstant) { - summarySection.add(fromClassConstant); - hasConstants = true; - } - - @Override - public void addConstantMembers(TypeElement typeElement, Collection<VariableElement> fields, - Content target) { - currentTypeElement = typeElement; - - //generate links backward only to public classes. - Content classLink = (utils.isPublic(typeElement) || utils.isProtected(typeElement)) ? - getLink(new HtmlLinkInfo(configuration, - HtmlLinkInfo.Kind.SHOW_TYPE_PARAMS_IN_LABEL, typeElement)) : - Text.of(utils.getFullyQualifiedName(typeElement)); - - PackageElement enclosingPackage = utils.containingPackage(typeElement); - Content caption = new ContentBuilder(); - if (!enclosingPackage.isUnnamed()) { - caption.add(enclosingPackage.getQualifiedName()); - caption.add("."); - } - caption.add(classLink); - - var table = new Table<Void>(HtmlStyle.summaryTable) - .setCaption(caption) - .setHeader(constantsTableHeader) - .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); - - for (VariableElement field : fields) { - table.addRow(getTypeColumn(field), getNameColumn(field), getValue(field)); - } - target.add(HtmlTree.LI(table)); - } - - /** - * Get the type column for the constant summary table row. - * - * @param member the field to be documented. - * @return the type column of the constant table row - */ - private Content getTypeColumn(VariableElement member) { - Content typeContent = new ContentBuilder(); - var code = new HtmlTree(TagName.CODE) - .setId(htmlIds.forMember(currentTypeElement, member)); - for (Modifier mod : member.getModifiers()) { - code.add(Text.of(mod.toString())) - .add(Entity.NO_BREAK_SPACE); - } - Content type = getLink(new HtmlLinkInfo(configuration, - HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, member.asType())); - code.add(type); - typeContent.add(code); - return typeContent; - } - - /** - * Get the name column for the constant summary table row. - * - * @param member the field to be documented. - * @return the name column of the constant table row - */ - private Content getNameColumn(VariableElement member) { - Content nameContent = getDocLink(HtmlLinkInfo.Kind.PLAIN, - member, member.getSimpleName()); - return HtmlTree.CODE(nameContent); - } - - /** - * Get the value column for the constant summary table row. - * - * @param member the field to be documented. - * @return the value column of the constant table row - */ - private Content getValue(VariableElement member) { - String value = utils.constantValueExpression(member); - return HtmlTree.CODE(Text.of(value)); - } - - @Override - public void addConstantSummaries(Content content) { - bodyContents.addMainContent(content); - } - - @Override - public void addFooter() { - bodyContents.setFooter(getFooter()); - } - - @Override - public void printDocument(Content content) throws DocFileIOException { - content.add(bodyContents); - printHtmlDocument(null, "summary of constants", content); - - if (hasConstants && configuration.mainIndex != null) { - configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS, - resources.getText("doclet.Constants_Summary"), path)); - } - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java similarity index 60% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java index c2345b2b126..9a893f63b90 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ConstructorWriter.java @@ -39,19 +39,20 @@ 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.Text; -import jdk.javadoc.internal.doclets.toolkit.ConstructorWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; +import jdk.javadoc.internal.doclets.toolkit.BaseOptions; +import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.CONSTRUCTORS; - /** * Writes constructor documentation. */ -public class ConstructorWriterImpl extends AbstractExecutableMemberWriter - implements ConstructorWriter, MemberSummaryWriter { +public class ConstructorWriter extends AbstractExecutableMemberWriter { + + /** + * The current constructor that is being documented at this point in time. + */ + private ExecutableElement currentConstructor; private boolean foundNonPubConstructor = false; @@ -59,14 +60,12 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter * Construct a new ConstructorWriterImpl. * * @param writer The writer for the class that the constructors belong to. - * @param typeElement the class being documented. */ - public ConstructorWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) { - super(writer, typeElement); - - VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); - List<? extends Element> constructors = vmt.getVisibleMembers(CONSTRUCTORS); + public ConstructorWriter(ClassWriter writer) { + super(writer, writer.getTypeElement()); + // the following must be done before the summary table is generated + var constructors = getVisibleMembers(VisibleMemberTable.Kind.CONSTRUCTORS); for (Element constructor : constructors) { if (utils.isProtected(constructor) || utils.isPrivate(constructor)) { setFoundNonPubConstructor(true); @@ -79,10 +78,96 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter * * @param writer The writer for the class that the constructors belong to. */ - public ConstructorWriterImpl(SubWriterHolderWriter writer) { + public ConstructorWriter(SubWriterHolderWriter writer) { super(writer); } + public void build(Content target) throws DocletException { + buildConstructorDoc(target); + } + + /** + * Build the constructor documentation. + * + * @param target the content to which the documentation will be added + */ + protected void buildConstructorDoc(Content target) { + var constructors = getVisibleMembers(VisibleMemberTable.Kind.CONSTRUCTORS); + if (!constructors.isEmpty()) { + for (Element constructor : constructors) { + if (utils.isProtected(constructor) || utils.isPrivate(constructor)) { + setFoundNonPubConstructor(true); + } + } + + Content constructorDetailsHeader = getConstructorDetailsHeader(target); + Content memberList = getMemberList(); + + for (Element constructor : constructors) { + currentConstructor = (ExecutableElement)constructor; + Content constructorContent = getConstructorHeaderContent(currentConstructor); + + buildSignature(constructorContent); + buildDeprecationInfo(constructorContent); + buildPreviewInfo(constructorContent); + buildConstructorComments(constructorContent); + buildTagInfo(constructorContent); + + memberList.add(getMemberListItem(constructorContent)); + } + Content constructorDetails = getConstructorDetails(constructorDetailsHeader, memberList); + target.add(constructorDetails); + } + } + + /** + * Build the signature. + * + * @param constructorContent the content to which the documentation will be added + */ + protected void buildSignature(Content constructorContent) { + constructorContent.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); + } + + /** + * Build the preview information. + * + * @param constructorContent the content to which the documentation will be added + */ + protected void buildPreviewInfo(Content constructorContent) { + addPreview(currentConstructor, constructorContent); + } + + /** + * Build the comments for the constructor. Do nothing if + * {@link BaseOptions#noComment()} is set to true. + * + * @param constructorContent the content to which the documentation will be added + */ + protected void buildConstructorComments(Content constructorContent) { + if (!options.noComment()) { + addComments(currentConstructor, constructorContent); + } + } + + /** + * Build the tag information. + * + * @param constructorContent the content to which the documentation will be added + */ + protected void buildTagInfo(Content constructorContent) { + addTags(currentConstructor, constructorContent); + } + @Override public Content getMemberSummaryHeader(TypeElement typeElement, Content content) { @@ -98,8 +183,7 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter HtmlIds.CONSTRUCTOR_SUMMARY, summariesList, content); } - @Override - public Content getConstructorDetailsHeader(Content content) { + protected Content getConstructorDetailsHeader(Content content) { content.add(MarkerComments.START_OF_CONSTRUCTOR_DETAILS); Content constructorDetails = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, @@ -108,8 +192,7 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter return constructorDetails; } - @Override - public Content getConstructorHeaderContent(ExecutableElement constructor) { + protected Content getConstructorHeaderContent(ExecutableElement constructor) { Content content = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, Text.of(name(constructor))); @@ -122,8 +205,7 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter .setId(htmlIds.forMember(constructor)); } - @Override - public Content getSignature(ExecutableElement constructor) { + protected Content getSignature(ExecutableElement constructor) { return new Signatures.MemberSignature(constructor, this) .setParameters(getParameters(constructor, true)) .setExceptions(getExceptions(constructor)) @@ -131,28 +213,23 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter .toContent(); } - @Override - public void addDeprecated(ExecutableElement constructor, Content constructorContent) { + protected void addDeprecated(ExecutableElement constructor, Content constructorContent) { addDeprecatedInfo(constructor, constructorContent); } - @Override - public void addPreview(ExecutableElement constructor, Content content) { + protected void addPreview(ExecutableElement constructor, Content content) { addPreviewInfo(constructor, content); } - @Override - public void addComments(ExecutableElement constructor, Content constructorContent) { + protected void addComments(ExecutableElement constructor, Content constructorContent) { addComment(constructor, constructorContent); } - @Override - public void addTags(ExecutableElement constructor, Content constructorContent) { + protected void addTags(ExecutableElement constructor, Content constructorContent) { writer.addTagsInfo(constructor, constructorContent); } - @Override - public Content getConstructorDetails(Content memberDetailsHeader, Content memberDetails) { + protected Content getConstructorDetails(Content memberDetailsHeader, Content memberDetails) { return writer.getDetailsListItem( HtmlTree.SECTION(HtmlStyle.constructorDetails) .setId(HtmlIds.CONSTRUCTOR_DETAIL) @@ -160,8 +237,7 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter .add(memberDetails)); } - @Override - public void setFoundNonPubConstructor(boolean foundNonPubConstructor) { + protected void setFoundNonPubConstructor(boolean foundNonPubConstructor) { this.foundNonPubConstructor = foundNonPubConstructor; } @@ -222,8 +298,7 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter } } - @Override - public Content getMemberHeader(){ + protected Content getMemberHeader(){ return writer.getMemberHeader(); } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Content.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Content.java similarity index 99% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Content.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Content.java index 9ad23e6cfa2..597747bdb4c 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Content.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Content.java @@ -23,7 +23,7 @@ * questions. */ -package jdk.javadoc.internal.doclets.toolkit; +package jdk.javadoc.internal.doclets.formats.html; import java.io.IOException; import java.io.StringWriter; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Contents.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Contents.java index 4831a152ff8..a7a23b07170 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Contents.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Contents.java @@ -34,7 +34,6 @@ import java.util.regex.Pattern; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.Entity; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; @@ -393,7 +392,7 @@ public class Contents { */ public Content getContent(String key, Object o0, Object o1, Object o2) { Content c = new ContentBuilder(); - Pattern p = Pattern.compile("\\{([012])\\}"); + Pattern p = Pattern.compile("\\{([012])}"); String text = resources.getText(key); // TODO: cache Matcher m = p.matcher(text); int start = 0; 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 1a28411b5e8..679322bc049 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 @@ -36,7 +36,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.Navigation.PageMode; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DeprecatedAPIListBuilder; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandler.java similarity index 97% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandler.java index 6567f6e13fb..b8779bb919c 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandler.java @@ -31,9 +31,7 @@ import com.sun.source.doctree.StartElementTree; import com.sun.source.util.DocTreeFactory; import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.DocFileElement; -import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; @@ -54,7 +52,7 @@ import java.util.List; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; -public class DocFilesHandlerImpl implements DocFilesHandler { +public class DocFilesHandler { public final Element element; public final Location location; @@ -69,7 +67,7 @@ public class DocFilesHandlerImpl implements DocFilesHandler { * @param element the containing element of the doc-files. * */ - public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) { + public DocFilesHandler(HtmlConfiguration configuration, Element element) { this.configuration = configuration; this.options = configuration.getOptions(); this.element = element; @@ -102,7 +100,6 @@ public class DocFilesHandlerImpl implements DocFilesHandler { * @throws DocFileIOException if there is a problem while copying * the documentation files */ - @Override public void copyDocFiles() throws DocFileIOException { boolean first = true; for (DocFile srcdir : DocFile.list(configuration, location, source)) { @@ -119,7 +116,6 @@ public class DocFilesHandlerImpl implements DocFilesHandler { } } - @Override public List<DocPath> getStylesheets() throws DocFileIOException { var stylesheets = new ArrayList<DocPath>(); for (DocFile srcdir : DocFile.list(configuration, location, source)) { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java similarity index 60% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java index ce55e9af876..d00bf986ad6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriter.java @@ -25,7 +25,6 @@ package jdk.javadoc.internal.doclets.formats.html; - import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; @@ -34,24 +33,110 @@ 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.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.EnumConstantWriter; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; +import jdk.javadoc.internal.doclets.toolkit.BaseOptions; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** * Writes enum constant documentation in HTML format. */ -public class EnumConstantWriterImpl extends AbstractMemberWriter - implements EnumConstantWriter, MemberSummaryWriter { +public class EnumConstantWriter extends AbstractMemberWriter { - public EnumConstantWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) { - super(writer, typeElement); + /** + * The current enum constant that is being documented. + */ + private VariableElement currentElement; + + public EnumConstantWriter(ClassWriter classWriter) { + super(classWriter, classWriter.typeElement); } - public EnumConstantWriterImpl(SubWriterHolderWriter writer) { + public EnumConstantWriter(SubWriterHolderWriter writer) { super(writer); } + public void build(Content target) { + buildEnumConstant(target); + } + + /** + * Build the enum constant documentation. + * + * @param target the content to which the documentation will be added + */ + protected void buildEnumConstant(Content target) { + var enumConstants = getVisibleMembers(VisibleMemberTable.Kind.ENUM_CONSTANTS); + if (!enumConstants.isEmpty()) { + Content enumConstantsDetailsHeader = getEnumConstantsDetailsHeader(typeElement, + target); + Content memberList = getMemberList(); + + for (Element enumConstant : enumConstants) { + currentElement = (VariableElement)enumConstant; + Content enumConstantContent = getEnumConstantsHeader(currentElement, + memberList); + + buildSignature(enumConstantContent); + buildDeprecationInfo(enumConstantContent); + buildPreviewInfo(enumConstantContent); + buildEnumConstantComments(enumConstantContent); + buildTagInfo(enumConstantContent); + + memberList.add(getMemberListItem(enumConstantContent)); + } + Content enumConstantDetails = getEnumConstantsDetails( + enumConstantsDetailsHeader, memberList); + target.add(enumConstantDetails); + } + } + + /** + * Build the signature. + * + * @param target the content to which the documentation will be added + */ + protected void buildSignature(Content target) { + target.add(getSignature(currentElement)); + } + + /** + * Build the deprecation information. + * + * @param target the content to which the documentation will be added + */ + protected void buildDeprecationInfo(Content target) { + addDeprecated(currentElement, target); + } + + /** + * Build the preview information. + * + * @param target the content to which the documentation will be added + */ + protected void buildPreviewInfo(Content target) { + addPreview(currentElement, target); + } + + /** + * Build the comments for the enum constant. Do nothing if + * {@link BaseOptions#noComment()} is set to true. + * + * @param target the content to which the documentation will be added + */ + protected void buildEnumConstantComments(Content target) { + if (!options.noComment()) { + addComments(currentElement, target); + } + } + + /** + * Build the tag information. + * + * @param target the content to which the documentation will be added + */ + protected void buildTagInfo(Content target) { + addTags(currentElement, target); + } + @Override public Content getMemberSummaryHeader(TypeElement typeElement, Content content) { @@ -67,8 +152,7 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter HtmlIds.ENUM_CONSTANT_SUMMARY, summariesList, content); } - @Override - public Content getEnumConstantsDetailsHeader(TypeElement typeElement, + protected Content getEnumConstantsDetailsHeader(TypeElement typeElement, Content memberDetails) { memberDetails.add(MarkerComments.START_OF_ENUM_CONSTANT_DETAILS); var enumConstantsDetailsContent = new ContentBuilder(); @@ -78,8 +162,7 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter return enumConstantsDetailsContent; } - @Override - public Content getEnumConstantsHeader(VariableElement enumConstant, + protected Content getEnumConstantsHeader(VariableElement enumConstant, Content enumConstantsDetails) { Content enumConstantsContent = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, @@ -89,36 +172,30 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter .setId(htmlIds.forMember(enumConstant)); } - @Override - public Content getSignature(VariableElement enumConstant) { + protected Content getSignature(VariableElement enumConstant) { return new Signatures.MemberSignature(enumConstant, this) .setType(enumConstant.asType()) .setAnnotations(writer.getAnnotationInfo(enumConstant, true)) .toContent(); } - @Override - public void addDeprecated(VariableElement enumConstant, Content content) { + protected void addDeprecated(VariableElement enumConstant, Content content) { addDeprecatedInfo(enumConstant, content); } - @Override - public void addPreview(VariableElement enumConstant, Content content) { + protected void addPreview(VariableElement enumConstant, Content content) { addPreviewInfo(enumConstant, content); } - @Override - public void addComments(VariableElement enumConstant, Content enumConstants) { + protected void addComments(VariableElement enumConstant, Content enumConstants) { addComment(enumConstant, enumConstants); } - @Override - public void addTags(VariableElement enumConstant, Content content) { + protected void addTags(VariableElement enumConstant, Content content) { writer.addTagsInfo(enumConstant, content); } - @Override - public Content getEnumConstantsDetails(Content memberDetailsHeader, + protected Content getEnumConstantsDetails(Content memberDetailsHeader, Content content) { return writer.getDetailsListItem( HtmlTree.SECTION(HtmlStyle.constantDetails) @@ -175,8 +252,7 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter return writer.getDocLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, member, name); } - @Override - public Content getMemberHeader(){ + 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 f71df85f64a..22f4db20ba3 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 @@ -53,7 +53,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.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.DocletElement; import jdk.javadoc.internal.doclets.toolkit.OverviewElement; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; @@ -247,34 +246,31 @@ public class ExternalSpecsWriter extends HtmlDocletWriter { Comparator<String> getTitleComparator() { Collator collator = Collator.getInstance(); - return new Comparator<>() { - @Override - public int compare(String s1, String s2) { - int i1 = 0; - int i2 = 0; - while (i1 < s1.length() && i2 < s2.length()) { - int j1 = find(s1, i1, Character::isDigit); - int j2 = find(s2, i2, Character::isDigit); - int cmp = collator.compare(s1.substring(i1, j1), s2.substring(i2, j2)); - if (cmp != 0) { - return cmp; - } - if (j1 == s1.length() || j2 == s2.length()) { - i1 = j1; - i2 = j2; - break; - } - int k1 = find(s1, j1, ch -> !Character.isDigit(ch)); - int k2 = find(s2, j2, ch -> !Character.isDigit(ch)); - cmp = Integer.compare(Integer.parseInt(s1.substring(j1, k1)), Integer.parseInt(s2.substring(j2, k2))); - if (cmp != 0) { - return cmp; - } - i1 = k1; - i2 = k2; + return (s1, s2) -> { + int i1 = 0; + int i2 = 0; + while (i1 < s1.length() && i2 < s2.length()) { + int j1 = find(s1, i1, Character::isDigit); + int j2 = find(s2, i2, Character::isDigit); + int cmp = collator.compare(s1.substring(i1, j1), s2.substring(i2, j2)); + if (cmp != 0) { + return cmp; } - return i1 < s1.length() ? 1 : i2 < s2.length() ? -1 : 0; + if (j1 == s1.length() || j2 == s2.length()) { + i1 = j1; + i2 = j2; + break; + } + int k1 = find(s1, j1, ch -> !Character.isDigit(ch)); + int k2 = find(s2, j2, ch -> !Character.isDigit(ch)); + cmp = Integer.compare(Integer.parseInt(s1.substring(j1, k1)), Integer.parseInt(s2.substring(j2, k2))); + if (cmp != 0) { + return cmp; + } + i1 = k1; + i2 = k2; } + return i1 < s1.length() ? 1 : i2 < s2.length() ? -1 : 0; }; } @@ -292,8 +288,7 @@ public class ExternalSpecsWriter extends HtmlDocletWriter { if (element instanceof OverviewElement) { return links.createLink(pathToRoot.resolve(i.getUrl()), resources.getText("doclet.Overview")); - } else if (element instanceof DocletElement) { - DocletElement e = (DocletElement) element; + } else if (element instanceof DocletElement e) { // Implementations of DocletElement do not override equals and // hashCode; putting instances of DocletElement in a map is not // incorrect, but might well be inefficient diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java similarity index 64% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java index ac9b102c32f..34658d0448d 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FieldWriter.java @@ -37,24 +37,115 @@ import jdk.javadoc.internal.doclets.formats.html.markup.Entity; 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.Content; -import jdk.javadoc.internal.doclets.toolkit.FieldWriter; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; +import jdk.javadoc.internal.doclets.toolkit.BaseOptions; +import jdk.javadoc.internal.doclets.toolkit.DocletException; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** * Writes field documentation in HTML format. */ -public class FieldWriterImpl extends AbstractMemberWriter - implements FieldWriter, MemberSummaryWriter { +public class FieldWriter extends AbstractMemberWriter { - public FieldWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) { + /** + * The index of the current field that is being documented at this point + * in time. + */ + private VariableElement currentElement; + + public FieldWriter(ClassWriter writer) { + super(writer, writer.typeElement); + } + + public FieldWriter(SubWriterHolderWriter writer, TypeElement typeElement) { super(writer, typeElement); } - public FieldWriterImpl(SubWriterHolderWriter writer) { + // used in ClassUseWriter and SummaryUseWriter + public FieldWriter(SubWriterHolderWriter writer) { super(writer); } + public void build(Content target) throws DocletException { + buildFieldDoc(target); + } + + /** + * Build the field documentation. + * + * @param target the content to which the documentation will be added + */ + protected void buildFieldDoc(Content target) { + var fields = getVisibleMembers(VisibleMemberTable.Kind.FIELDS); + if (!fields.isEmpty()) { + Content fieldDetailsHeader = getFieldDetailsHeader(target); + Content memberList = getMemberList(); + + for (Element element : fields) { + currentElement = (VariableElement)element; + Content fieldContent = getFieldHeaderContent(currentElement); + + buildSignature(fieldContent); + buildDeprecationInfo(fieldContent); + buildPreviewInfo(fieldContent); + buildFieldComments(fieldContent); + buildTagInfo(fieldContent); + + memberList.add(getMemberListItem(fieldContent)); + } + Content fieldDetails = getFieldDetails(fieldDetailsHeader, memberList); + target.add(fieldDetails); + } + } + + /** + * Build the signature. + * + * @param fieldContent the content to which the documentation will be added + */ + protected void buildSignature(Content fieldContent) { + fieldContent.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); + } + + /** + * Build the preview information. + * + * @param fieldContent the content to which the documentation will be added + */ + protected void buildPreviewInfo(Content fieldContent) { + addPreview(currentElement, fieldContent); + } + + /** + * Build the comments for the field. Do nothing if + * {@link BaseOptions#noComment()} is set to true. + * + * @param fieldContent the content to which the documentation will be added + */ + protected void buildFieldComments(Content fieldContent) { + if (!options.noComment()) { + addComments(currentElement, fieldContent); + } + } + + /** + * Build the tag information. + * + * @param fieldContent the content to which the documentation will be added + */ + protected void buildTagInfo(Content fieldContent) { + addTags(currentElement, fieldContent); + } + + @Override public Content getMemberSummaryHeader(TypeElement typeElement, Content content) { @@ -70,8 +161,7 @@ public class FieldWriterImpl extends AbstractMemberWriter HtmlIds.FIELD_SUMMARY, summariesList, content); } - @Override - public Content getFieldDetailsHeader(Content content) { + protected Content getFieldDetailsHeader(Content content) { content.add(MarkerComments.START_OF_FIELD_DETAILS); Content fieldDetailsContent = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, @@ -80,8 +170,7 @@ public class FieldWriterImpl extends AbstractMemberWriter return fieldDetailsContent; } - @Override - public Content getFieldHeaderContent(VariableElement field) { + protected Content getFieldHeaderContent(VariableElement field) { Content content = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, Text.of(name(field))); @@ -90,38 +179,32 @@ public class FieldWriterImpl extends AbstractMemberWriter .setId(htmlIds.forMember(field)); } - @Override - public Content getSignature(VariableElement field) { + protected Content getSignature(VariableElement field) { return new Signatures.MemberSignature(field, this) .setType(utils.asInstantiatedFieldType(typeElement, field)) .setAnnotations(writer.getAnnotationInfo(field, true)) .toContent(); } - @Override - public void addDeprecated(VariableElement field, Content fieldContent) { + protected void addDeprecated(VariableElement field, Content fieldContent) { addDeprecatedInfo(field, fieldContent); } - @Override - public void addPreview(VariableElement field, Content content) { + protected void addPreview(VariableElement field, Content content) { addPreviewInfo(field, content); } - @Override - public void addComments(VariableElement field, Content fieldContent) { + protected void addComments(VariableElement field, Content fieldContent) { if (!utils.getFullBody(field).isEmpty()) { writer.addInlineComment(field, fieldContent); } } - @Override - public void addTags(VariableElement field, Content fieldContent) { + protected void addTags(VariableElement field, Content fieldContent) { writer.addTagsInfo(field, fieldContent); } - @Override - public Content getFieldDetails(Content memberDetailsHeaderContent, Content memberContent) { + protected Content getFieldDetails(Content memberDetailsHeaderContent, Content memberContent) { return writer.getDetailsListItem( HtmlTree.SECTION(HtmlStyle.fieldDetails) .setId(HtmlIds.FIELD_DETAIL) @@ -201,8 +284,7 @@ public class FieldWriterImpl extends AbstractMemberWriter return writer.getDocLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, member, name); } - @Override - public Content getMemberHeader(){ + 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 0f0a56d5eb1..2848fff194e 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 @@ -36,7 +36,6 @@ 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.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocLink; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java index 6709dbbdb3e..b90fde1bae2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -61,7 +62,6 @@ import jdk.javadoc.internal.doclets.toolkit.BaseOptions; 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.WriterFactory; import jdk.javadoc.internal.doclets.toolkit.util.DeprecatedAPIListBuilder; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; @@ -183,6 +183,11 @@ public class HtmlConfiguration extends BaseConfiguration { */ private ZonedDateTime buildDate; + /** + * The set of packages for which we have copied the doc files. + */ + private Set<PackageElement> containingPackagesSeen; + /** * Constructs the full configuration needed by the doclet, including * the format-specific part, defined in this class, and the format-independent @@ -220,6 +225,7 @@ public class HtmlConfiguration extends BaseConfiguration { messages = new Messages(this, msgResources); options = new HtmlOptions(this); + containingPackagesSeen = new HashSet<>(); Runtime.Version v; try { @@ -271,6 +277,15 @@ public class HtmlConfiguration extends BaseConfiguration { return options; } + /** + * {@return the packages for which we have copied the doc files} + * + * @see {@link ClassWriter#copyDocFiles()} + */ + public Set<PackageElement> getContainingPackagesSeen() { + return containingPackagesSeen; + } + @Override public boolean finishOptionSettings() { if (!options.validateOptions()) { @@ -365,9 +380,9 @@ public class HtmlConfiguration extends BaseConfiguration { } } - @Override public WriterFactory getWriterFactory() { - return new WriterFactoryImpl(this); + // TODO: this is called many times: why not create and use a single instance? + return new WriterFactory(this); } @Override 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 ca88ef26e7c..9daf109182f 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 @@ -51,8 +51,6 @@ import jdk.javadoc.doclet.Reporter; import jdk.javadoc.internal.doclets.toolkit.AbstractDoclet; import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.Messages; -import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder; -import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.DeprecatedAPIListBuilder; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; @@ -213,7 +211,11 @@ public class HtmlDoclet extends AbstractDoclet { protected void generateOtherFiles(ClassTree classTree) throws DocletException { super.generateOtherFiles(classTree); - HtmlOptions options = configuration.getOptions(); + + new ConstantsSummaryWriter(configuration).build(); + new SerializedFormWriter(configuration).build(); + + var options = configuration.getOptions(); if (options.linkSource()) { SourceToHTMLConverter.convertRoot(configuration, DocPaths.SOURCE_OUTPUT); } @@ -323,7 +325,7 @@ public class HtmlDoclet extends AbstractDoclet { protected void generateFiles() throws DocletException { super.generateFiles(); - if (configuration.tagletManager != null) { // may be null, if no files generated, perhaps because of errros + if (configuration.tagletManager != null) { // may be null, if no files generated, perhaps because of errors configuration.tagletManager.printReport(); } @@ -388,13 +390,12 @@ public class HtmlDoclet extends AbstractDoclet { @Override // defined by AbstractDoclet protected void generateClassFiles(SortedSet<TypeElement> typeElems, ClassTree classTree) throws DocletException { - BuilderFactory f = configuration.getBuilderFactory(); for (TypeElement te : typeElems) { if (utils.hasHiddenTag(te) || !(configuration.isGeneratedDoc(te) && utils.isIncluded(te))) { continue; } - f.getClassBuilder(te, classTree).build(); + new ClassWriter(configuration, te, classTree).build(); } } @@ -403,9 +404,7 @@ public class HtmlDoclet extends AbstractDoclet { if (configuration.showModules) { List<ModuleElement> mdles = new ArrayList<>(configuration.modulePackages.keySet()); for (ModuleElement mdle : mdles) { - AbstractBuilder moduleSummaryBuilder = - configuration.getBuilderFactory().getModuleSummaryBuilder(mdle); - moduleSummaryBuilder.build(); + new ModuleWriter(configuration, mdle).build(); } } } @@ -420,9 +419,7 @@ public class HtmlDoclet extends AbstractDoclet { // 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))) { - AbstractBuilder packageSummaryBuilder = - configuration.getBuilderFactory().getPackageSummaryBuilder(pkg); - packageSummaryBuilder.build(); + new PackageWriter(configuration, pkg).build(); 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 fde4734f049..8d2a8a02f7d 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 @@ -92,7 +92,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.formats.html.taglets.Taglet; import jdk.javadoc.internal.doclets.formats.html.taglets.TagletWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.Messages; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; @@ -199,6 +198,16 @@ public class HtmlDocletWriter { * @param path the file to be generated. */ public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path) { + this(configuration, path, true); + } + /** + * Creates an {@code HtmlDocletWriter}. + * + * @param configuration the configuration for this doclet + * @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) { this.configuration = configuration; this.options = configuration.getOptions(); this.contents = configuration.getContents(); @@ -214,8 +223,17 @@ public class HtmlDocletWriter { this.docPaths = configuration.docPaths; this.mainBodyScript = new Script(); + if (generating) { + writeGenerating(); + } + } + + /** + * Writes a "Generating _file_" message to the console + */ + protected final void writeGenerating() { messages.notice("doclet.Generating_0", - DocFile.createFileForOutput(configuration, path).getPath()); + DocFile.createFileForOutput(configuration, path).getPath()); } /** @@ -300,10 +318,10 @@ public class HtmlDocletWriter { // for these methods: // * ForkJoinPool.execute(java.lang.Runnable) // This is a long-standing bug, which must be fixed separately: JDK-8302316 - MethodWriterImpl.addImplementsInfo(this, method, implementedMethods, dl); + MethodWriter.addImplementsInfo(this, method, implementedMethods, dl); } if (overrideInfo != null) { - MethodWriterImpl.addOverridden(this, + MethodWriter.addOverridden(this, overrideInfo.overriddenMethodOwner(), overrideInfo.overriddenMethod(), dl); @@ -1476,9 +1494,9 @@ public class HtmlDocletWriter { // in their respective writers, but other uses of the method are only interested in TypeElements. Element currentPageElement = getCurrentPageElement(); if (currentPageElement == null) { - if (this instanceof PackageWriterImpl packageWriter) { + if (this instanceof PackageWriter packageWriter) { currentPageElement = packageWriter.packageElement; - } else if (this instanceof ModuleWriterImpl moduleWriter) { + } else if (this instanceof ModuleWriter moduleWriter) { currentPageElement = moduleWriter.mdle; } } @@ -1511,7 +1529,7 @@ public class HtmlDocletWriter { * element of this writer. */ private boolean inSamePackage(Element element) { - Element currentPageElement = (this instanceof PackageWriterImpl packageWriter) + Element currentPageElement = (this instanceof PackageWriter packageWriter) ? packageWriter.packageElement : getCurrentPageElement(); return currentPageElement != null && !utils.isModule(element) && Objects.equals(utils.containingPackage(currentPageElement), @@ -2018,8 +2036,7 @@ public class HtmlDocletWriter { private List<DocPath> getStylesheets(Element element) throws DocFileIOException { List<DocPath> localStylesheets = configuration.localStylesheetMap.get(element); if (localStylesheets == null) { - DocFilesHandlerImpl docFilesHandler = (DocFilesHandlerImpl)configuration - .getWriterFactory().getDocFilesHandler(element); + DocFilesHandler docFilesHandler = configuration.getWriterFactory().getDocFilesHandler(element); localStylesheets = docFilesHandler.getStylesheets(); configuration.localStylesheetMap.put(element, localStylesheets); } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkFactory.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkFactory.java index 99815eca71f..93e860e275f 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkFactory.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkFactory.java @@ -46,7 +46,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkInfo.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkInfo.java index a7be9e3b10d..053959d5546 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkInfo.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlLinkInfo.java @@ -35,7 +35,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.BaseConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.Utils; @@ -77,7 +76,7 @@ public class HtmlLinkInfo { /** * Link with optional type parameters and bounds rendered as separate links. */ - LINK_TYPE_PARAMS_AND_BOUNDS; + LINK_TYPE_PARAMS_AND_BOUNDS } private final HtmlConfiguration configuration; 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 976b78ad23b..8a42bb63b77 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 @@ -36,7 +36,6 @@ 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.Script; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 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 f5707289792..d7ba0ceece8 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,7 +46,6 @@ 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.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java similarity index 73% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java index e3b603be76f..8c73e1d60a6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/MethodWriter.java @@ -26,6 +26,7 @@ package jdk.javadoc.internal.doclets.formats.html; import java.util.Collection; +import java.util.Optional; import java.util.SortedSet; import java.util.TreeSet; @@ -40,25 +41,39 @@ 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.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.MethodWriter; +import jdk.javadoc.internal.doclets.toolkit.BaseOptions; +import jdk.javadoc.internal.doclets.toolkit.DocletException; +import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.Utils; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** * Writes method documentation in HTML format. */ -public class MethodWriterImpl extends AbstractExecutableMemberWriter - implements MethodWriter, MemberSummaryWriter { +public class MethodWriter extends AbstractExecutableMemberWriter { + + /** + * The index of the current field that is being documented at this point + * in time. + */ + private ExecutableElement currentMethod; + + /** + * Construct a new MethodWriterImpl. + * + * @param writer the writer for the class that the methods belong to.\ + */ + public MethodWriter(ClassWriter writer) { + super(writer, writer.typeElement); + } /** * Construct a new MethodWriterImpl. * * @param writer the writer for the class that the methods belong to. - * @param typeElement the class being documented. + * @param typeElement the class */ - public MethodWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) { + public MethodWriter(SubWriterHolderWriter writer, TypeElement typeElement) { super(writer, typeElement); } @@ -67,10 +82,97 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter * * @param writer The writer for the class that the methods belong to. */ - public MethodWriterImpl(SubWriterHolderWriter writer) { + // used in ClassUseWriter and SummaryUseWriter + public MethodWriter(SubWriterHolderWriter writer) { super(writer); } + public void build(Content target) throws DocletException { + buildMethodDoc(target); + } + + /** + * Build the method documentation. + * + * @param detailsList the content to which the documentation will be added + */ + protected void buildMethodDoc(Content detailsList) { + var methods = getVisibleMembers(VisibleMemberTable.Kind.METHODS); + if (!methods.isEmpty()) { + Content methodDetailsHeader = getMethodDetailsHeader(detailsList); + Content memberList = writer.getMemberList(); + + for (Element method : methods) { + currentMethod = (ExecutableElement)method; + Content methodContent = getMethodHeader(currentMethod); + + buildSignature(methodContent); + buildDeprecationInfo(methodContent); + buildPreviewInfo(methodContent); + buildMethodComments(methodContent); + buildTagInfo(methodContent); + + memberList.add(writer.getMemberListItem(methodContent)); + } + Content methodDetails = getMethodDetails(methodDetailsHeader, memberList); + detailsList.add(methodDetails); + } + } + + /** + * Build the signature. + * + * @param methodContent the content to which the documentation will be added + */ + protected void buildSignature(Content methodContent) { + methodContent.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); + } + + /** + * Build the preview information. + * + * @param methodContent the content to which the documentation will be added + */ + protected void buildPreviewInfo(Content methodContent) { + addPreview(currentMethod, methodContent); + } + + /** + * Build the comments for the method. Do nothing if + * {@link BaseOptions#noComment()} is set to true. + * + * @param methodContent the content to which the documentation will be added + */ + protected void buildMethodComments(Content methodContent) { + if (!options.noComment()) { + assert utils.isMethod(currentMethod); // not all executables are methods + var docFinder = utils.docFinder(); + Optional<ExecutableElement> r = docFinder.search(currentMethod, + m -> DocFinder.Result.fromOptional(utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m))).toOptional(); + ExecutableElement method = r.orElse(currentMethod); + TypeMirror containingType = method.getEnclosingElement().asType(); + addComments(containingType, method, methodContent); + } + } + + /** + * Build the tag information. + * + * @param methodContent the content to which the documentation will be added + */ + protected void buildTagInfo(Content methodContent) { + addTags(currentMethod, methodContent); + } + @Override public Content getMemberSummaryHeader(TypeElement typeElement, Content target) { target.add(MarkerComments.START_OF_METHOD_SUMMARY); @@ -85,8 +187,7 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter HtmlIds.METHOD_SUMMARY, summariesList, content); } - @Override - public Content getMethodDetailsHeader(Content content) { + protected Content getMethodDetailsHeader(Content content) { content.add(MarkerComments.START_OF_METHOD_DETAILS); Content methodDetailsContent = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, @@ -95,8 +196,7 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter return methodDetailsContent; } - @Override - public Content getMethodHeader(ExecutableElement method) { + protected Content getMethodHeader(ExecutableElement method) { Content content = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, Text.of(name(method))); @@ -109,8 +209,7 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter .setId(htmlIds.forMember(method)); } - @Override - public Content getSignature(ExecutableElement method) { + protected Content getSignature(ExecutableElement method) { return new Signatures.MemberSignature(method, this) .setTypeParameters(getTypeParameters(method)) .setReturnType(getReturnType(method)) @@ -120,18 +219,15 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter .toContent(); } - @Override - public void addDeprecated(ExecutableElement method, Content methodContent) { + protected void addDeprecated(ExecutableElement method, Content methodContent) { addDeprecatedInfo(method, methodContent); } - @Override - public void addPreview(ExecutableElement method, Content content) { + protected void addPreview(ExecutableElement method, Content content) { addPreviewInfo(method, content); } - @Override - public void addComments(TypeMirror holderType, ExecutableElement method, Content methodContent) { + protected void addComments(TypeMirror holderType, ExecutableElement method, Content methodContent) { TypeElement holder = utils.asTypeElement(holderType); if (!utils.getFullBody(method).isEmpty()) { if (holder.equals(typeElement) || @@ -160,13 +256,11 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter } } - @Override - public void addTags(ExecutableElement method, Content methodContent) { + protected void addTags(ExecutableElement method, Content methodContent) { writer.addTagsInfo(method, methodContent); } - @Override - public Content getMethodDetails(Content methodDetailsHeader, Content methodDetails) { + protected Content getMethodDetails(Content methodDetailsHeader, Content methodDetails) { Content c = new ContentBuilder(methodDetailsHeader, methodDetails); return getMember(HtmlTree.SECTION(HtmlStyle.methodDetails, c) .setId(HtmlIds.METHOD_DETAIL)); @@ -264,15 +358,9 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter Contents contents = writer.contents; Content label; HtmlLinkInfo.Kind context; - if (utils.isAbstract(holder) && utils.isAbstract(method)) { - //Abstract method is implemented from abstract class, - //not overridden - label = contents.specifiedByLabel; - context = HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS; - } else { - label = contents.overridesLabel; - context = HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS; - } + // Abstract method is implemented from abstract class, not overridden + label = utils.isAbstract(holder) && utils.isAbstract(method) ? contents.specifiedByLabel : contents.overridesLabel; + context = HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS; dl.add(HtmlTree.DT(label)); Content overriddenTypeLink = writer.getLink(new HtmlLinkInfo(writer.configuration, context, overriddenType)); @@ -347,8 +435,7 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter return new ContentBuilder(); } - @Override - public Content getMemberHeader(){ + 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 91b3f02ed9c..93152c49a61 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,7 +34,6 @@ import javax.lang.model.element.ModuleElement; 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.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java similarity index 90% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java index 2c8e684a017..dd8f3b4cd84 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java @@ -50,8 +50,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.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter; +import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; @@ -60,7 +59,7 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; * required modules, packages and service types for the module. A click on any of the links will update * the frame with the clicked element page. */ -public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryWriter { +public class ModuleWriter extends HtmlDocletWriter { /** * The module being documented. @@ -91,7 +90,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW * A package that is neither exported or opened to any modules is a concealed package. * An open module opens all its packages to all modules. */ - class PackageEntry { + static class PackageEntry { /** * Summary of package exports: * If null, the package is not exported to any modules; @@ -159,15 +158,107 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW * @param configuration the configuration of the doclet. * @param mdle Module under consideration. */ - public ModuleWriterImpl(HtmlConfiguration configuration, ModuleElement mdle) { + public ModuleWriter(HtmlConfiguration configuration, ModuleElement mdle) { super(configuration, configuration.docPaths.moduleSummary(mdle)); this.mdle = mdle; this.moduleMode = configuration.docEnv.getModuleMode(); computeModulesData(); } - @Override - public Content getModuleHeader(String heading) { + /** + * Build the module summary. + * + * @throws DocletException if there is a problem while building the documentation + */ + public void build() throws DocletException { + buildModuleDoc(); + } + + /** + * Build the module documentation. + * + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildModuleDoc() throws DocletException { + Content content = getModuleHeader(mdle.getQualifiedName().toString()); + + buildContent(); + + addModuleFooter(); + printDocument(content); + var docFilesHandler = configuration.getWriterFactory().getDocFilesHandler(mdle); + docFilesHandler.copyDocFiles(); + } + + /** + * Build the content for the module doc. + */ + protected void buildContent() { + Content moduleContent = getContentHeader(); + + addModuleSignature(moduleContent); + buildModuleDescription(moduleContent); + buildSummary(moduleContent); + + addModuleContent(moduleContent); + } + + /** + * Builds the list of summary sections for this module. + * + * @param target the module content to which the summaries will + * be added + */ + protected void buildSummary(Content target) { + Content summariesList = getSummariesList(); + + buildPackagesSummary(summariesList); + buildModulesSummary(summariesList); + buildServicesSummary(summariesList); + + target.add(getSummary(summariesList)); + } + + /** + * Builds the summary of the module dependencies of this module. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildModulesSummary(Content summariesList) { + addModulesSummary(summariesList); + } + + /** + * Builds the summary of the packages exported or opened by this module. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildPackagesSummary(Content summariesList) { + addPackagesSummary(summariesList); + } + + /** + * Builds the summary of the services used or provided by this module. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildServicesSummary(Content summariesList) { + addServicesSummary(summariesList); + } + + /** + * Builds the description for this module. + * + * @param moduleContent the content to which the module description will + * be added + */ + protected void buildModuleDescription(Content moduleContent) { + if (!options.noComment()) { + addModuleDescription(moduleContent); + } + } + + protected Content getModuleHeader(String heading) { HtmlTree body = getBody(getWindowTitle(mdle.getQualifiedName().toString())); var div = HtmlTree.DIV(HtmlStyle.header); Content moduleHead = new ContentBuilder(); @@ -197,18 +288,15 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW )); } - @Override - public Content getContentHeader() { + protected Content getContentHeader() { return new ContentBuilder(); } - @Override - public Content getSummariesList() { + protected Content getSummariesList() { return HtmlTree.UL(HtmlStyle.summaryList); } - @Override - public Content getSummary(Content source) { + protected Content getSummary(Content source) { return HtmlTree.SECTION(HtmlStyle.summary, source); } @@ -448,8 +536,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); } - @Override - public void addModulesSummary(Content summariesList) { + protected void addModulesSummary(Content summariesList) { if (display(requires) || display(indirectModules)) { TableHeader requiresTableHeader = new TableHeader(contents.modifierLabel, contents.moduleLabel, @@ -492,8 +579,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW } } - @Override - public void addPackagesSummary(Content summariesList) { + protected void addPackagesSummary(Content summariesList) { if (display(packages) || display(indirectPackages) || display(indirectOpenPackages)) { var section = HtmlTree.SECTION(HtmlStyle.packagesSummary) @@ -659,8 +745,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW } } - @Override - public void addServicesSummary(Content summariesList) { + protected void addServicesSummary(Content summariesList) { boolean haveUses = displayServices(uses, usesTrees); boolean haveProvides = displayServices(provides.keySet(), providesTrees); @@ -786,8 +871,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW } } - @Override - public void addModuleDescription(Content moduleContent) { + protected void addModuleDescription(Content moduleContent) { addPreviewInfo(mdle, moduleContent); if (!utils.getFullBody(mdle).isEmpty()) { var tree = HtmlTree.SECTION(HtmlStyle.moduleDescription) @@ -800,24 +884,20 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW } } - @Override - public void addModuleSignature(Content moduleContent) { + protected void addModuleSignature(Content moduleContent) { moduleContent.add(new HtmlTree(TagName.HR)); moduleContent.add(Signatures.getModuleSignature(mdle, this)); } - @Override - public void addModuleContent(Content source) { + protected void addModuleContent(Content source) { bodyContents.addMainContent(source); } - @Override - public void addModuleFooter() { + protected void addModuleFooter() { bodyContents.setFooter(getFooter()); } - @Override - public void printDocument(Content content) throws DocFileIOException { + protected void printDocument(Content content) throws DocFileIOException { content.add(bodyContents); printHtmlDocument(configuration.metakeywords.getMetaKeywordsForModule(mdle), getDescription("declaration", mdle), getLocalStylesheets(mdle), content); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Navigation.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Navigation.java index 7c01d9477d4..fb75d36946b 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Navigation.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Navigation.java @@ -42,15 +42,12 @@ 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.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; import jdk.javadoc.internal.doclets.toolkit.util.DocLink; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - /** * Factory for navigation bar. * @@ -98,7 +95,7 @@ public class Navigation { SEARCH, SYSTEM_PROPERTIES, TREE, - USE; + USE } /** diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java similarity index 93% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java index 009110785be..3bab83a2d4b 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/NestedClassWriter.java @@ -36,20 +36,17 @@ import jdk.javadoc.internal.doclets.formats.html.markup.Entity; 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.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; /** * Writes nested class documentation in HTML format. */ -public class NestedClassWriterImpl extends AbstractMemberWriter - implements MemberSummaryWriter { +public class NestedClassWriter extends AbstractMemberWriter { - public NestedClassWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) { + public NestedClassWriter(SubWriterHolderWriter writer, TypeElement typeElement) { super(writer, typeElement); } - public NestedClassWriterImpl(SubWriterHolderWriter writer) { + public NestedClassWriter(SubWriterHolderWriter writer) { super(writer); } 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 d20616285d1..ae3b3f1f482 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 @@ -34,7 +34,6 @@ 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.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 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 fb9f62d9f98..dcce9d709d2 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 @@ -32,7 +32,6 @@ 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.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 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 8453c63b5e7..b3ffa7a2cd1 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 @@ -33,7 +33,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.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 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 91326db4827..1f5b4e6fb40 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 @@ -41,7 +41,6 @@ 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.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java similarity index 79% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java index fadcc7451f4..ef0ae1ea065 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageWriter.java @@ -48,8 +48,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.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter; +import jdk.javadoc.internal.doclets.toolkit.DocletException; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; @@ -60,8 +59,7 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; * frame. This will list all the Class Kinds in the package. A click on any * class-kind will update the frame with the clicked class-kind page. */ -public class PackageWriterImpl extends HtmlDocletWriter - implements PackageSummaryWriter { +public class PackageWriter extends HtmlDocletWriter { /** * The package being documented. @@ -94,7 +92,7 @@ public class PackageWriterImpl extends HtmlDocletWriter * @param configuration the configuration of the doclet. * @param packageElement PackageElement under consideration. */ - public PackageWriterImpl(HtmlConfiguration configuration, PackageElement packageElement) { + public PackageWriter(HtmlConfiguration configuration, PackageElement packageElement) { super(configuration, configuration.docPaths.forPackage(packageElement) .resolve(DocPaths.PACKAGE_SUMMARY)); @@ -102,8 +100,107 @@ public class PackageWriterImpl extends HtmlDocletWriter computePackageData(); } - @Override - public Content getPackageHeader() { + /** + * Build the package summary. + * + * @throws DocletException if there is a problem while building the documentation + */ + public void build() throws DocletException { + buildPackageDoc(); + } + + /** + * Build the package documentation. + * + * @throws DocletException if there is a problem while building the documentation + */ + protected void buildPackageDoc() throws DocletException { + Content content = getPackageHeader(); + + buildContent(); + + addPackageFooter(); + printDocument(content); + var docFilesHandler = configuration + .getWriterFactory() + .getDocFilesHandler(packageElement); + docFilesHandler.copyDocFiles(); + } + + /** + * Build the content for the package. + */ + protected void buildContent() { + Content packageContent = getContentHeader(); + + addPackageSignature(packageContent); + buildPackageDescription(packageContent); + buildPackageTags(packageContent); + buildSummary(packageContent); + + addPackageContent(packageContent); + } + + /** + * Builds the list of summaries for the different kinds of types in this package. + * + * @param packageContent the package content to which the summaries will + * be added + */ + protected void buildSummary(Content packageContent) { + Content summariesList = getSummariesList(); + + buildRelatedPackagesSummary(summariesList); + buildAllClassesAndInterfacesSummary(summariesList); + + packageContent.add(getPackageSummary(summariesList)); + } + + /** + * Builds a list of "nearby" packages (subpackages, superpackages, and sibling packages). + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildRelatedPackagesSummary(Content summariesList) { + addRelatedPackagesSummary(summariesList); + } + + /** + * Builds the summary for all classes and interfaces in this package. + * + * @param summariesList the list of summaries to which the summary will be added + */ + protected void buildAllClassesAndInterfacesSummary(Content summariesList) { + addAllClassesAndInterfacesSummary(summariesList); + } + + + /** + * Build the description of the summary. + * + * @param packageContent the content to which the package description will + * be added + */ + protected void buildPackageDescription(Content packageContent) { + if (options.noComment()) { + return; + } + addPackageDescription(packageContent); + } + + /** + * Build the tags of the summary. + * + * @param packageContent the content to which the package tags will be added + */ + protected void buildPackageTags(Content packageContent) { + if (options.noComment()) { + return; + } + addPackageTags(packageContent); + } + + protected Content getPackageHeader() { String packageName = getLocalizedPackageName(packageElement).toString(); HtmlTree body = getBody(getWindowTitle(packageName)); var div = HtmlTree.DIV(HtmlStyle.header); @@ -129,8 +226,7 @@ public class PackageWriterImpl extends HtmlDocletWriter return body; } - @Override - public Content getContentHeader() { + protected Content getContentHeader() { return new ContentBuilder(); } @@ -219,13 +315,11 @@ public class PackageWriterImpl extends HtmlDocletWriter } } - @Override - public Content getSummariesList() { + protected Content getSummariesList() { return HtmlTree.UL(HtmlStyle.summaryList); } - @Override - public void addRelatedPackagesSummary(Content summaryContent) { + protected void addRelatedPackagesSummary(Content summaryContent) { boolean showModules = configuration.showModules && hasRelatedPackagesInOtherModules(relatedPackages); TableHeader tableHeader= showModules ? new TableHeader(contents.moduleLabel, contents.packageLabel, contents.descriptionLabel) @@ -247,10 +341,10 @@ public class PackageWriterImpl extends HtmlDocletWriter .setId(HtmlIds.CLASS_SUMMARY) .setDefaultTab(contents.allClassesAndInterfacesLabel) .addTab(contents.interfaces, utils::isPlainInterface) - .addTab(contents.classes, e -> utils.isNonThrowableClass(e)) + .addTab(contents.classes, utils::isNonThrowableClass) .addTab(contents.enums, utils::isEnum) - .addTab(contents.records, e -> utils.isRecord(e)) - .addTab(contents.exceptionClasses, e -> utils.isThrowable(e)) + .addTab(contents.records, utils::isRecord) + .addTab(contents.exceptionClasses, utils::isThrowable) .addTab(contents.annotationTypes, utils::isAnnotationInterface); for (TypeElement typeElement : allClasses) { if (typeElement != null && utils.isCoreClass(typeElement)) { @@ -319,8 +413,7 @@ public class PackageWriterImpl extends HtmlDocletWriter } } - @Override - public void addPackageDescription(Content packageContent) { + protected void addPackageDescription(Content packageContent) { addPreviewInfo(packageElement, packageContent); if (!utils.getBody(packageElement).isEmpty()) { section.setId(HtmlIds.PACKAGE_DESCRIPTION); @@ -329,30 +422,25 @@ public class PackageWriterImpl extends HtmlDocletWriter } } - @Override - public void addPackageTags(Content packageContent) { + protected void addPackageTags(Content packageContent) { addTagsInfo(packageElement, section); packageContent.add(section); } - @Override - public void addPackageSignature(Content packageContent) { + protected void addPackageSignature(Content packageContent) { packageContent.add(new HtmlTree(TagName.HR)); packageContent.add(Signatures.getPackageSignature(packageElement, this)); } - @Override - public void addPackageContent(Content packageContent) { + protected void addPackageContent(Content packageContent) { bodyContents.addMainContent(packageContent); } - @Override - public void addPackageFooter() { + protected void addPackageFooter() { bodyContents.setFooter(getFooter()); } - @Override - public void printDocument(Content content) throws DocFileIOException { + protected void printDocument(Content content) throws DocFileIOException { String description = getDescription("declaration", packageElement); List<DocPath> localStylesheets = getLocalStylesheets(packageElement); content.add(bodyContents); @@ -360,8 +448,7 @@ public class PackageWriterImpl extends HtmlDocletWriter description, localStylesheets, content); } - @Override - public Content getPackageSummary(Content summaryContent) { + protected Content getPackageSummary(Content summaryContent) { return HtmlTree.SECTION(HtmlStyle.summary, summaryContent); } 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 5a03420e0db..1e19b69a8c8 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,7 +38,6 @@ 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.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java similarity index 62% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriterImpl.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java index a9715392f76..2a2ecdc23be 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriterImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PropertyWriter.java @@ -25,29 +25,137 @@ package jdk.javadoc.internal.doclets.formats.html; +import java.util.ArrayList; +import java.util.stream.Collectors; + import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; +import com.sun.source.doctree.DocCommentTree; +import com.sun.source.doctree.DocTree; + import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.Entity; 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.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.PropertyWriter; +import jdk.javadoc.internal.doclets.toolkit.BaseOptions; +import jdk.javadoc.internal.doclets.toolkit.CommentUtils; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; /** * Writes property documentation in HTML format. */ -public class PropertyWriterImpl extends AbstractMemberWriter - implements PropertyWriter, MemberSummaryWriter { +public class PropertyWriter extends AbstractMemberWriter { - public PropertyWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) { - super(writer, typeElement); + /** + * The index of the current property that is being documented at this point + * in time. + */ + private ExecutableElement currentProperty; + + public PropertyWriter(ClassWriter writer) { + super(writer, writer.typeElement); } + public void build(Content target) { + buildPropertyDoc(target); + } + + /** + * Build the property documentation. + * + * @param detailsList the content to which the documentation will be added + */ + protected void buildPropertyDoc(Content detailsList) { + var properties = getVisibleMembers(VisibleMemberTable.Kind.PROPERTIES); + if (!properties.isEmpty()) { + Content propertyDetailsHeader = getPropertyDetailsHeader(detailsList); + Content memberList = getMemberList(); + + for (Element property : properties) { + currentProperty = (ExecutableElement)property; + Content propertyContent = getPropertyHeaderContent(currentProperty); + + buildSignature(propertyContent); + buildPropertyComments(propertyContent); + buildTagInfo(propertyContent); + + memberList.add(getMemberListItem(propertyContent)); + } + Content propertyDetails = getPropertyDetails(propertyDetailsHeader, memberList); + detailsList.add(propertyDetails); + } + } + + /** + * Build the signature. + * + * @param propertyContent the content to which the documentation will be added + */ + protected void buildSignature(Content propertyContent) { + propertyContent.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); + } + + /** + * Build the preview information. + * + * @param propertyContent the content to which the documentation will be added + */ + protected void buildPreviewInfo(Content propertyContent) { + addPreview(currentProperty, propertyContent); + } + + /** + * Build the comments for the property. Do nothing if + * {@link BaseOptions#noComment()} is set to true. + * + * @param propertyContent the content to which the documentation will be added + */ + protected void buildPropertyComments(Content propertyContent) { + if (!options.noComment()) { + addComments(currentProperty, propertyContent); + } + } + + /** + * Build the tag information. + * + * @param propertyContent the content to which the documentation will be added + */ + protected void buildTagInfo(Content propertyContent) { + CommentUtils cmtUtils = configuration.cmtUtils; + DocCommentTree dct = utils.getDocCommentTree(currentProperty); + var fullBody = dct.getFullBody(); + ArrayList<DocTree> blockTags = dct.getBlockTags().stream() + .filter(t -> t.getKind() != DocTree.Kind.RETURN) + .collect(Collectors.toCollection(ArrayList::new)); + String sig = "#" + currentProperty.getSimpleName() + "()"; + blockTags.add(cmtUtils.makeSeeTree(sig, currentProperty)); + // The property method is used as a proxy for the property + // (which does not have an explicit element of its own.) + // Temporarily override the doc comment for the property method + // by removing the `@return` tag, which should not be displayed for + // the property. + CommentUtils.DocCommentInfo prev = cmtUtils.setDocCommentTree(currentProperty, fullBody, blockTags); + try { + addTags(currentProperty, propertyContent); + } finally { + cmtUtils.setDocCommentInfo(currentProperty, prev); + } + } + + @Override public Content getMemberSummaryHeader(TypeElement typeElement, Content content) { content.add(MarkerComments.START_OF_PROPERTY_SUMMARY); @@ -62,8 +170,7 @@ public class PropertyWriterImpl extends AbstractMemberWriter HtmlIds.PROPERTY_SUMMARY, summariesList, content); } - @Override - public Content getPropertyDetailsHeader(Content memberDetails) { + protected Content getPropertyDetailsHeader(Content memberDetails) { memberDetails.add(MarkerComments.START_OF_PROPERTY_DETAILS); Content propertyDetailsContent = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, @@ -72,8 +179,7 @@ public class PropertyWriterImpl extends AbstractMemberWriter return propertyDetailsContent; } - @Override - public Content getPropertyHeaderContent(ExecutableElement property) { + protected Content getPropertyHeaderContent(ExecutableElement property) { Content content = new ContentBuilder(); var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, Text.of(utils.getPropertyLabel(name(property)))); @@ -82,24 +188,20 @@ public class PropertyWriterImpl extends AbstractMemberWriter .setId(htmlIds.forProperty(property)); } - @Override - public Content getSignature(ExecutableElement property) { + protected Content getSignature(ExecutableElement property) { return new Signatures.MemberSignature(property, this) .setType(utils.getReturnType(typeElement, property)) .setAnnotations(writer.getAnnotationInfo(property, true)) .toContent(); } - @Override - public void addDeprecated(ExecutableElement property, Content propertyContent) { + protected void addDeprecated(ExecutableElement property, Content propertyContent) { } - @Override - public void addPreview(ExecutableElement property, Content content) { + protected void addPreview(ExecutableElement property, Content content) { } - @Override - public void addComments(ExecutableElement property, Content propertyContent) { + protected void addComments(ExecutableElement property, Content propertyContent) { TypeElement holder = (TypeElement)property.getEnclosingElement(); if (!utils.getFullBody(property).isEmpty()) { if (holder.equals(typeElement) || @@ -126,13 +228,11 @@ public class PropertyWriterImpl extends AbstractMemberWriter } } - @Override - public void addTags(ExecutableElement property, Content propertyContent) { + protected void addTags(ExecutableElement property, Content propertyContent) { writer.addTagsInfo(property, propertyContent); } - @Override - public Content getPropertyDetails(Content memberDetailsHeader, Content memberDetails) { + protected Content getPropertyDetails(Content memberDetailsHeader, Content memberDetails) { return writer.getDetailsListItem( HtmlTree.SECTION(HtmlStyle.propertyDetails) .setId(HtmlIds.PROPERTY_DETAIL) 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 21bd17c1a58..1e07f01deca 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 @@ -34,7 +34,6 @@ 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.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialFieldWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java similarity index 83% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialFieldWriter.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java index 2838e549451..c709c963cff 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialFieldWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialFieldWriter.java @@ -41,18 +41,15 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.formats.html.taglets.TagletWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; /** * Generate serialized form for serializable fields. * Documentation denoted by the tags <code>serial</code> and * <code>serialField</code> is processed. */ -public class HtmlSerialFieldWriter extends FieldWriterImpl - implements SerializedFormWriter.SerialFieldWriter { +public class SerialFieldWriter extends FieldWriter { - public HtmlSerialFieldWriter(SubWriterHolderWriter writer, TypeElement typeElement) { + public SerialFieldWriter(SubWriterHolderWriter writer, TypeElement typeElement) { super(writer, typeElement); } @@ -60,18 +57,15 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl return utils.serializableFields(te); } - @Override - public Content getSerializableFieldsHeader() { + protected Content getSerializableFieldsHeader() { return HtmlTree.UL(HtmlStyle.blockList); } - @Override - public Content getFieldsContentHeader(boolean isLastContent) { + protected Content getFieldsContentHeader(boolean isLastContent) { return new HtmlTree(TagName.LI).setStyle(HtmlStyle.blockList); } - @Override - public Content getSerializableFields(String heading, Content source) { + protected Content getSerializableFields(String heading, Content source) { var section = HtmlTree.SECTION(HtmlStyle.detail); if (!source.isEmpty()) { Content headingContent = Text.of(heading); @@ -82,8 +76,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl return HtmlTree.LI(section); } - @Override - public void addMemberHeader(TypeMirror fieldType, String fieldName, Content content) { + protected void addMemberHeader(TypeMirror fieldType, String fieldName, Content content) { Content nameContent = Text.of(fieldName); var heading = HtmlTree.HEADING(Headings.SerializedForm.MEMBER_HEADING, nameContent); content.add(heading); @@ -102,8 +95,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl * @param field the field to document. * @param content the content to which the deprecated info will be added */ - @Override - public void addMemberDeprecatedInfo(VariableElement field, Content content) { + protected void addMemberDeprecatedInfo(VariableElement field, Content content) { addDeprecatedInfo(field, content); } @@ -113,8 +105,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl * @param field the field to document. * @param content the content to which the deprecated info will be added */ - @Override - public void addMemberDescription(VariableElement field, Content content) { + protected void addMemberDescription(VariableElement field, Content content) { if (!utils.getFullBody(field).isEmpty()) { writer.addInlineComment(field, content); } @@ -130,8 +121,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl * @param serialFieldTag the field to document (represented by tag) * @param content the content to which the deprecated info will be added */ - @Override - public void addMemberDescription(VariableElement field, SerialFieldTree serialFieldTag, Content content) { + protected void addMemberDescription(VariableElement field, SerialFieldTree serialFieldTag, Content content) { List<? extends DocTree> description = serialFieldTag.getDescription(); if (!description.isEmpty()) { Content serialFieldContent = writer.commentTagsToContent(field, @@ -148,8 +138,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl * @param field the field to document. * @param content the content to which the member tags info will be added */ - @Override - public void addMemberTags(VariableElement field, Content content) { + protected void addMemberTags(VariableElement field, Content content) { Content tagContent = writer.getBlockTagOutput(field); if (!tagContent.isEmpty()) { var dl = HtmlTree.DL(HtmlStyle.notes); @@ -166,8 +155,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl * @param field the field to check overview details for. * @return true if overview details need to be printed */ - @Override - public boolean shouldPrintOverview(VariableElement field) { + protected boolean shouldPrintOverview(VariableElement field) { if (!options.noComment()) { if(!utils.getFullBody(field).isEmpty() || writer.hasSerializationOverviewTags(field)) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialMethodWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java similarity index 81% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialMethodWriter.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java index 2f9b7da1b2f..caa400c9470 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlSerialMethodWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerialMethodWriter.java @@ -29,11 +29,9 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; 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.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; import jdk.javadoc.internal.doclets.formats.html.taglets.TagletManager; @@ -41,20 +39,17 @@ import jdk.javadoc.internal.doclets.formats.html.taglets.TagletManager; * Generate serialized form for Serializable/Externalizable methods. * Documentation denoted by the <code>serialData</code> tag is processed. */ -public class HtmlSerialMethodWriter extends MethodWriterImpl implements - SerializedFormWriter.SerialMethodWriter { +public class SerialMethodWriter extends MethodWriter { - public HtmlSerialMethodWriter(SubWriterHolderWriter writer, TypeElement typeElement) { + public SerialMethodWriter(SubWriterHolderWriter writer, TypeElement typeElement) { super(writer, typeElement); } - @Override - public Content getSerializableMethodsHeader() { + protected Content getSerializableMethodsHeader() { return HtmlTree.UL(HtmlStyle.blockList); } - @Override - public Content getMethodsContentHeader(boolean isLastContent) { + protected Content getMethodsContentHeader(boolean isLastContent) { return new HtmlTree(TagName.LI); } @@ -66,8 +61,7 @@ public class HtmlSerialMethodWriter extends MethodWriterImpl implements * content * @return a content for the serializable methods content */ - @Override - public Content getSerializableMethods(String heading, Content source) { + protected Content getSerializableMethods(String heading, Content source) { Content headingContent = Text.of(heading); var serialHeading = HtmlTree.HEADING(Headings.SerializedForm.CLASS_SUBHEADING, headingContent); var section = HtmlTree.SECTION(HtmlStyle.detail, serialHeading); @@ -81,8 +75,7 @@ public class HtmlSerialMethodWriter extends MethodWriterImpl implements * @param msg the message to be displayed * @return no customization message content */ - @Override - public Content getNoCustomizationMsg(String msg) { + protected Content getNoCustomizationMsg(String msg) { return Text.of(msg); } @@ -92,8 +85,7 @@ public class HtmlSerialMethodWriter extends MethodWriterImpl implements * @param member the method document to be listed * @param methodsContent the content to which the member header will be added */ - @Override - public void addMemberHeader(ExecutableElement member, Content methodsContent) { + protected void addMemberHeader(ExecutableElement member, Content methodsContent) { Content memberContent = Text.of(name(member)); var heading = HtmlTree.HEADING(Headings.SerializedForm.MEMBER_HEADING, memberContent); methodsContent.add(heading); @@ -106,8 +98,7 @@ public class HtmlSerialMethodWriter extends MethodWriterImpl implements * @param member the method to document. * @param methodsContent the content to which the deprecated info will be added */ - @Override - public void addDeprecatedMemberInfo(ExecutableElement member, Content methodsContent) { + protected void addDeprecatedMemberInfo(ExecutableElement member, Content methodsContent) { addDeprecatedInfo(member, methodsContent); } @@ -117,8 +108,7 @@ public class HtmlSerialMethodWriter extends MethodWriterImpl implements * @param member the method to document. * @param methodsContent the content to which the deprecated info will be added */ - @Override - public void addMemberDescription(ExecutableElement member, Content methodsContent) { + protected void addMemberDescription(ExecutableElement member, Content methodsContent) { addComment(member, methodsContent); } @@ -128,8 +118,7 @@ public class HtmlSerialMethodWriter extends MethodWriterImpl implements * @param member the method to document. * @param methodsContent the content to which the member tags info will be added */ - @Override - public void addMemberTags(ExecutableElement member, Content methodsContent) { + protected void addMemberTags(ExecutableElement member, Content methodsContent) { TagletManager tagletManager = configuration.tagletManager; Content tagContent = writer.getBlockTagOutput(member, tagletManager.getSerializedFormTaglets()); var dl = HtmlTree.DL(HtmlStyle.notes); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java similarity index 67% rename from src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java rename to src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java index 7432a9dd471..1a5d328fd9f 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/SerializedFormBuilder.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -23,12 +23,11 @@ * questions. */ -package jdk.javadoc.internal.doclets.toolkit.builders; - +package jdk.javadoc.internal.doclets.formats.html; import java.util.Collection; -import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -41,31 +40,34 @@ import javax.lang.model.type.TypeMirror; import com.sun.source.doctree.SerialFieldTree; import com.sun.source.doctree.SerialTree; -import jdk.javadoc.internal.doclets.toolkit.Content; + +import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; +import jdk.javadoc.internal.doclets.formats.html.markup.Entity; +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.DocletException; -import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; +import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; +import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; +import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; import jdk.javadoc.internal.doclets.toolkit.util.Utils; /** - * Builds the serialized form. + * Generates the Serialized Form Information Page, <i>serialized-form.html</i>. */ -public class SerializedFormBuilder extends AbstractBuilder { - - /** - * The writer for this builder. - */ - private SerializedFormWriter writer; +public class SerializedFormWriter extends SubWriterHolderWriter { /** * The writer for serializable fields. */ - private SerializedFormWriter.SerialFieldWriter fieldWriter; + private SerialFieldWriter fieldWriter; /** * The writer for serializable method documentation. */ - private SerializedFormWriter.SerialMethodWriter methodWriter; + private SerialMethodWriter methodWriter; /** * The header for the serial version UID. Save the string @@ -90,22 +92,15 @@ public class SerializedFormBuilder extends AbstractBuilder { */ protected Element currentMember; - /** - * Construct a new SerializedFormBuilder. - * @param context the build context. - */ - private SerializedFormBuilder(Context context) { - super(context); - } + Set<TypeElement> visibleClasses; /** - * Construct a new SerializedFormBuilder. - * - * @param context the build context. - * @return the new SerializedFormBuilder + * @param configuration the configuration data for the doclet */ - public static SerializedFormBuilder getInstance(Context context) { - return new SerializedFormBuilder(context); + public SerializedFormWriter(HtmlConfiguration configuration) { + super(configuration, DocPaths.SERIALIZED_FORM, false); + visibleClasses = configuration.getIncludedTypeElements(); + configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.SERIALIZED_FORM); } /** @@ -113,19 +108,17 @@ public class SerializedFormBuilder extends AbstractBuilder { * * @throws DocletException if there is a problem while building the documentation */ - @Override - public void build() throws DocletException { + void build() throws DocletException { SortedSet<TypeElement> rootclasses = new TreeSet<>(utils.comparators.makeGeneralPurposeComparator()); rootclasses.addAll(configuration.getIncludedTypeElements()); if (!serialClassFoundToDocument(rootclasses)) { //Nothing to document. return; } - writer = configuration.getWriterFactory().getSerializedFormWriter(); - if (writer == null) { - //Doclet does not support this output. - return; - } + + configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.SERIALIZED_FORM); + writeGenerating(); + buildSerializedForm(); } @@ -135,39 +128,35 @@ public class SerializedFormBuilder extends AbstractBuilder { * @throws DocletException if there is a problem while building the documentation */ protected void buildSerializedForm() throws DocletException { - Content content = writer.getHeader(resources.getText( + Content content = getHeader(resources.getText( "doclet.Serialized_Form")); buildSerializedFormSummaries(); - writer.addFooter(); - writer.printDocument(content); + addFooter(); + printDocument(content); } /** * Build the serialized form summaries. - * - * @throws DocletException if there is a problem while building the documentation */ - protected void buildSerializedFormSummaries() - throws DocletException { - Content c = writer.getSerializedSummariesHeader(); + protected void buildSerializedFormSummaries() { + Content c = getSerializedSummariesHeader(); for (PackageElement pkg : configuration.packages) { currentPackage = pkg; buildPackageSerializedForm(c); } - writer.addSerializedContent(c); + addSerializedContent(c); } /** * Build the package serialized form for the current package being processed. * * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation */ - protected void buildPackageSerializedForm(Content target) throws DocletException { - Content packageSerializedHeader = writer.getPackageSerializedHeader(); + protected void buildPackageSerializedForm(Content target) { + Content packageSerializedHeader = getPackageSerializedHeader(); SortedSet<TypeElement> classes = utils.getAllClassesUnfiltered(currentPackage); if (classes.isEmpty()) { return; @@ -182,7 +171,7 @@ public class SerializedFormBuilder extends AbstractBuilder { buildPackageHeader(packageSerializedHeader); buildClassSerializedForm(packageSerializedHeader); - writer.addPackageSerialized(target, packageSerializedHeader); + addPackageSerialized(target, packageSerializedHeader); } /** @@ -191,33 +180,31 @@ public class SerializedFormBuilder extends AbstractBuilder { * @param target the content to which the documentation will be added */ protected void buildPackageHeader(Content target) { - target.add(writer.getPackageHeader(currentPackage)); + target.add(getPackageHeader(currentPackage)); } /** * Build the class serialized form. * * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation */ - protected void buildClassSerializedForm(Content target) - throws DocletException { - Content classSerializedHeader = writer.getClassSerializedHeader(); + protected void buildClassSerializedForm(Content target) { + Content classSerializedHeader = getClassSerializedHeader(); SortedSet<TypeElement> typeElements = utils.getAllClassesUnfiltered(currentPackage); for (TypeElement typeElement : typeElements) { currentTypeElement = typeElement; - fieldWriter = writer.getSerialFieldWriter(currentTypeElement); - methodWriter = writer.getSerialMethodWriter(currentTypeElement); + fieldWriter = getSerialFieldWriter(currentTypeElement); + methodWriter = getSerialMethodWriter(currentTypeElement); if (utils.isClass(currentTypeElement) && utils.isSerializable(currentTypeElement)) { if (!serialClassInclude(utils, currentTypeElement)) { continue; } - Content classHeader = writer.getClassHeader(currentTypeElement); + Content classHeader = getClassHeader(currentTypeElement); buildSerialUIDInfo(classHeader); buildClassContent(classHeader); - classSerializedHeader.add(writer.getMember(classHeader)); + classSerializedHeader.add(getMember(classHeader)); } } target.add(classSerializedHeader); @@ -229,12 +216,12 @@ public class SerializedFormBuilder extends AbstractBuilder { * @param target the content to which the serial UID information will be added */ protected void buildSerialUIDInfo(Content target) { - Content serialUIDHeader = writer.getSerialUIDInfoHeader(); + Content serialUIDHeader = getSerialUIDInfoHeader(); for (VariableElement field : utils.getFieldsUnfiltered(currentTypeElement)) { if (field.getSimpleName().toString().compareTo(SERIAL_VERSION_UID) == 0 && - field.getConstantValue() != null) { - writer.addSerialUIDInfo(SERIAL_VERSION_UID_HEADER, - utils.constantValueExpression(field), serialUIDHeader); + field.getConstantValue() != null) { + addSerialUIDInfo(SERIAL_VERSION_UID_HEADER, + utils.constantValueExpression(field), serialUIDHeader); break; } } @@ -245,10 +232,9 @@ public class SerializedFormBuilder extends AbstractBuilder { * Build the summaries for the methods and fields. * * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation */ - protected void buildClassContent(Content target) throws DocletException { - Content classContent = writer.getClassContentHeader(); + protected void buildClassContent(Content target) { + Content classContent = getClassContentHeader(); buildSerializableMethods(classContent); buildFieldHeader(classContent); @@ -261,9 +247,8 @@ public class SerializedFormBuilder extends AbstractBuilder { * Build the summaries for the methods that belong to the given class. * * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation */ - protected void buildSerializableMethods(Content target) throws DocletException { + protected void buildSerializableMethods(Content target) { Content serializableMethodsHeader = methodWriter.getSerializableMethodsHeader(); for (var i = utils.serializationMethods(currentTypeElement).iterator(); i.hasNext(); ) { currentMember = i.next(); @@ -313,9 +298,8 @@ public class SerializedFormBuilder extends AbstractBuilder { * Build the information for the method. * * @param methodsContent the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation */ - protected void buildMethodInfo(Content methodsContent) throws DocletException { + protected void buildMethodInfo(Content methodsContent) { if (options.noComment()) { return; } @@ -394,10 +378,8 @@ public class SerializedFormBuilder extends AbstractBuilder { * Build the summaries for the fields that belong to the given class. * * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation */ - protected void buildSerializableFields(Content target) - throws DocletException { + protected void buildSerializableFields(Content target) { Collection<VariableElement> members = utils.serializableFields(currentTypeElement); if (!members.isEmpty()) { Content serializableFieldsHeader = fieldWriter.getSerializableFieldsHeader(); @@ -548,7 +530,6 @@ public class SerializedFormBuilder extends AbstractBuilder { } List<? extends SerialTree> serial = utils.getSerialTrees(element); if (!serial.isEmpty()) { - CommentHelper ch = utils.getCommentHelper(element); // look for `@serial include|exclude` String serialtext = Utils.toLowerCase(serial.get(0).toString()); if (serialtext.contains("exclude")) { @@ -574,4 +555,172 @@ public class SerializedFormBuilder extends AbstractBuilder { } return false; } + + /** + * Get the given header. + * + * @param header the header to write + * @return the body content + */ + Content getHeader(String header) { + HtmlTree body = getBody(getWindowTitle(header)); + Content h1Content = Text.of(header); + var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, + HtmlStyle.title, h1Content); + var div = HtmlTree.DIV(HtmlStyle.header, heading); + bodyContents.setHeader(getHeader(PageMode.SERIALIZED_FORM)) + .addMainContent(div); + return body; + } + + /** + * Get the serialized form summaries header. + * + * @return the serialized form summaries header + */ + Content getSerializedSummariesHeader() { + return HtmlTree.UL(HtmlStyle.blockList); + } + + /** + * Get the package serialized form header. + * + * @return the package serialized form header tree + */ + Content getPackageSerializedHeader() { + return HtmlTree.SECTION(HtmlStyle.serializedPackageContainer); + } + + Content getPackageHeader(PackageElement packageElement) { + var heading = HtmlTree.HEADING_TITLE(Headings.SerializedForm.PACKAGE_HEADING, + contents.packageLabel); + heading.add(Entity.NO_BREAK_SPACE); + heading.add(getPackageLink(packageElement, Text.of(utils.getPackageName(packageElement)))); + return heading; + } + + Content getClassSerializedHeader() { + return HtmlTree.UL(HtmlStyle.blockList); + } + + /** + * Checks if a class is generated and is visible. + * + * @param typeElement the class being processed. + * @return true if the class, that is being processed, is generated and is visible. + */ + public boolean isVisibleClass(TypeElement typeElement) { + return visibleClasses.contains(typeElement) && configuration.isGeneratedDoc(typeElement) + && !utils.hasHiddenTag(typeElement); + } + + Content getClassHeader(TypeElement typeElement) { + Content classLink = (isVisibleClass(typeElement)) + ? getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.PLAIN, typeElement) + .label(configuration.getClassName(typeElement))) + : Text.of(utils.getFullyQualifiedName(typeElement)); + var section = HtmlTree.SECTION(HtmlStyle.serializedClassDetails) + .setId(htmlIds.forClass(typeElement)); + Content superClassLink = typeElement.getSuperclass() != null + ? getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, + typeElement.getSuperclass())) + : null; + Content interfaceLink = getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, + utils.isExternalizable(typeElement) + ? utils.getExternalizableType() + : utils.getSerializableType())); + + // Print the heading. + Content className = new ContentBuilder(); + className.add(utils.getTypeElementKindName(typeElement, false)); + className.add(Entity.NO_BREAK_SPACE); + className.add(classLink); + section.add(HtmlTree.HEADING(Headings.SerializedForm.CLASS_HEADING, className)); + // Print a simplified signature. + Content signature = new ContentBuilder(); + signature.add("class "); + signature.add(typeElement.getSimpleName()); + signature.add(" extends "); + signature.add(superClassLink); + signature.add(" implements "); + signature.add(interfaceLink); + section.add(HtmlTree.DIV(HtmlStyle.typeSignature, signature)); + return section; + } + + Content getSerialUIDInfoHeader() { + return HtmlTree.DL(HtmlStyle.nameValue); + } + + /** + * Adds the serial UID info. + * + * @param header the header that will show up before the UID. + * @param serialUID the serial UID to print. + * @param target the serial UID content to which the serial UID + * content will be added + */ + void addSerialUIDInfo(String header, + String serialUID, + Content target) + { + Content headerContent = Text.of(header); + target.add(HtmlTree.DT(headerContent)); + Content serialContent = Text.of(serialUID); + target.add(HtmlTree.DD(serialContent)); + } + + Content getClassContentHeader() { + return HtmlTree.UL(HtmlStyle.blockList); + } + + /** + * Add the serialized content section. + * + * @param source the serialized content to be added + */ + void addSerializedContent(Content source) { + bodyContents.addMainContent(source); + } + + void addPackageSerialized(Content serializedSummaries, + Content packageSerialized) + { + serializedSummaries.add(HtmlTree.LI(packageSerialized)); + } + + /** + * Add the footer. + */ + void addFooter() { + bodyContents.setFooter(getFooter()); + } + + void printDocument(Content source) throws DocFileIOException { + source.add(bodyContents); + printHtmlDocument(null, "serialized forms", source); + + if (configuration.mainIndex != null) { + configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS, + resources.getText("doclet.Serialized_Form"), path)); + } + } + + /** + * Return an instance of a SerialFieldWriter. + * + * @return an instance of a SerialFieldWriter. + */ + SerialFieldWriter getSerialFieldWriter(TypeElement typeElement) { + return new SerialFieldWriter(this, typeElement); + } + + /** + * Return an instance of a SerialMethodWriter. + * + * @return an instance of a SerialMethodWriter. + */ + SerialMethodWriter getSerialMethodWriter(TypeElement typeElement) { + return new SerialMethodWriter(this, typeElement); + } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java deleted file mode 100644 index 3193a730333..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SerializedFormWriterImpl.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 1998, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.formats.html; - -import java.util.Set; - -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; -import jdk.javadoc.internal.doclets.formats.html.markup.Entity; -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.Content; -import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; -import jdk.javadoc.internal.doclets.toolkit.util.IndexItem; - -/** - * Generates the Serialized Form Information Page, <i>serialized-form.html</i>. - */ -public class SerializedFormWriterImpl extends SubWriterHolderWriter - implements SerializedFormWriter { - - Set<TypeElement> visibleClasses; - - /** - * @param configuration the configuration data for the doclet - */ - public SerializedFormWriterImpl(HtmlConfiguration configuration) { - super(configuration, DocPaths.SERIALIZED_FORM); - visibleClasses = configuration.getIncludedTypeElements(); - configuration.conditionalPages.add(HtmlConfiguration.ConditionalPage.SERIALIZED_FORM); - } - - /** - * Get the given header. - * - * @param header the header to write - * @return the body content - */ - @Override - public Content getHeader(String header) { - HtmlTree body = getBody(getWindowTitle(header)); - Content h1Content = Text.of(header); - var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING, - HtmlStyle.title, h1Content); - var div = HtmlTree.DIV(HtmlStyle.header, heading); - bodyContents.setHeader(getHeader(PageMode.SERIALIZED_FORM)) - .addMainContent(div); - return body; - } - - /** - * Get the serialized form summaries header. - * - * @return the serialized form summaries header - */ - @Override - public Content getSerializedSummariesHeader() { - return HtmlTree.UL(HtmlStyle.blockList); - } - - /** - * Get the package serialized form header. - * - * @return the package serialized form header tree - */ - @Override - public Content getPackageSerializedHeader() { - return HtmlTree.SECTION(HtmlStyle.serializedPackageContainer); - } - - @Override - public Content getPackageHeader(PackageElement packageElement) { - var heading = HtmlTree.HEADING_TITLE(Headings.SerializedForm.PACKAGE_HEADING, - contents.packageLabel); - heading.add(Entity.NO_BREAK_SPACE); - heading.add(getPackageLink(packageElement, Text.of(utils.getPackageName(packageElement)))); - return heading; - } - - @Override - public Content getClassSerializedHeader() { - return HtmlTree.UL(HtmlStyle.blockList); - } - - /** - * Checks if a class is generated and is visible. - * - * @param typeElement the class being processed. - * @return true if the class, that is being processed, is generated and is visible. - */ - public boolean isVisibleClass(TypeElement typeElement) { - return visibleClasses.contains(typeElement) && configuration.isGeneratedDoc(typeElement) - && !utils.hasHiddenTag(typeElement); - } - - @Override - public Content getClassHeader(TypeElement typeElement) { - Content classLink = (isVisibleClass(typeElement)) - ? getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.PLAIN, typeElement) - .label(configuration.getClassName(typeElement))) - : Text.of(utils.getFullyQualifiedName(typeElement)); - var section = HtmlTree.SECTION(HtmlStyle.serializedClassDetails) - .setId(htmlIds.forClass(typeElement)); - Content superClassLink = typeElement.getSuperclass() != null - ? getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, - typeElement.getSuperclass())) - : null; - Content interfaceLink = getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, - utils.isExternalizable(typeElement) - ? utils.getExternalizableType() - : utils.getSerializableType())); - - // Print the heading. - Content className = new ContentBuilder(); - className.add(utils.getTypeElementKindName(typeElement, false)); - className.add(Entity.NO_BREAK_SPACE); - className.add(classLink); - section.add(HtmlTree.HEADING(Headings.SerializedForm.CLASS_HEADING, className)); - // Print a simplified signature. - Content signature = new ContentBuilder(); - signature.add("class "); - signature.add(typeElement.getSimpleName()); - signature.add(" extends "); - signature.add(superClassLink); - signature.add(" implements "); - signature.add(interfaceLink); - section.add(HtmlTree.DIV(HtmlStyle.typeSignature, signature)); - return section; - } - - @Override - public Content getSerialUIDInfoHeader() { - return HtmlTree.DL(HtmlStyle.nameValue); - } - - /** - * Adds the serial UID info. - * - * @param header the header that will show up before the UID. - * @param serialUID the serial UID to print. - * @param target the serial UID content to which the serial UID - * content will be added - */ - @Override - public void addSerialUIDInfo(String header, - String serialUID, - Content target) - { - Content headerContent = Text.of(header); - target.add(HtmlTree.DT(headerContent)); - Content serialContent = Text.of(serialUID); - target.add(HtmlTree.DD(serialContent)); - } - - @Override - public Content getClassContentHeader() { - return HtmlTree.UL(HtmlStyle.blockList); - } - - /** - * Add the serialized content section. - * - * @param source the serialized content to be added - */ - @Override - public void addSerializedContent(Content source) { - bodyContents.addMainContent(source); - } - - @Override - public void addPackageSerialized(Content serializedSummaries, - Content packageSerialized) - { - serializedSummaries.add(HtmlTree.LI(packageSerialized)); - } - - /** - * Add the footer. - */ - @Override - public void addFooter() { - bodyContents.setFooter(getFooter()); - } - - @Override - public void printDocument(Content source) throws DocFileIOException { - source.add(bodyContents); - printHtmlDocument(null, "serialized forms", source); - - if (configuration.mainIndex != null) { - configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS, - resources.getText("doclet.Serialized_Form"), path)); - } - } - - /** - * Return an instance of a SerialFieldWriter. - * - * @return an instance of a SerialFieldWriter. - */ - @Override - public SerialFieldWriter getSerialFieldWriter(TypeElement typeElement) { - return new HtmlSerialFieldWriter(this, typeElement); - } - - /** - * Return an instance of a SerialMethodWriter. - * - * @return an instance of a SerialMethodWriter. - */ - @Override - public SerialMethodWriter getSerialMethodWriter(TypeElement typeElement) { - return new HtmlSerialMethodWriter(this, typeElement); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Signatures.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Signatures.java index a47a99581f3..f4f472de9f9 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Signatures.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Signatures.java @@ -32,7 +32,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.formats.html.markup.TagName; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.Utils; import javax.lang.model.element.Element; @@ -63,7 +62,7 @@ import static javax.lang.model.element.Modifier.SYNCHRONIZED; public class Signatures { - public static Content getModuleSignature(ModuleElement mdle, ModuleWriterImpl moduleWriter) { + public static Content getModuleSignature(ModuleElement mdle, ModuleWriter moduleWriter) { var signature = HtmlTree.DIV(HtmlStyle.moduleSignature); Content annotations = moduleWriter.getAnnotationInfo(mdle, true); if (!annotations.isEmpty()) { @@ -80,7 +79,7 @@ public class Signatures { return signature; } - public static Content getPackageSignature(PackageElement pkg, PackageWriterImpl pkgWriter) { + public static Content getPackageSignature(PackageElement pkg, PackageWriter pkgWriter) { if (pkg.isUnnamed()) { return Text.EMPTY; } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java index 5afc8f8c31f..c01bc08b874 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java @@ -43,7 +43,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.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.Messages; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; 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 850dc49bb0d..d2e4fff02a0 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 @@ -37,7 +37,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; 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.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; /** @@ -49,7 +48,7 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocPath; * class subclass of this class can be subclassed to change formatting. * * @see AbstractMemberWriter - * @see ClassWriterImpl + * @see ClassWriter */ public abstract class SubWriterHolderWriter extends HtmlDocletWriter { @@ -62,6 +61,10 @@ public abstract class SubWriterHolderWriter extends HtmlDocletWriter { super(configuration, filename); } + public SubWriterHolderWriter(HtmlConfiguration configuration, DocPath filename, boolean generating) { + super(configuration, filename, generating); + } + /** * Add the summary header. * 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 764eee5687b..100c2454807 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 @@ -38,7 +38,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.Script; 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.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.SummaryAPIListBuilder; @@ -251,13 +250,15 @@ public abstract class SummaryListWriter<B extends SummaryAPIListBuilder> extends } protected Content getSummaryLink(Element e) { + // TODO: notable that these do not go through the writerFactory + // also maybe notable that annotation type members are not handled as such AbstractMemberWriter writer = switch (e.getKind()) { case INTERFACE, CLASS, ENUM, - ANNOTATION_TYPE, RECORD -> new NestedClassWriterImpl(this); - case FIELD -> new FieldWriterImpl(this); - case METHOD -> new MethodWriterImpl(this); - case CONSTRUCTOR -> new ConstructorWriterImpl(this); - case ENUM_CONSTANT -> new EnumConstantWriterImpl(this); + ANNOTATION_TYPE, RECORD -> new NestedClassWriter(this); + case FIELD -> new FieldWriter(this); + case METHOD -> new MethodWriter(this); + case CONSTRUCTOR -> new ConstructorWriter(this); + case ENUM_CONSTANT -> new EnumConstantWriter(this); case RECORD_COMPONENT -> throw new AssertionError("Record components are not supported by SummaryListWriter!"); default -> 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 05690b53594..983fc6db0d4 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 @@ -32,7 +32,6 @@ 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.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.DocletElement; import jdk.javadoc.internal.doclets.toolkit.OverviewElement; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Table.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Table.java index 90bcb0755d4..af960414658 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Table.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Table.java @@ -41,7 +41,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.TagName; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; /** * An HTML container used to display summary tables for various kinds of elements diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TableHeader.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TableHeader.java index d80e1f26e66..a505797764e 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TableHeader.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TableHeader.java @@ -34,7 +34,6 @@ 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.HtmlStyle; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.toolkit.Content; /** * A row of header cells for an HTML table. 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 cca0103adae..0b0b25fe808 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 @@ -34,7 +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.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; -import jdk.javadoc.internal.doclets.toolkit.Content; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 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 new file mode 100644 index 00000000000..c2602cfd23d --- /dev/null +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactory.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.javadoc.internal.doclets.formats.html; + + +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.util.ClassTree; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; + +/** + * The factory that returns HTML writers. + */ +// TODO: be more consistent about using this factory +public class WriterFactory { + + private final HtmlConfiguration configuration; + public WriterFactory(HtmlConfiguration configuration) { + this.configuration = configuration; + } + + public ConstantsSummaryWriter getConstantsSummaryWriter() { + return new ConstantsSummaryWriter(configuration); + } + + public PackageWriter getPackageSummaryWriter(PackageElement packageElement) { + return new PackageWriter(configuration, packageElement); + } + + public ModuleWriter getModuleSummaryWriter(ModuleElement mdle) { + return new ModuleWriter(configuration, mdle); + } + + public ClassWriter getClassWriter(TypeElement typeElement, ClassTree classTree) { + return new ClassWriter(configuration, typeElement, classTree); + } + + public AnnotationTypeMemberWriter getAnnotationTypeMemberWriter( + ClassWriter classWriter) { + TypeElement te = classWriter.getTypeElement(); + return new AnnotationTypeMemberWriter(classWriter, te, AnnotationTypeMemberWriter.Kind.ANY); + } + + public AnnotationTypeMemberWriter getAnnotationTypeOptionalMemberWriter( + ClassWriter classWriter) { + TypeElement te = classWriter.getTypeElement(); + return new AnnotationTypeMemberWriter(classWriter, te, AnnotationTypeMemberWriter.Kind.OPTIONAL); + } + + public AnnotationTypeMemberWriter getAnnotationTypeRequiredMemberWriter( + ClassWriter classWriter) { + TypeElement te = classWriter.getTypeElement(); + return new AnnotationTypeMemberWriter(classWriter, te, AnnotationTypeMemberWriter.Kind.REQUIRED); + } + + public EnumConstantWriter getEnumConstantWriter(ClassWriter classWriter) { + return new EnumConstantWriter(classWriter); + } + + public FieldWriter getFieldWriter(ClassWriter classWriter) { + return new FieldWriter(classWriter); + } + + public PropertyWriter getPropertyWriter(ClassWriter classWriter) { + return new PropertyWriter(classWriter); + } + + public MethodWriter getMethodWriter(ClassWriter classWriter) { + return new MethodWriter(classWriter); + } + + public ConstructorWriter getConstructorWriter(ClassWriter classWriter) { + return new ConstructorWriter(classWriter); + } + + public AbstractMemberWriter getMemberSummaryWriter(ClassWriter classWriter, + VisibleMemberTable.Kind memberType) { + switch (memberType) { + case CONSTRUCTORS: + return getConstructorWriter(classWriter); + case ENUM_CONSTANTS: + return getEnumConstantWriter(classWriter); + case ANNOTATION_TYPE_MEMBER_OPTIONAL: + return getAnnotationTypeOptionalMemberWriter(classWriter); + case ANNOTATION_TYPE_MEMBER_REQUIRED: + return getAnnotationTypeRequiredMemberWriter(classWriter); + case FIELDS: + return getFieldWriter(classWriter); + case PROPERTIES: + return getPropertyWriter(classWriter); + case NESTED_CLASSES: + return new NestedClassWriter(classWriter, classWriter.getTypeElement()); + case METHODS: + return getMethodWriter(classWriter); + default: + return null; + } + } + + public SerializedFormWriter getSerializedFormWriter() { + return new SerializedFormWriter(configuration); + } + + public DocFilesHandler getDocFilesHandler(Element element) { + return new DocFilesHandler(configuration, element); + } +} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java deleted file mode 100644 index b4830b474e6..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.formats.html; - - -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.ClassWriter; -import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; -import jdk.javadoc.internal.doclets.toolkit.WriterFactory; -import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; -import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; - -/** - * The factory that returns HTML writers. - */ -public class WriterFactoryImpl implements WriterFactory { - - private final HtmlConfiguration configuration; - public WriterFactoryImpl(HtmlConfiguration configuration) { - this.configuration = configuration; - } - - @Override - public ConstantsSummaryWriter getConstantsSummaryWriter() { - return new ConstantsSummaryWriterImpl(configuration); - } - - @Override - public PackageSummaryWriter getPackageSummaryWriter(PackageElement packageElement) { - return new PackageWriterImpl(configuration, packageElement); - } - - @Override - public ModuleSummaryWriter getModuleSummaryWriter(ModuleElement mdle) { - return new ModuleWriterImpl(configuration, mdle); - } - - @Override - public ClassWriter getClassWriter(TypeElement typeElement, ClassTree classTree) { - return new ClassWriterImpl(configuration, typeElement, classTree); - } - - @Override - public AnnotationTypeMemberWriterImpl getAnnotationTypeMemberWriter( - ClassWriter classWriter) { - TypeElement te = classWriter.getTypeElement(); - return new AnnotationTypeMemberWriterImpl( - (ClassWriterImpl) classWriter, te, AnnotationTypeMemberWriterImpl.Kind.ANY); - } - - @Override - public AnnotationTypeMemberWriterImpl getAnnotationTypeOptionalMemberWriter( - ClassWriter classWriter) { - TypeElement te = classWriter.getTypeElement(); - return new AnnotationTypeMemberWriterImpl( - (ClassWriterImpl) classWriter, te, AnnotationTypeMemberWriterImpl.Kind.OPTIONAL); - } - - @Override - public AnnotationTypeMemberWriterImpl getAnnotationTypeRequiredMemberWriter( - ClassWriter classWriter) { - TypeElement te = classWriter.getTypeElement(); - return new AnnotationTypeMemberWriterImpl( - (ClassWriterImpl) classWriter, te, AnnotationTypeMemberWriterImpl.Kind.REQUIRED); - } - - @Override - public EnumConstantWriterImpl getEnumConstantWriter(ClassWriter classWriter) { - return new EnumConstantWriterImpl((ClassWriterImpl) classWriter, - classWriter.getTypeElement()); - } - - @Override - public FieldWriterImpl getFieldWriter(ClassWriter classWriter) { - return new FieldWriterImpl((ClassWriterImpl) classWriter, classWriter.getTypeElement()); - } - - @Override - public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter) { - return new PropertyWriterImpl((ClassWriterImpl) classWriter, - classWriter.getTypeElement()); - } - - @Override - public MethodWriterImpl getMethodWriter(ClassWriter classWriter) { - return new MethodWriterImpl((ClassWriterImpl) classWriter, classWriter.getTypeElement()); - } - - @Override - public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter) { - return new ConstructorWriterImpl((ClassWriterImpl) classWriter, - classWriter.getTypeElement()); - } - - @Override - public MemberSummaryWriter getMemberSummaryWriter(ClassWriter classWriter, - VisibleMemberTable.Kind memberType) { - switch (memberType) { - case CONSTRUCTORS: - return getConstructorWriter(classWriter); - case ENUM_CONSTANTS: - return getEnumConstantWriter(classWriter); - case ANNOTATION_TYPE_MEMBER_OPTIONAL: - return getAnnotationTypeOptionalMemberWriter(classWriter); - case ANNOTATION_TYPE_MEMBER_REQUIRED: - return getAnnotationTypeRequiredMemberWriter(classWriter); - case FIELDS: - return getFieldWriter(classWriter); - case PROPERTIES: - return getPropertyWriter(classWriter); - case NESTED_CLASSES: - return new NestedClassWriterImpl((SubWriterHolderWriter) - classWriter, classWriter.getTypeElement()); - case METHODS: - return getMethodWriter(classWriter); - default: - return null; - } - } - - @Override - public SerializedFormWriter getSerializedFormWriter() { - return new SerializedFormWriterImpl(configuration); - } - - @Override - public DocFilesHandler getDocFilesHandler(Element element) { - return new DocFilesHandlerImpl(configuration, element); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/BodyContents.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/BodyContents.java index a6354a88aa0..9f4351d0ef2 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/BodyContents.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/BodyContents.java @@ -25,7 +25,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import java.io.IOException; import java.io.Writer; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Comment.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Comment.java index 78adad48bd7..aa563eeded7 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Comment.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Comment.java @@ -29,7 +29,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Objects; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * Class for generating a comment for HTML pages of javadoc output. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/ContentBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/ContentBuilder.java index 45888144deb..34573dd7794 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/ContentBuilder.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/ContentBuilder.java @@ -31,7 +31,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * A sequence of Content nodes. 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 c2d20432134..6ee4e157762 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 @@ -25,7 +25,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import java.io.IOException; import java.io.Writer; 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 9ba3f4ecdb8..60366487565 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 @@ -34,7 +34,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocument.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocument.java index 99e2ec1b642..dcfed8707dd 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocument.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlDocument.java @@ -29,7 +29,7 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java index fa77c37b853..d296aa4c83b 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java @@ -39,7 +39,7 @@ import java.util.Objects; import java.util.function.Function; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr.Role; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * A tree node representing an HTML element, containing the name of the element, diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Links.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Links.java index 732feca7a6f..cfdc3cda5c6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Links.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Links.java @@ -25,7 +25,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocLink; import jdk.javadoc.internal.doclets.toolkit.util.DocPath; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/RawHtml.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/RawHtml.java index 02e8aff13ba..5127be87ccd 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/RawHtml.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/RawHtml.java @@ -28,7 +28,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; import java.io.IOException; import java.io.Writer; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * Class for generating raw HTML content to be added to HTML pages of javadoc output. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Script.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Script.java index e76372897b3..f194aa5527a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Script.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Script.java @@ -28,8 +28,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; import java.io.IOException; import java.io.Writer; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * A builder for HTML script elements. @@ -165,7 +164,7 @@ public class Script { sb.append("\\\""); break; case '\'': - sb.append("\\\'"); + sb.append("\\'"); break; case '\\': sb.append("\\\\"); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Text.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Text.java index 389617a1d81..b96d86577a6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Text.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Text.java @@ -28,7 +28,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; import java.io.IOException; import java.io.Writer; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * Class for containing immutable string content for HTML tags of javadoc output. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/TextBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/TextBuilder.java index 0bdd81c73ed..5baa581450a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/TextBuilder.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/TextBuilder.java @@ -28,7 +28,7 @@ package jdk.javadoc.internal.doclets.formats.html.markup; import java.io.IOException; import java.io.Writer; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * Class for generating string content for HTML tags of javadoc output. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/BaseTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/BaseTaglet.java index 868e12f2700..bda31883f35 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/BaseTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/BaseTaglet.java @@ -33,7 +33,7 @@ import com.sun.source.doctree.DocTree; import jdk.javadoc.doclet.Taglet.Location; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.Messages; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.Utils; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DeprecatedTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DeprecatedTaglet.java index 457bc15a018..d586b697bd7 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DeprecatedTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DeprecatedTaglet.java @@ -38,7 +38,7 @@ import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; 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.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; /** diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DocRootTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DocRootTaglet.java index 520532e261d..94d701f7441 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DocRootTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/DocRootTaglet.java @@ -34,7 +34,7 @@ import com.sun.source.doctree.DocTree; import jdk.javadoc.doclet.Taglet; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * An inline taglet representing {@code {@docRoot}}. This taglet is diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/IndexTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/IndexTaglet.java index ae578f283c3..4361dd5c1ef 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/IndexTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/IndexTaglet.java @@ -35,7 +35,7 @@ import com.sun.source.doctree.TextTree; import jdk.javadoc.doclet.Taglet; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * An inline taglet used to index a word or a phrase. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java index 180078b9e86..b7b937a5fc6 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java @@ -39,7 +39,7 @@ import com.sun.source.util.DocTreePath; import jdk.javadoc.doclet.Taglet.Location; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Result; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LinkTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LinkTaglet.java index 459b0b9a407..06bfd1d59e8 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LinkTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LinkTaglet.java @@ -43,12 +43,12 @@ import com.sun.source.doctree.LinkTree; import com.sun.source.util.DocTreePath; import jdk.javadoc.doclet.Taglet; -import jdk.javadoc.internal.doclets.formats.html.ClassWriterImpl; +import jdk.javadoc.internal.doclets.formats.html.ClassWriter; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocLink; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; @@ -237,7 +237,7 @@ public class LinkTaglet extends BaseTaglet { // documented, this must be an inherited link. Redirect it. // The current class either overrides the referenced member or // inherits it automatically. - if (htmlWriter instanceof ClassWriterImpl cw) { + if (htmlWriter instanceof ClassWriter cw) { containing = cw.getTypeElement(); } else if (!utils.isPublic(containing)) { reportWarning.accept("doclet.link.see.reference_not_accessible", diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LiteralTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LiteralTaglet.java index 23e891a21f7..1d209427c21 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LiteralTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/LiteralTaglet.java @@ -36,7 +36,7 @@ import jdk.javadoc.doclet.Taglet; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * An inline taglet used to denote literal text, possibly in monospace font. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ParamTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ParamTaglet.java index 0ef1a41f777..9963547acf3 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ParamTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ParamTaglet.java @@ -46,7 +46,7 @@ import jdk.javadoc.internal.doclets.formats.html.HtmlIds; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.Utils; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ReturnTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ReturnTaglet.java index 290ad2dd15e..6ba5d897c46 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ReturnTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ReturnTaglet.java @@ -43,7 +43,7 @@ import jdk.javadoc.internal.doclets.formats.html.Contents; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.Utils; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SeeTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SeeTaglet.java index c3595bd12b8..2b6ad36896a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SeeTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SeeTaglet.java @@ -39,15 +39,15 @@ import com.sun.source.doctree.DocTree; import com.sun.source.doctree.SeeTree; import jdk.javadoc.doclet.Taglet; -import jdk.javadoc.internal.doclets.formats.html.ClassWriterImpl; +import jdk.javadoc.internal.doclets.formats.html.ClassWriter; import jdk.javadoc.internal.doclets.formats.html.Contents; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.HtmlDocletWriter; +import jdk.javadoc.internal.doclets.formats.html.SerializedFormWriter; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.builders.SerializedFormBuilder; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.DocLink; @@ -107,7 +107,7 @@ public class SeeTaglet extends BaseTaglet implements InheritableTaglet { links.add(seeTagOutput(holder, dt)); } if (utils.isVariableElement(holder) && ((VariableElement)holder).getConstantValue() != null && - htmlWriter instanceof ClassWriterImpl classWriter) { + htmlWriter instanceof ClassWriter classWriter) { //Automatically add link to constant values page for constant fields. DocPath constantsPath = htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES); @@ -120,8 +120,8 @@ public class SeeTaglet extends BaseTaglet implements InheritableTaglet { } if (utils.isClass(holder) && utils.isSerializable((TypeElement)holder)) { //Automatically add link to serialized form page for serializable classes. - if (SerializedFormBuilder.serialInclude(utils, holder) && - SerializedFormBuilder.serialInclude(utils, utils.containingPackage(holder))) { + if (SerializedFormWriter.serialInclude(utils, holder) && + SerializedFormWriter.serialInclude(utils, utils.containingPackage(holder))) { DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM); DocLink link = serialPath.fragment(utils.getFullyQualifiedName(holder)); links.add(htmlWriter.links.createLink(link, diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SimpleTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SimpleTaglet.java index bf9fd1d60f3..119da6a7610 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SimpleTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SimpleTaglet.java @@ -36,14 +36,13 @@ import javax.lang.model.element.ExecutableElement; import com.sun.source.doctree.BlockTagTree; import com.sun.source.doctree.DocTree; -import com.sun.source.doctree.UnknownBlockTagTree; import jdk.javadoc.doclet.Taglet; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; /** @@ -184,7 +183,7 @@ public class SimpleTaglet extends BaseTaglet implements InheritableTaglet { if (header == null || tags.isEmpty()) { return null; } - return simpleBlockTagOutput(holder, tags, header, tagletWriter); + return simpleBlockTagOutput(holder, tags, header); } /** @@ -198,8 +197,7 @@ public class SimpleTaglet extends BaseTaglet implements InheritableTaglet { */ private Content simpleBlockTagOutput(Element element, List<? extends DocTree> simpleTags, - String header, - TagletWriter writer) { + String header) { var ch = utils.getCommentHelper(element); var context = tagletWriter.context; var htmlWriter = tagletWriter.htmlWriter; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SnippetTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SnippetTaglet.java index ce8cdf06415..35e9e3c25be 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SnippetTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SnippetTaglet.java @@ -59,7 +59,7 @@ import jdk.javadoc.internal.doclets.formats.html.taglets.snippet.ParseException; import jdk.javadoc.internal.doclets.formats.html.taglets.snippet.Parser; import jdk.javadoc.internal.doclets.formats.html.taglets.snippet.Style; import jdk.javadoc.internal.doclets.formats.html.taglets.snippet.StyledText; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.DocletElement; import jdk.javadoc.internal.doclets.toolkit.Resources; import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SpecTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SpecTaglet.java index 1548ab3fcd2..e7a7620e5eb 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SpecTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SpecTaglet.java @@ -46,7 +46,7 @@ import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; import jdk.javadoc.internal.doclets.formats.html.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.Utils; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SummaryTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SummaryTaglet.java index c1df4588ec3..0961c7312d5 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SummaryTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SummaryTaglet.java @@ -34,7 +34,7 @@ import com.sun.source.doctree.SummaryTree; import jdk.javadoc.doclet.Taglet.Location; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * A taglet that represents the {@code {@summary}} tag. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SystemPropertyTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SystemPropertyTaglet.java index 0f7e8f9a620..3dc72e561a1 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SystemPropertyTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/SystemPropertyTaglet.java @@ -35,7 +35,7 @@ import com.sun.source.doctree.SystemPropertyTree; import jdk.javadoc.doclet.Taglet; import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * A taglet that represents the {@code @systemProperty} tag. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/Taglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/Taglet.java index cfaa63a8551..0236287468c 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/Taglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/Taglet.java @@ -31,7 +31,7 @@ import javax.lang.model.element.Element; import com.sun.source.doctree.DocTree; import jdk.javadoc.doclet.Taglet.Location; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * This is the taglet interface used internally within the doclet. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java index f6cef9af500..8d52217c801 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java @@ -54,7 +54,7 @@ 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.markup.Text; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.formats.html.taglets.Taglet.UnsupportedTagletOperationException; import jdk.javadoc.internal.doclets.toolkit.DocletElement; import jdk.javadoc.internal.doclets.toolkit.Resources; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ThrowsTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ThrowsTaglet.java index f7e1ce94d6f..131f0350e5e 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ThrowsTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ThrowsTaglet.java @@ -59,7 +59,7 @@ import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo; import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; import jdk.javadoc.internal.doclets.toolkit.util.Utils; import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/UserTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/UserTaglet.java index 149d06f90a8..bcfdd6682ed 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/UserTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/UserTaglet.java @@ -33,7 +33,7 @@ import javax.lang.model.element.Element; import com.sun.source.doctree.DocTree; import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; /** * A taglet wrapper, allows the public taglet {@link jdk.javadoc.doclet.Taglet} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ValueTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ValueTaglet.java index 166a1bcc7f0..006277eeeb0 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ValueTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/ValueTaglet.java @@ -41,7 +41,7 @@ import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; import jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo; import jdk.javadoc.internal.doclets.formats.html.markup.Text; import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; -import jdk.javadoc.internal.doclets.toolkit.Content; +import jdk.javadoc.internal.doclets.formats.html.Content; import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; /** diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java index b2da7d1fe7e..0153704175e 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java @@ -35,8 +35,6 @@ import javax.lang.model.element.TypeElement; import jdk.javadoc.doclet.Doclet; import jdk.javadoc.doclet.DocletEnvironment; -import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder; -import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory; import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; import jdk.javadoc.internal.doclets.toolkit.util.UncheckedDocletException; @@ -193,13 +191,7 @@ public abstract class AbstractDoclet implements Doclet { * @param classTree the data structure representing the class tree * @throws DocletException if there is a problem while generating the documentation */ - protected void generateOtherFiles(ClassTree classTree) throws DocletException { - BuilderFactory builderFactory = configuration.getBuilderFactory(); - AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuilder(); - constantsSummaryBuilder.build(); - AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder(); - serializedFormBuilder.build(); - } + protected void generateOtherFiles(ClassTree classTree) throws DocletException { } /** * Generate the module documentation. diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AnnotationTypeMemberWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AnnotationTypeMemberWriter.java deleted file mode 100644 index 685b6e9a1b5..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AnnotationTypeMemberWriter.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.Element; - -/** - * The interface for writing annotation type required member output. - */ -public interface AnnotationTypeMemberWriter extends MemberWriter { - - /** - * Adds the annotation type member header. - * - * @return the content for the member header - */ - Content getMemberHeader(); - - /** - * Adds the annotation type details marker. - * - * @param memberDetails the content representing details marker - */ - void addAnnotationDetailsMarker(Content memberDetails); - - /** - * Adds the annotation type details header. - * - * @return the content for the annotation details header - */ - Content getAnnotationDetailsHeader(); - - /** - * Gets the annotation type documentation header. - * - * @param member the annotation type being documented - * @return the content for the annotation type documentation header - */ - Content getAnnotationHeaderContent(Element member); - - /** - * Gets the annotation type details. - * - * @param annotationDetailsHeader the content representing annotation type details header - * @param annotationDetails the content representing annotation type details - * @return the annotation type details - */ - Content getAnnotationDetails(Content annotationDetailsHeader, Content annotationDetails); - - /** - * {@return the signature for the specified member} - * - * @param member the member being documented - */ - Content getSignature(Element member); - - /** - * Adds the deprecated output for the given member. - * - * @param member the member being documented - * @param target the content to which the deprecated information will be added - */ - void addDeprecated(Element member, Content target); - - /** - * Adds the preview output for the given member. - * - * @param member the member being documented - * @param content the content to which the preview information will be added - */ - void addPreview(Element member, Content content); - - /** - * Adds the comments for the given member. - * - * @param member the member being documented - * @param annotationContent the content to which the comments will be added - */ - void addComments(Element member, Content annotationContent); - - /** - * Adds the tags for the given member. - * - * @param member the member being documented - * @param annotationContent the content to which the tags will be added - */ - void addTags(Element member, Content annotationContent); - - /** - * Adds the default value documentation if the member has one. - * - * @param member the member being documented - * @param annotationContent the content to which the default value will be added - */ - void addDefaultValueInfo(Element member, Content annotationContent); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java index 01bab84819f..029e743a504 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java @@ -60,7 +60,6 @@ import jdk.javadoc.doclet.DocletEnvironment; import jdk.javadoc.doclet.Reporter; import jdk.javadoc.doclet.StandardDoclet; import jdk.javadoc.doclet.Taglet; -import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory; import jdk.javadoc.internal.doclets.toolkit.util.Comparators; import jdk.javadoc.internal.doclets.toolkit.util.DocFile; import jdk.javadoc.internal.doclets.toolkit.util.DocFileFactory; @@ -87,11 +86,6 @@ public abstract class BaseConfiguration { */ public final Doclet doclet; - /** - * The factory for builders. - */ - protected BuilderFactory builderFactory; - /** * The meta tag keywords instance. */ @@ -249,18 +243,6 @@ public abstract class BaseConfiguration { includedTypeElements = Collections.unmodifiableSet(includedSplitter.tset); } - /** - * Return the builder factory for this doclet. - * - * @return the builder factory for this doclet. - */ - public BuilderFactory getBuilderFactory() { - if (builderFactory == null) { - builderFactory = new BuilderFactory(this); - } - return builderFactory; - } - public Reporter getReporter() { return this.reporter; } @@ -482,13 +464,6 @@ public abstract class BaseConfiguration { return !(utils.isDeprecated(te) || utils.isDeprecated(utils.containingPackage(te))); } - /** - * Return the doclet specific instance of a writer factory. - * - * @return the {@link WriterFactory} for the doclet. - */ - public abstract WriterFactory getWriterFactory(); - /** * Return the Locale for this document. * diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ClassWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ClassWriter.java deleted file mode 100644 index dc8578847f2..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ClassWriter.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; - -/** - * The interface for writing class output. - */ -public interface ClassWriter { - /** - * Returns an instance of an output object. - * - * @return an instance of an output object - */ - Content getOutputInstance(); - - /** - * Get the header of the page. - * - * @param header the header string to write - * @return header content that needs to be added to the documentation - */ - Content getHeader(String header); - - /** - * Get the class content header. - * - * @return class content header that needs to be added to the documentation - */ - Content getClassContentHeader(); - - /** - * Add the class inheritance tree documentation. - * - * @param target the content to which the documentation will be added - */ - void addClassTree(Content target); - - /** - * Add the type parameter and state component information. - * - * @param target the content to which the documentation will be added - */ - void addParamInfo(Content target); - - /** - * Add all superinterfaces if this is an interface. - * - * @param target the content to which the documentation will be added - */ - void addSuperInterfacesInfo(Content target); - - /** - * Add all implemented interfaces if this is a class. - * - * @param target the content to which the documentation will be added - */ - void addImplementedInterfacesInfo(Content target); - - /** - * Add all the classes that extend this one. - * - * @param target the content to which the documentation will be added - */ - void addSubClassInfo(Content target); - - /** - * Add all the interfaces that extend this one. - * - * @param target the content to which the documentation will be added - */ - void addSubInterfacesInfo(Content target); - - /** - * If this is an interface, add all classes that implement this - * interface. - * - * @param target the content to which the documentation will be added - */ - void addInterfaceUsageInfo(Content target); - - /** - * If this is an functional interface, display appropriate message. - * - * @param target the content to which the documentation will be added - */ - void addFunctionalInterfaceInfo(Content target); - - /** - * If this is an inner class or interface, add the enclosing class or - * interface. - * - * @param target the content to which the documentation will be added - */ - void addNestedClassInfo(Content target); - - /** - * {@return the class information} - * - * @param classInfo the class information - */ - Content getClassInfo(Content classInfo); - - /** - * If this class is deprecated, add the appropriate information. - * - * @param classInfo the content to which the documentation will be added - */ - void addClassDeprecationInfo(Content classInfo); - - /** - * Add the signature of the current class content. - * - * @param classInfo the class content to which the signature will be added - */ - void addClassSignature(Content classInfo); - - /** - * Build the class description. - * - * @param classInfo the content to which the documentation will be added - */ - void addClassDescription(Content classInfo); - - /** - * Add the tag information for the current class. - * - * @param classInfo the content to which the tag information will be added - */ - void addClassTagInfo(Content classInfo); - - /** - * Returns a list to be used for the list of summaries for members of a given kind. - * - * @return a list to be used for the list of summaries for members of a given kind - */ - Content getSummariesList(); - - /** - * Returns an item for the list of summaries for members of a given kind. - * - * @param content content for the item - * @return an item for the list of summaries for members of a given kind - */ - Content getSummariesListItem(Content content); - - /** - * Returns a list to be used for the list of details for members of a given kind. - * - * @return a list to be used for the list of details for members of a given kind - */ - Content getDetailsList(); - - /** - * Returns an item for the list of details for members of a given kind. - * - * @param content content for the item - * @return an item for the list of details for members of a given kind - */ - Content getDetailsListItem(Content content); - - /** - * Add the class content. - * - * @param classContent the class content which will be added to the content - */ - void addClassContent(Content classContent); - - /** - * Add the footer of the page. - */ - void addFooter(); - - /** - * Print the document. - * - * @param content the content that will be printed as a document - * @throws DocFileIOException if there is a problem while writing the document - */ - void printDocument(Content content) throws DocFileIOException; - - /** - * Return the TypeElement being documented. - * - * @return the TypeElement being documented. - */ - TypeElement getTypeElement(); - - /** - * {@return the member summary} - * - * @param memberContent the content used to build the summary - */ - Content getMemberSummary(Content memberContent); - - /** - * {@return the member details} - * - * @param memberContent the content used to generate the member details - */ - Content getMemberDetails(Content memberContent); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstantsSummaryWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstantsSummaryWriter.java deleted file mode 100644 index dbc04dbef55..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstantsSummaryWriter.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import java.util.*; - -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; - -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; - -/** - * The interface for writing constants summary output. - */ -public interface ConstantsSummaryWriter { - - /** - * Get the header for the constant summary documentation. - * - * @return header that needs to be added to the documentation - */ - Content getHeader(); - - /** - * Get the header for the constant content list. - * - * @return content header that needs to be added to the documentation - */ - Content getContentsHeader(); - - /** - * Adds the given package name link to the constant content list. - * - * @param abbrevPackageName the abbreviated package name - * @param content the content to which the link will be added - */ - void addLinkToPackageContent(String abbrevPackageName, Content content); - - /** - * Add the content list to the documentation. - * - * @param content the content that will be added to the list - */ - void addContentsList(Content content); - - /** - * Get the constant summaries for the document. - * - * @return constant summaries header to be added to the documentation - */ - Content getConstantSummaries(); - - /** - * Adds a header for the given abbreviated package name. - * - * @param abbrevPackageName the abbreviated package name - * @param toContent the summaries documentation - */ - void addPackageGroup(String abbrevPackageName, Content toContent); - - /** - * Get the class summary header for the constants summary. - * - * @return the header content for the class constants summary - */ - Content getClassConstantHeader(); - - /** - * Add the content list to the documentation summaries. - * - * @param fromClassConstant the class constant content that will be added to the list - */ - void addClassConstant(Content fromClassConstant); - - /** - * Adds the constant member table to the documentation. - * - * @param typeElement the class whose constants are being documented. - * @param fields the constants being documented. - * @param target the content to which the constant member - * table content will be added - */ - void addConstantMembers(TypeElement typeElement, Collection<VariableElement> fields, - Content target); - - /** - * Add the summaries list to the content. - * - * @param content the summaries content that will be added to the list - */ - void addConstantSummaries(Content content); - - /** - * Adds the footer for the summary documentation. - */ - void addFooter(); - - /** - * Print the constants summary document. - * - * @param content the content which should be printed - * @throws DocFileIOException if there is a problem while writing the document - */ - void printDocument(Content content) throws DocFileIOException; -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstructorWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstructorWriter.java deleted file mode 100644 index 9086d7f371a..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ConstructorWriter.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.ExecutableElement; - -/** - * The interface for writing constructor output. - */ -public interface ConstructorWriter extends MemberWriter { - - /** - * {@return the constructor details header} - * - * @param content the content representing member details - */ - Content getConstructorDetailsHeader(Content content); - - /** - * {@return the constructor documentation header} - * - * @param constructor the constructor being documented - */ - Content getConstructorHeaderContent(ExecutableElement constructor); - - /** - * {@return the signature for the given constructor} - * - * @param constructor the constructor being documented - */ - Content getSignature(ExecutableElement constructor); - - /** - * Add the deprecated output for the given constructor. - * - * @param constructor the constructor being documented - * @param constructorContent the content to which the deprecated information will be added - */ - void addDeprecated(ExecutableElement constructor, Content constructorContent); - - /** - * Add the preview output for the given member. - * - * @param member the member being documented - * @param content the content to which the preview information will be added - */ - void addPreview(ExecutableElement member, Content content); - - /** - * Add the comments for the given constructor. - * - * @param constructor the constructor being documented - * @param constructorContent the content to which the comments will be added - */ - void addComments(ExecutableElement constructor, Content constructorContent); - - /** - * Add the tags for the given constructor. - * - * @param constructor the constructor being documented - * @param constructorContent the content to which the tags will be added - */ - void addTags(ExecutableElement constructor, Content constructorContent); - - /** - * {@return the constructor details} - * - * @param memberDetailsHeader the content representing member details header - * @param memberDetails the content representing member details - */ - Content getConstructorDetails(Content memberDetailsHeader, Content memberDetails); - - /** - * Let the writer know whether a non public constructor was found. - * - * @param foundNonPubConstructor true if we found a non public constructor. - */ - void setFoundNonPubConstructor(boolean foundNonPubConstructor); - - /** - * @return the member header} - */ - Content getMemberHeader(); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFilesHandler.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFilesHandler.java deleted file mode 100644 index dbd830a82c6..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFilesHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -package jdk.javadoc.internal.doclets.toolkit; - -import java.util.List; - -import jdk.javadoc.internal.doclets.toolkit.util.DocPath; - -/** - * The interface for copying doc-files to the output. - */ -public interface DocFilesHandler { - void copyDocFiles() throws DocletException; - List<DocPath> getStylesheets() throws DocletException; -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/EnumConstantWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/EnumConstantWriter.java deleted file mode 100644 index 83824ad4935..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/EnumConstantWriter.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; - -/** - * The interface for writing enum constant output. - */ -public interface EnumConstantWriter extends MemberWriter { - - /** - * Get the enum constants details header. - * - * @param typeElement the class being documented - * @param memberDetails the content representing member details - * @return a content for the enum constants details header - */ - Content getEnumConstantsDetailsHeader(TypeElement typeElement, - Content memberDetails); - - /** - * Get the enum constants documentation header. - * - * @param enumConstant the enum constant being documented - * @param enumConstantsDetails the content representing enum constant details - * @return the enum constant documentation header - */ - Content getEnumConstantsHeader(VariableElement enumConstant, - Content enumConstantsDetails); - - /** - * Get the signature for the given enum constant. - * - * @param enumConstant the enum constant being documented - * @return the enum constant signature - */ - Content getSignature(VariableElement enumConstant); - - /** - * Add the deprecated output for the given enum constant. - * - * @param enumConstant the enum constant being documented - * @param content the content to which the deprecated information will be added - */ - void addDeprecated(VariableElement enumConstant, Content content); - - /** - * Add the preview output for the given member. - * - * @param member the member being documented - * @param content the content to which the preview information will be added - */ - void addPreview(VariableElement member, Content content); - - /** - * Add the comments for the given enum constant. - * - * @param enumConstant the enum constant being documented - * @param enumConstants the content to which the comments will be added - */ - void addComments(VariableElement enumConstant, Content enumConstants); - - /** - * Add the tags for the given enum constant. - * - * @param enumConstant the enum constant being documented - * @param content the content to which the tags will be added - */ - void addTags(VariableElement enumConstant, Content content); - - /** - * Get the enum constants details. - * - * @param memberDetailsHeader member details header - * @param content the content representing member details - * @return the enum constant details - */ - Content getEnumConstantsDetails(Content memberDetailsHeader, Content content); - - /** - * Gets the member header. - * - * @return the member header - */ - Content getMemberHeader(); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/FieldWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/FieldWriter.java deleted file mode 100644 index 85db6e674fc..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/FieldWriter.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.VariableElement; - -/** - * The interface for writing field output. - */ -public interface FieldWriter extends MemberWriter { - - /** - * Get the field details header. - * - * @param content the content representing member details - * @return the field details header - */ - Content getFieldDetailsHeader(Content content); - - /** - * Get the field documentation header. - * - * @param field the constructor being documented - * @return the field documentation header - */ - Content getFieldHeaderContent(VariableElement field); - - /** - * Get the signature for the given field. - * - * @param field the field being documented - * @return the field signature - */ - Content getSignature(VariableElement field); - - /** - * Add the deprecated output for the given field. - * - * @param field the field being documented - * @param fieldContent the content to which the deprecated information will be added - */ - void addDeprecated(VariableElement field, Content fieldContent); - - /** - * Adds the preview output for the given member. - * - * @param member the member being documented - * @param content the content to which the preview information will be added - */ - void addPreview(VariableElement member, Content content); - - /** - * Add the comments for the given field. - * - * @param field the field being documented - * @param fieldContent the content to which the comments will be added - */ - void addComments(VariableElement field, Content fieldContent); - - /** - * Add the tags for the given field. - * - * @param field the field being documented - * @param fieldContent the content to which the tags will be added - */ - void addTags(VariableElement field, Content fieldContent); - - /** - * Get the field details. - * - * @param memberDetailsHeaderContent the content representing member details header - * @param memberContent the content representing member details - * @return the field details - */ - Content getFieldDetails(Content memberDetailsHeaderContent, Content memberContent); - - /** - * Gets the member header. - * - * @return the member header - */ - Content getMemberHeader(); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberSummaryWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberSummaryWriter.java deleted file mode 100644 index 34c2f9810db..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberSummaryWriter.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; - -import com.sun.source.doctree.DocTree; - -/** - * The interface for writing member summary output. - */ -public interface MemberSummaryWriter { - - /** - * 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 - */ - Content getMemberSummaryHeader(TypeElement typeElement, Content content); - - /** - * Returns the summary table for the given class. - * - * @param typeElement the class the summary table belongs to - * - * @return the summary table - */ - Content getSummaryTable(TypeElement typeElement); - - /** - * Adds the member summary for the given class and member. - * - * @param typeElement the class the summary belongs to - * @param member the member that is documented - * @param firstSentenceTrees the tags for the sentence being documented - */ - void addMemberSummary(TypeElement typeElement, Element member, - List<? extends DocTree> firstSentenceTrees); - - /** - * Returns the inherited member summary header for the given class. - * - * @param typeElement the class the summary belongs to - * - * @return the inherited member summary header - */ - Content getInheritedSummaryHeader(TypeElement typeElement); - - /** - * Adds the inherited member summary for the given class and member. - * - * @param typeElement the class the inherited member belongs to - * @param member the inherited member that is being documented - * @param isFirst true if this is the first member in the list - * @param isLast true if this is the last member in the list - * @param content the content to which the links will be added - */ - void addInheritedMemberSummary(TypeElement typeElement, - Element member, boolean isFirst, boolean isLast, - Content content); - - /** - * Returns the inherited summary links. - * - * @return the inherited summary links - */ - Content getInheritedSummaryLinks(); - - /** - * Adds the given summary to the list of summaries. - * - * @param summariesList the list of summaries - * @param content the summary - */ - void addSummary(Content summariesList, Content content); - - /** - * Returns the member content. - * - * @param memberContent the content representing the member - * - * @return the member content - */ - Content getMember(Content memberContent); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberWriter.java deleted file mode 100644 index ea65c51eed5..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MemberWriter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -/** - * Common behavior for writing members of a type. - */ -public interface MemberWriter { - - /** - * {@return a list to add member items to} - * - * @see #getMemberListItem(Content) - */ - Content getMemberList(); - - /** - * {@return a member item} - * - * @param member the member to represent as an item - * @see #getMemberList() - */ - Content getMemberListItem(Content member); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MethodWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MethodWriter.java deleted file mode 100644 index 3483849195a..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/MethodWriter.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.TypeMirror; - -/** - * The interface for writing method output. - */ -public interface MethodWriter extends MemberWriter { - - /** - * Get the method details header. - * - * @param content the content representing member details - * @return the method details header - */ - Content getMethodDetailsHeader(Content content); - - /** - * Get the method documentation header. - * - * @param method the method being documented - * @return the method documentation header - */ - Content getMethodHeader(ExecutableElement method); - - /** - * Get the signature for the given method. - * - * @param method the method being documented - * @return the method signature - */ - Content getSignature(ExecutableElement method); - - /** - * Add the deprecated output for the given method. - * - * @param method the method being documented - * @param methodContent the content to which the deprecated information will be added - */ - void addDeprecated(ExecutableElement method, Content methodContent); - - /** - * Adds the preview output for the given member. - * - * @param member the member being documented - * @param content the content to which the preview information will be added - */ - void addPreview(ExecutableElement member, Content content); - - /** - * Add the comments for the given method. - * - * @param holder the holder type (not erasure) of the method - * @param method the method being documented - * @param methodContent the content to which the comments will be added - */ - void addComments(TypeMirror holder, ExecutableElement method, Content methodContent); - - /** - * Add the tags for the given method. - * - * @param method the method being documented - * @param methodContent the content to which the tags will be added - */ - void addTags(ExecutableElement method, Content methodContent); - - /** - * Get the method details. - * - * @param methodDetailsHeader the content representing method details header - * @param methodDetails the content representing method details - * @return the method details - */ - Content getMethodDetails(Content methodDetailsHeader, Content methodDetails); - - /** - * Gets the member header. - * - * @return the member header - */ - Content getMemberHeader(); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ModuleSummaryWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ModuleSummaryWriter.java deleted file mode 100644 index b987b457aa1..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/ModuleSummaryWriter.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; - -/** - * The interface for writing module summary output. - */ -public interface ModuleSummaryWriter { - - /** - * Get the header for the summary. - * - * @param heading module name. - * @return the header to be added to the content - */ - Content getModuleHeader(String heading); - - /** - * Get the header for the module content. - * - * @return the module content header - */ - Content getContentHeader(); - - /** - * Get the header for the summary header. - * - * @return the summary header - */ - Content getSummariesList(); - - /** - * Wrap the content into summary section. - * - * @param source the content to wrap into the summary section - * @return the summary - */ - Content getSummary(Content source); - - /** - * Adds the module description. - * - * @param moduleContent the content to which the module description - * will be added - */ - void addModuleDescription(Content moduleContent); - - /** - * Adds the module signature. - * - * @param moduleContent the content to which the module signature - * will be added - */ - void addModuleSignature(Content moduleContent); - - /** - * Adds the summary of modules to the list of summaries. - * - * @param summariesList the list of summaries - */ - void addModulesSummary(Content summariesList); - - /** - * Adds the summary of packages to the list of summaries. - * - * @param summariesList the list of summaries - */ - void addPackagesSummary(Content summariesList); - - /** - * Adds the summary of services to the list of summaries. - * - * @param summariesList the list of summaries - */ - void addServicesSummary(Content summariesList); - - /** - * Adds the module content to the documentation. - * - * @param source the content that will be added - */ - void addModuleContent(Content source); - - /** - * Adds the footer to the documentation. - */ - void addModuleFooter(); - - /** - * Print the module summary document. - * - * @param content the content that will be printed - * @throws DocFileIOException if there is a problem while writing the document - */ - void printDocument(Content content) throws DocFileIOException; -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/NestedClassWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/NestedClassWriter.java deleted file mode 100644 index 5590112dde4..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/NestedClassWriter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -/** - * The interface for writing class output. - */ -public interface NestedClassWriter { -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PackageSummaryWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PackageSummaryWriter.java deleted file mode 100644 index 9716178b21b..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PackageSummaryWriter.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import java.util.List; -import java.util.SortedSet; - -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; - -/** - * The interface for writing package summary output. - */ -public interface PackageSummaryWriter { - - /** - * Get the header for the summary. - * - * @return the header to be added to the content - */ - Content getPackageHeader(); - - /** - * Get the header for the package content. - * - * @return the package content header - */ - Content getContentHeader(); - - /** - * Get the header for the package summary. - * - * @return the package summary header - */ - Content getSummariesList(); - - /** - * Adds the table of related packages to the documentation. - * - * @param summaryContent the content to which the summaries will be added - */ - void addRelatedPackagesSummary(Content summaryContent); - - /** - * Adds the table of all classes and interfaces to the documentation. - * - * @param summaryContent the content to which the summaries will be added - */ - void addAllClassesAndInterfacesSummary(Content summaryContent); - - /** - * Adds the package description from the "packages.html" file to the documentation. - * - * @param packageContent the content to which the package description - * will be added - */ - void addPackageDescription(Content packageContent); - - /** - * Adds the tag information from the "packages.html" file to the documentation. - * - * @param packageContent the content to which the package tags will - * be added - */ - void addPackageTags(Content packageContent); - - /** - * Adds the package signature. - * - * @param packageContent the content to which the package signature - * will be added - */ - void addPackageSignature(Content packageContent); - - /** - * Adds the tag information from the "packages.html" or "package-info.java" file to the - * documentation. - * - * @param packageContent the package content to be added - */ - void addPackageContent(Content packageContent); - - /** - * Adds the footer to the documentation. - */ - void addPackageFooter(); - - /** - * Print the package summary document. - * - * @param content the content that will be printed - * @throws DocFileIOException if there is a problem while writing the document - */ - void printDocument(Content content) throws DocFileIOException; - - /** - * Gets the package summary. - * @param summaryContent the content representing the package summary - * @return the package summary - */ - Content getPackageSummary(Content summaryContent); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyUtils.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyUtils.java index aeaaab975ce..823f172b360 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyUtils.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyUtils.java @@ -25,11 +25,28 @@ package jdk.javadoc.internal.doclets.toolkit; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; + +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Types; +import javax.tools.Diagnostic; + +import com.sun.source.doctree.DocCommentTree; + +import jdk.javadoc.internal.doclets.toolkit.util.Utils; +import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; + +import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.PROPERTIES; /** * This class provides basic JavaFX property related utility methods. @@ -169,4 +186,92 @@ public class PropertyUtils { return typeUtils.isAssignable(returnType, jbObservableType); } } + + + /** + * A utility class to manage the property-related methods that should be + * synthesized or updated. + * + * A property may comprise a field (that is typically private, if present), + * a {@code fooProperty()} method (which is the defining characteristic for + * a property), a {@code getFoo()} method and/or a {@code setFoo(Foo foo)} method. + * + * Either the field (if present) or the {@code fooProperty()} method should have a + * comment. If there is no field, or no comment on the field, the description for + * the property will be derived from the description of the {@code fooProperty()} + * method. If any method does not have a comment, one will be provided. + */ + public static class PropertyHelper { + private final BaseConfiguration configuration; + private final Utils utils; + private final TypeElement typeElement; + + private final Map<Element, Element> classPropertiesMap = new HashMap<>(); + + public PropertyHelper(BaseConfiguration configuration, TypeElement typeElement) { + this.configuration = configuration; + this.utils = configuration.utils; + this.typeElement = typeElement; + computeProperties(); + } + + private void computeProperties() { + VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); + List<ExecutableElement> props = ElementFilter.methodsIn(vmt.getVisibleMembers(PROPERTIES)); + for (ExecutableElement propertyMethod : props) { + ExecutableElement getter = vmt.getPropertyGetter(propertyMethod); + ExecutableElement setter = vmt.getPropertySetter(propertyMethod); + VariableElement field = vmt.getPropertyField(propertyMethod); + + addToPropertiesMap(propertyMethod, field, getter, setter); + } + } + + private void addToPropertiesMap(ExecutableElement propertyMethod, + VariableElement field, + ExecutableElement getter, + ExecutableElement setter) { + // determine the preferred element from which to derive the property description + Element e = field == null || !utils.hasDocCommentTree(field) + ? propertyMethod : field; + + if (e == field && utils.hasDocCommentTree(propertyMethod)) { + configuration.getReporter().print(Diagnostic.Kind.WARNING, + propertyMethod, configuration.getDocResources().getText("doclet.duplicate.comment.for.property")); + } + + addToPropertiesMap(propertyMethod, e); + addToPropertiesMap(getter, e); + addToPropertiesMap(setter, e); + } + + private void addToPropertiesMap(Element propertyMethod, + Element commentSource) { + Objects.requireNonNull(commentSource); + if (propertyMethod == null) { + return; + } + + DocCommentTree docTree = utils.hasDocCommentTree(propertyMethod) + ? utils.getDocCommentTree(propertyMethod) + : null; + + /* The second condition is required for the property buckets. In + * this case the comment is at the property method (not at the field) + * and it needs to be listed in the map. + */ + if ((docTree == null) || propertyMethod.equals(commentSource)) { + classPropertiesMap.put(propertyMethod, commentSource); + } + } + + /** + * Returns the element for the property documentation belonging to the given member. + * @param element the member for which the property documentation is needed. + * @return the element for the property documentation, null if there is none. + */ + public Element getPropertyElement(Element element) { + return classPropertiesMap.get(element); + } + } } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyWriter.java deleted file mode 100644 index 24bb3052cae..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/PropertyWriter.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.ExecutableElement; - -/** - * The interface for writing property output. - */ -public interface PropertyWriter extends MemberWriter { - - /** - * Get the property details header. - * - * @param memberDetails the content representing member details - * @return the property details header - */ - Content getPropertyDetailsHeader(Content memberDetails); - - /** - * Get the property documentation header. - * - * @param property the property being documented - * @return the property documentation header - */ - Content getPropertyHeaderContent(ExecutableElement property); - - /** - * Get the signature for the given property. - * - * @param property the property being documented - * @return the property signature - */ - Content getSignature(ExecutableElement property); - - /** - * Add the deprecated output for the given property. - * - * @param property the property being documented - * @param propertyContent content to which the deprecated information will be added - */ - void addDeprecated(ExecutableElement property, Content propertyContent); - - /** - * Add the preview output for the given member. - * - * @param member the member being documented - * @param content the content to which the preview information will be added - */ - void addPreview(ExecutableElement member, Content content); - - /** - * Add the comments for the given property. - * - * @param property the property being documented - * @param propertyContent the content to which the comments will be added - */ - void addComments(ExecutableElement property, Content propertyContent); - - /** - * Add the tags for the given property. - * - * @param property the property being documented - * @param propertyContent the content to which the tags will be added - */ - void addTags(ExecutableElement property, Content propertyContent); - - /** - * Get the property details. - * - * @param memberDetailsHeader the content representing member details header - * @param memberDetails the content representing member details - * @return the property details - */ - Content getPropertyDetails(Content memberDetailsHeader, Content memberDetails); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java deleted file mode 100644 index ed469dd65dc..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/SerializedFormWriter.java +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.TypeMirror; - -import com.sun.source.doctree.SerialFieldTree; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; - -/** - * The interface for writing serialized form output. - */ -public interface SerializedFormWriter { - - /** - * Get the header. - * - * @param header the header to write. - * @return the header content - */ - Content getHeader(String header); - - /** - * Get the serialized form summaries header. - * - * @return the serialized form summary header - */ - Content getSerializedSummariesHeader(); - - /** - * Get the package serialized form header. - * - * @return the package serialized form header - */ - Content getPackageSerializedHeader(); - - /** - * Add the serialized package to the serialized summaries. - * - * @param serializedSummaries the serialized content to which the package serialized content will be added - * @param packageSerialized the serialized content per package that needs to be added - */ - void addPackageSerialized(Content serializedSummaries, Content packageSerialized); - - /** - * {@return a header for the given package} - * - * @param packageElement the package element to write - */ - Content getPackageHeader(PackageElement packageElement); - - /** - * {@return the serialized class header} - */ - Content getClassSerializedHeader(); - - /** - * {@return the heading for the serializable class} - * - * @param typeElement the class being processed - */ - Content getClassHeader(TypeElement typeElement); - - /** - * {@return the serial UID info header} - */ - Content getSerialUIDInfoHeader(); - - /** - * Adds the serial UID info. - * - * @param header the header that will show up before the UID. - * @param serialUID the serial UID to print. - * @param target the serial UID to which the content will be added. - */ - void addSerialUIDInfo(String header, String serialUID, Content target); - - /** - * {@return the serialized class header} - */ - Content getClassContentHeader(); - - /** - * Return an instance of a SerialFieldWriter for a class. - * - * @param typeElement the class - * @return an instance of a SerialFieldWriter. - */ - SerialFieldWriter getSerialFieldWriter(TypeElement typeElement); - - /** - * Return an instance of a SerialMethodWriter for a class. - * - * @param typeElement the class - * @return an instance of a SerialMethodWriter. - */ - SerialMethodWriter getSerialMethodWriter(TypeElement typeElement); - - /** - * Add the serialized content to the body content. - * - * @param source content for serialized data - */ - void addSerializedContent(Content source); - - /** - * Add the footer. - */ - void addFooter(); - - /** - * Print the serialized form document. - * - * @param source the content that will be printed - * @throws DocFileIOException if there is a problem while writing the document - */ - void printDocument(Content source) throws DocFileIOException; - - /** - * Gets the member. - * - * @param content the content used to generate the complete member - * @return the member - */ - Content getMember(Content content); - - /** - * A writer for the serialized form for a given field. - */ - interface SerialFieldWriter { - - /** - * {@return the serializable field header} - */ - Content getSerializableFieldsHeader(); - - /** - * {@return the field content header} - * - * @param isLastContent true if this is the last content to be documented - */ - Content getFieldsContentHeader(boolean isLastContent); - - /** - * {@return the fields} - * - * @param heading the heading to write. - * @param content the content to be added - * @return serializable fields content - */ - Content getSerializableFields(String heading, Content content); - - /** - * Adds the deprecated information for this member. - * - * @param field the field to document. - * @param content the content to which the deprecated information will be added - */ - void addMemberDeprecatedInfo(VariableElement field, Content content); - - /** - * Adds the description text for this member. - * - * @param field the field to document - * @param content the content to which the member description will be added - */ - void addMemberDescription(VariableElement field, Content content); - - /** - * Adds the description text for this member represented by the tag. - * - * @param field the field to document - * @param serialFieldTag the field to document (represented by tag) - * @param content the content to which the member description will be added - */ - void addMemberDescription(VariableElement field, SerialFieldTree serialFieldTag, Content content); - - /** - * Adds the tag information for this member. - * - * @param field the field to document - * @param content the content to which the member tags will be added - */ - void addMemberTags(VariableElement field, Content content); - - /** - * Adds the member header. - * - * @param fieldType the type of the field - * @param fieldName the name of the field - * @param content the content to which the member header will be added - */ - void addMemberHeader(TypeMirror fieldType, String fieldName, Content content); - - /** - * Check to see if overview details should be printed. If - * nocomment option set or if there is no text to be printed - * for deprecation info, inline comment or tags, - * do not print overview details. - * - * @param field the field to check overview details for - * @return true if overview details need to be printed - */ - boolean shouldPrintOverview(VariableElement field); - } - - /** - * Write the serialized form for a given field. - */ - interface SerialMethodWriter { - - /** - * {@return the header for serializable methods section} - */ - Content getSerializableMethodsHeader(); - - /** - * {@return the header for serializable methods content section} - * - * @param isLastContent true if the content being documented is the last content - */ - Content getMethodsContentHeader(boolean isLastContent); - - /** - * Gets the given heading. - * - * @param heading the heading to write - * @param source the content which will be added - * @return a serializable methods content - */ - Content getSerializableMethods(String heading, Content source); - - /** - * Gets a warning that no serializable methods exist. - * - * @param msg the warning to print - * @return a no customization message - */ - Content getNoCustomizationMsg(String msg); - - /** - * Adds the header. - * - * @param member the member to write the header for - * @param methodsContent the content to which the header will be added - */ - void addMemberHeader(ExecutableElement member, Content methodsContent); - - /** - * Adds the deprecated information for this member. - * - * @param member the member to write the deprecated information for - * @param methodsContent the content to which the deprecated - * information will be added - */ - void addDeprecatedMemberInfo(ExecutableElement member, Content methodsContent); - - /** - * Adds the description for this member. - * - * @param member the member to write the information for - * @param methodsContent the content to which the member - * information will be added - */ - void addMemberDescription(ExecutableElement member, Content methodsContent); - - /** - * Adds the tag information for this member. - * - * @param member the member to write the tags information for - * @param methodsContent the content to which the tags - * information will be added - */ - void addMemberTags(ExecutableElement member, Content methodsContent); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java deleted file mode 100644 index 0b007db7f7e..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WriterFactory.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit; - -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.util.ClassTree; -import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; - -/** - * The interface for a factory creates writers. - */ -public interface WriterFactory { - - /** - * Return the writer for the constant summary. - * - * @return the writer for the constant summary. Return null if this - * writer is not supported by the doclet. - */ - ConstantsSummaryWriter getConstantsSummaryWriter(); - - /** - * Return the writer for the package summary. - * - * @param packageElement the package being documented - * @return the writer for the package summary. Return null if this - * writer is not supported by the doclet. - */ - PackageSummaryWriter getPackageSummaryWriter(PackageElement packageElement); - - /** - * Return the writer for the module summary. - * - * @param mdle the module being documented - * @return the writer for the module summary. Return null if this - * writer is not supported by the doclet. - */ - ModuleSummaryWriter getModuleSummaryWriter(ModuleElement mdle); - - /** - * Returns the writer for a given type element, - * or null if this writer is not supported by the doclet. - * - * @param typeElement the class being documented - * @param classTree the class tree - * @return the writer - */ - ClassWriter getClassWriter(TypeElement typeElement, ClassTree classTree); - - /** - * Return the method writer for a given type element, - * or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the class being documented - * @return the method writer - */ - MethodWriter getMethodWriter(ClassWriter classWriter); - - /** - * Return the annotation type member writer for a given annotation - * type, or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the annotation type being documented - * @return the member writer - */ - AnnotationTypeMemberWriter getAnnotationTypeMemberWriter( - ClassWriter classWriter); - - /** - * Return the annotation type optional member writer for a given annotation - * type, or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the annotation type being documented - * @return the member writer - */ - AnnotationTypeMemberWriter getAnnotationTypeOptionalMemberWriter( - ClassWriter classWriter); - - /** - * Return the annotation type required member writer for a given annotation - * type, or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the annotation type being documented - * @return the member writer - */ - AnnotationTypeMemberWriter getAnnotationTypeRequiredMemberWriter( - ClassWriter classWriter); - - /** - * Return the enum constant writer for a given type element, - * or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the type element being documented - * @return the enum constant writer - */ - EnumConstantWriter getEnumConstantWriter(ClassWriter classWriter); - - /** - * Return the field writer for a given type element, - * or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the class being documented - * @return the field writer for the given class. Return null if this - * writer is not supported by the doclet. - */ - FieldWriter getFieldWriter(ClassWriter classWriter); - - /** - * Return the property writer for a given class, - * or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the type element being documented - * @return the property writer - */ - PropertyWriter getPropertyWriter(ClassWriter classWriter); - - /** - * Return the constructor writer for a given type element, - * or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the type element being documented - * @return the constructor writer - */ - ConstructorWriter getConstructorWriter(ClassWriter classWriter); - - /** - * Return the specified member summary writer for a given type element, - * or null if this writer is not supported by the doclet. - * - * @param classWriter the writer for the class being documented - * @param memberType the {@link VisibleMemberTable} member type indicating - * the type of member summary that should be returned - * @return the summary writer - * - * @see VisibleMemberTable - */ - MemberSummaryWriter getMemberSummaryWriter(ClassWriter classWriter, - VisibleMemberTable.Kind memberType); - - /** - * Return the writer for the serialized form. - * - * @return the writer for the serialized form - */ - SerializedFormWriter getSerializedFormWriter(); - - /** - * Return the handler for doc files. - * - * @return the handler for the doc files - */ - DocFilesHandler getDocFilesHandler(Element pkg); -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractBuilder.java deleted file mode 100644 index d6c87a63e09..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractBuilder.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.PackageElement; - -import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -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.Utils; - - -/** - * The superclass for all builders. A builder is a class that provides - * the structure and content of API documentation. A builder is completely - * doclet independent which means that any doclet can use builders to - * construct documentation, as long as it implements the appropriate - * writer interfaces. For example, if a doclet wanted to use - * {@link ConstantsSummaryBuilder} to build a constant summary, all it has to - * do is implement the ConstantsSummaryWriter interface and pass it to the - * builder using a WriterFactory. - */ -public abstract class AbstractBuilder { - public static class Context { - /** - * The configuration used in this run of the doclet. - */ - final BaseConfiguration configuration; - - /** - * Keep track of which packages we have seen for - * efficiency purposes. We don't want to copy the - * doc files multiple times for a single package. - */ - final Set<PackageElement> containingPackagesSeen; - - Context(BaseConfiguration configuration, Set<PackageElement> containingPackagesSeen) { - this.configuration = configuration; - this.containingPackagesSeen = containingPackagesSeen; - } - } - - /** - * The configuration used in this run of the doclet. - */ - protected final BaseConfiguration configuration; - protected final BaseOptions options; - - protected final BuilderFactory builderFactory; - protected final Messages messages; - protected final Resources resources; - protected final Utils utils; - - /** - * Keep track of which packages we have seen for - * efficiency purposes. We don't want to copy the - * doc files multiple times for a single package. - */ - protected final Set<PackageElement> containingPackagesSeen; - - /** - * Construct a Builder. - * @param c a context providing information used in this run of the doclet - */ - public AbstractBuilder(Context c) { - this.configuration = c.configuration; - this.options = configuration.getOptions(); - this.builderFactory = configuration.getBuilderFactory(); - this.messages = configuration.getMessages(); - this.resources = configuration.getDocResources(); - this.utils = configuration.utils; - this.containingPackagesSeen = c.containingPackagesSeen; - } - - /** - * Build the documentation. - * - * @throws DocletException if there is a problem building the documentation - */ - public abstract void build() throws DocletException; -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractMemberBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractMemberBuilder.java deleted file mode 100644 index af327078a86..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AbstractMemberBuilder.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.List; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; -import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind; - -/** - * The superclass for all member builders. Member builders are only executed - * within Class Builders. They essentially build subcomponents. For example, - * method documentation is a subcomponent of class documentation. - */ -public abstract class AbstractMemberBuilder extends AbstractBuilder { - - protected final TypeElement typeElement; - - protected final VisibleMemberTable visibleMemberTable; - - /** - * Construct a SubBuilder. - * @param context a context object, providing information used in this run - * of the doclet. - */ - public AbstractMemberBuilder(Context context, TypeElement typeElement) { - super(context); - this.typeElement = typeElement; - visibleMemberTable = configuration.getVisibleMemberTable(typeElement); - } - - /** - * This method is not supported by subbuilders. - * - * @throws AssertionError always - */ - @Override - public void build() { - // You may not call the build method in a subbuilder. - throw new AssertionError(); - } - - /** - * Build the documentation. - * - * @param target the content into which to add the documentation - * @throws DocletException if there is a problem building the documentation - */ - public abstract void build(Content target) throws DocletException; - - /** - * Returns true if this subbuilder has anything to document. - * - * @return true if this subbuilder has anything to document - */ - public abstract boolean hasMembersToDocument(); - - /** - * Returns a list of visible elements of the specified kind in this - * type element. - * @param kind of members - * @return a list of members - */ - protected List<Element> getVisibleMembers(Kind kind) { - return visibleMemberTable.getVisibleMembers(kind); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeMemberBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeMemberBuilder.java deleted file mode 100644 index b2c7176664a..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeMemberBuilder.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeMemberWriter; -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds documentation for required annotation type members. - */ -public class AnnotationTypeMemberBuilder extends AbstractMemberBuilder { - - /** - * The writer to output the member documentation. - */ - protected AnnotationTypeMemberWriter writer; - - /** - * The list of members being documented. - */ - protected List<Element> members; - - /** - * The index of the current member that is being documented at this point - * in time. - */ - protected Element currentMember; - - /** - * Construct a new AnnotationTypeRequiredMemberBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - */ - protected AnnotationTypeMemberBuilder(Context context, - TypeElement typeElement, - AnnotationTypeMemberWriter writer) { - super(context, typeElement); - this.writer = Objects.requireNonNull(writer); - // In contrast to the annotation interface member summaries the details generated - // by this builder share a single list for both required and optional members. - this.members = getVisibleMembers(ANNOTATION_TYPE_MEMBER); - } - - - /** - * Construct a new AnnotationTypeMemberBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - * @return an instance of this object - */ - public static AnnotationTypeMemberBuilder getInstance( - Context context, TypeElement typeElement, - AnnotationTypeMemberWriter writer) { - return new AnnotationTypeMemberBuilder(context, typeElement, - writer); - } - - /** - * Returns whether or not there are members to document. - * @return whether or not there are members to document - */ - @Override - public boolean hasMembersToDocument() { - return !members.isEmpty(); - } - - @Override - public void build(Content target) throws DocletException { - buildAnnotationTypeMember(target); - } - - /** - * Build the member documentation. - * - * @param target the content to which the documentation will be added - * @throws DocletException if an error occurs - */ - protected void buildAnnotationTypeMember(Content target) - throws DocletException { - if (hasMembersToDocument()) { - writer.addAnnotationDetailsMarker(target); - Content annotationDetailsHeader = writer.getAnnotationDetailsHeader(); - Content memberList = writer.getMemberList(); - - for (Element member : members) { - currentMember = member; - Content annotationContent = writer.getAnnotationHeaderContent(currentMember); - - buildAnnotationTypeMemberChildren(annotationContent); - - memberList.add(writer.getMemberListItem(annotationContent)); - } - Content annotationDetails = writer.getAnnotationDetails(annotationDetailsHeader, memberList); - target.add(annotationDetails); - } - } - - protected void buildAnnotationTypeMemberChildren(Content annotationContent) { - buildSignature(annotationContent); - buildDeprecationInfo(annotationContent); - buildPreviewInfo(annotationContent); - buildMemberComments(annotationContent); - buildTagInfo(annotationContent); - buildDefaultValueInfo(annotationContent); - } - - /** - * Build the signature. - * - * @param target the content to which the documentation will be added - */ - protected void buildSignature(Content target) { - target.add(writer.getSignature(currentMember)); - } - - /** - * Build the deprecation information. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content annotationContent) { - writer.addDeprecated(currentMember, annotationContent); - } - - /** - * Build the preview information. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content annotationContent) { - writer.addPreview(currentMember, annotationContent); - } - - /** - * Build the comments for the member. Do nothing if - * {@link BaseOptions#noComment()} is set to true. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildMemberComments(Content annotationContent) { - if (!options.noComment()) { - writer.addComments(currentMember, annotationContent); - } - } - - /** - * Build the tag information. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildTagInfo(Content annotationContent) { - writer.addTags(currentMember, annotationContent); - } - - /** - * Build the default value for this optional member. - * - * @param annotationContent the content to which the documentation will be added - */ - protected void buildDefaultValueInfo(Content annotationContent) { - writer.addDefaultValueInfo(currentMember, annotationContent); - } - - /** - * Return the annotation type required member writer for this builder. - * - * @return the annotation type required member constant writer for this - * builder. - */ - public AnnotationTypeMemberWriter getWriter() { - return writer; - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java deleted file mode 100644 index e1710f3ca0f..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/BuilderFactory.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.HashSet; -import java.util.Set; - -import javax.lang.model.element.ModuleElement; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; -import jdk.javadoc.internal.doclets.toolkit.ClassWriter; -import jdk.javadoc.internal.doclets.toolkit.PropertyWriter; -import jdk.javadoc.internal.doclets.toolkit.WriterFactory; -import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; - -/** - * The factory for constructing builders. - */ -public class BuilderFactory { - - /** - * The factory to retrieve the required writers from. - */ - private final WriterFactory writerFactory; - - private final AbstractBuilder.Context context; - - /** - * Construct a builder factory using the given configuration. - * @param configuration the configuration for the current doclet - * being executed. - */ - public BuilderFactory (BaseConfiguration configuration) { - this.writerFactory = configuration.getWriterFactory(); - - Set<PackageElement> containingPackagesSeen = new HashSet<>(); - context = new AbstractBuilder.Context(configuration, containingPackagesSeen); - } - - /** - * Return the builder that builds the constant summary. - * @return the builder that builds the constant summary. - */ - public AbstractBuilder getConstantsSummaryBuilder() { - return ConstantsSummaryBuilder.getInstance(context); - } - - /** - * Return the builder that builds the package summary. - * - * @param pkg the package being documented. - * @return the builder that builds the package summary. - */ - public AbstractBuilder getPackageSummaryBuilder(PackageElement pkg) { - return PackageSummaryBuilder.getInstance(context, pkg, - writerFactory.getPackageSummaryWriter(pkg)); - } - - /** - * Return the builder that builds the module summary. - * - * @param mdle the module being documented. - * @return the builder that builds the module summary. - */ - public AbstractBuilder getModuleSummaryBuilder(ModuleElement mdle) { - return ModuleSummaryBuilder.getInstance(context, mdle, - writerFactory.getModuleSummaryWriter(mdle)); - } - - /** - * Return the builder for the class. - * - * @param typeElement the class being documented. - * @param classTree the class tree. - * @return the writer for the class. Return null if this - * writer is not supported by the doclet. - */ - public AbstractBuilder getClassBuilder(TypeElement typeElement, ClassTree classTree) { - return ClassBuilder.getInstance(context, typeElement, - writerFactory.getClassWriter(typeElement, classTree)); - } - - /** - * Return an instance of the method builder for the given class. - * - * @param classWriter the writer for the enclosing class - * @return an instance of the method builder for the given class. - */ - public AbstractMemberBuilder getMethodBuilder(ClassWriter classWriter) { - return MethodBuilder.getInstance(context, classWriter.getTypeElement(), - writerFactory.getMethodWriter(classWriter)); - } - - /** - * Return an instance of the annotation type member builder for the given - * class. - * - * @param classWriter the writer for the enclosing annotation type - * @return an instance of the annotation type member builder for the given - * annotation type. - */ - public AbstractMemberBuilder getAnnotationTypeMemberBuilder( - ClassWriter classWriter) { - return AnnotationTypeMemberBuilder.getInstance(context, - classWriter.getTypeElement(), - writerFactory.getAnnotationTypeMemberWriter(classWriter)); - } - - /** - * Return an instance of the enum constants builder for the given class. - * - * @param classWriter the writer for the enclosing class - * @return an instance of the enum constants builder for the given class. - */ - public AbstractMemberBuilder getEnumConstantsBuilder(ClassWriter classWriter) { - return EnumConstantBuilder.getInstance(context, classWriter.getTypeElement(), - writerFactory.getEnumConstantWriter(classWriter)); - } - - /** - * Return an instance of the field builder for the given class. - * - * @param classWriter the writer for the enclosing class - * @return an instance of the field builder for the given class. - */ - public AbstractMemberBuilder getFieldBuilder(ClassWriter classWriter) { - return FieldBuilder.getInstance(context, classWriter.getTypeElement(), - writerFactory.getFieldWriter(classWriter)); - } - - /** - * Return an instance of the property builder for the given class. - * - * @param classWriter the writer for the enclosing class - * @return an instance of the field builder for the given class. - */ - public AbstractMemberBuilder getPropertyBuilder(ClassWriter classWriter) { - final PropertyWriter propertyWriter = - writerFactory.getPropertyWriter(classWriter); - return PropertyBuilder.getInstance(context, - classWriter.getTypeElement(), - propertyWriter); - } - - /** - * Return an instance of the constructor builder for the given class. - * - * @param classWriter the writer for the enclosing class - * @return an instance of the constructor builder for the given class. - */ - public AbstractMemberBuilder getConstructorBuilder(ClassWriter classWriter) { - return ConstructorBuilder.getInstance(context, classWriter.getTypeElement(), - writerFactory.getConstructorWriter(classWriter)); - } - - /** - * Return an instance of the member summary builder for the given class. - * - * @param classWriter the writer for the enclosing class - * @return an instance of the member summary builder for the given class. - */ - public MemberSummaryBuilder getMemberSummaryBuilder(ClassWriter classWriter) { - return MemberSummaryBuilder.getInstance(classWriter, context); - } - - /** - * Return the builder that builds the serialized form. - * - * @return the builder that builds the serialized form. - */ - public AbstractBuilder getSerializedFormBuilder() { - return SerializedFormBuilder.getInstance(context); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java deleted file mode 100644 index e20ad98a12f..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java +++ /dev/null @@ -1,476 +0,0 @@ -/* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Name; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.TypeMirror; - -import jdk.javadoc.internal.doclets.toolkit.ClassWriter; -import jdk.javadoc.internal.doclets.toolkit.CommentUtils; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; -import jdk.javadoc.internal.doclets.toolkit.util.Utils; - -/** - * Builds the summary for a given class. - */ -public class ClassBuilder extends AbstractBuilder { - - /** - * The class being documented. - */ - private final TypeElement typeElement; - - /** - * The doclet specific writer. - */ - private final ClassWriter writer; - - private final Utils utils; - - /** - * Construct a new ClassBuilder. - * - * @param context the build context - * @param typeElement the class being documented. - * @param writer the doclet specific writer. - */ - private ClassBuilder(Context context, TypeElement typeElement, ClassWriter writer) { - super(context); - this.typeElement = typeElement; - this.writer = writer; - this.utils = configuration.utils; - switch (typeElement.getKind()) { - case ENUM -> setEnumDocumentation(typeElement); - case RECORD -> setRecordDocumentation(typeElement); - } - } - - /** - * Constructs a new ClassBuilder. - * - * @param context the build context - * @param typeElement the class being documented. - * @param writer the doclet specific writer. - * @return the new ClassBuilder - */ - public static ClassBuilder getInstance(Context context, TypeElement typeElement, ClassWriter writer) { - return new ClassBuilder(context, typeElement, writer); - } - - @Override - public void build() throws DocletException { - buildClassDoc(); - } - - /** - * Handles the {@literal <TypeElement>} tag. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildClassDoc() throws DocletException { - String key = switch (typeElement.getKind()) { - case INTERFACE -> "doclet.Interface"; - case ENUM -> "doclet.Enum"; - case RECORD -> "doclet.RecordClass"; - case ANNOTATION_TYPE -> "doclet.AnnotationType"; - case CLASS -> "doclet.Class"; - default -> throw new IllegalStateException(typeElement.getKind() + " " + typeElement); - }; - Content content = writer.getHeader(resources.getText(key) + " " - + utils.getSimpleName(typeElement)); - Content classContent = writer.getClassContentHeader(); - - buildClassTree(classContent); - buildClassInfo(classContent); - buildMemberSummary(classContent); - buildMemberDetails(classContent); - - writer.addClassContent(classContent); - writer.addFooter(); - writer.printDocument(content); - copyDocFiles(); - } - - /** - * Build the class inheritance tree documentation. - * - * @param classContent the content to which the documentation will be added - */ - protected void buildClassTree(Content classContent) { - writer.addClassTree(classContent); - } - - /** - * Build the class information documentation. - * - * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildClassInfo(Content target) throws DocletException { - Content c = writer.getOutputInstance(); - buildParamInfo(c); - buildSuperInterfacesInfo(c); - buildImplementedInterfacesInfo(c); - buildSubClassInfo(c); - buildSubInterfacesInfo(c); - buildInterfaceUsageInfo(c); - buildNestedClassInfo(c); - buildFunctionalInterfaceInfo(c); - buildClassSignature(c); - buildDeprecationInfo(c); - buildClassDescription(c); - buildClassTagInfo(c); - - target.add(writer.getClassInfo(c)); - } - - /** - * Build the type parameters and state components of this class. - * - * @param target the content to which the documentation will be added - */ - protected void buildParamInfo(Content target) { - writer.addParamInfo(target); - } - - /** - * If this is an interface, list all superinterfaces. - * - * @param target the content to which the documentation will be added - */ - protected void buildSuperInterfacesInfo(Content target) { - writer.addSuperInterfacesInfo(target); - } - - /** - * If this is a class, list all interfaces implemented by this class. - * - * @param target the content to which the documentation will be added - */ - protected void buildImplementedInterfacesInfo(Content target) { - writer.addImplementedInterfacesInfo(target); - } - - /** - * List all the classes that extend this one. - * - * @param target the content to which the documentation will be added - */ - protected void buildSubClassInfo(Content target) { - writer.addSubClassInfo(target); - } - - /** - * List all the interfaces that extend this one. - * - * @param target the content to which the documentation will be added - */ - protected void buildSubInterfacesInfo(Content target) { - writer.addSubInterfacesInfo(target); - } - - /** - * If this is an interface, list all classes that implement this interface. - * - * @param target the content to which the documentation will be added - */ - protected void buildInterfaceUsageInfo(Content target) { - writer.addInterfaceUsageInfo(target); - } - - /** - * If this is an functional interface, display appropriate message. - * - * @param target the content to which the documentation will be added - */ - protected void buildFunctionalInterfaceInfo(Content target) { - writer.addFunctionalInterfaceInfo(target); - } - - /** - * If this class is deprecated, build the appropriate information. - * - * @param target the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content target) { - writer.addClassDeprecationInfo(target); - } - - /** - * If this is an inner class or interface, list the enclosing class or interface. - * - * @param target the content to which the documentation will be added - */ - protected void buildNestedClassInfo(Content target) { - writer.addNestedClassInfo(target); - } - - /** - * Copy the doc files. - * - * @throws DocFileIOException if there is a problem while copying the files - */ - private void copyDocFiles() throws DocletException { - PackageElement containingPackage = utils.containingPackage(typeElement); - if ((configuration.packages == null || - !configuration.packages.contains(containingPackage)) && - !containingPackagesSeen.contains(containingPackage)) { - //Only copy doc files dir if the containing package is not - //documented AND if we have not documented a class from the same - //package already. Otherwise, we are making duplicate copies. - DocFilesHandler docFilesHandler = configuration - .getWriterFactory() - .getDocFilesHandler(containingPackage); - docFilesHandler.copyDocFiles(); - containingPackagesSeen.add(containingPackage); - } - } - - /** - * Build the signature of the current class. - * - * @param target the content to which the documentation will be added - */ - protected void buildClassSignature(Content target) { - writer.addClassSignature(target); - } - - /** - * Build the class description. - * - * @param target the content to which the documentation will be added - */ - protected void buildClassDescription(Content target) { - writer.addClassDescription(target); - } - - /** - * Build the tag information for the current class. - * - * @param target the content to which the documentation will be added - */ - protected void buildClassTagInfo(Content target) { - writer.addClassTagInfo(target); - } - - /** - * Build the member summary contents of the page. - * - * @param classContent the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildMemberSummary(Content classContent) throws DocletException { - Content summariesList = writer.getSummariesList(); - builderFactory.getMemberSummaryBuilder(writer).build(summariesList); - classContent.add(writer.getMemberSummary(summariesList)); - } - - /** - * Build the member details contents of the page. - * - * @param classContent the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildMemberDetails(Content classContent) throws DocletException { - Content detailsList = writer.getDetailsList(); - - buildEnumConstantsDetails(detailsList); - buildPropertyDetails(detailsList); - buildFieldDetails(detailsList); - buildConstructorDetails(detailsList); - buildAnnotationTypeMemberDetails(detailsList); - buildMethodDetails(detailsList); - - classContent.add(writer.getMemberDetails(detailsList)); - } - - /** - * Build the enum constants documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildEnumConstantsDetails(Content detailsList) throws DocletException { - builderFactory.getEnumConstantsBuilder(writer).build(detailsList); - } - - /** - * Build the field documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildFieldDetails(Content detailsList) throws DocletException { - builderFactory.getFieldBuilder(writer).build(detailsList); - } - - /** - * Build the property documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - public void buildPropertyDetails( Content detailsList) throws DocletException { - builderFactory.getPropertyBuilder(writer).build(detailsList); - } - - /** - * Build the constructor documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildConstructorDetails(Content detailsList) throws DocletException { - builderFactory.getConstructorBuilder(writer).build(detailsList); - } - - /** - * Build the method documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildMethodDetails(Content detailsList) throws DocletException { - builderFactory.getMethodBuilder(writer).build(detailsList); - } - - /** - * Build the annotation type optional member documentation. - * - * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem building the documentation - */ - protected void buildAnnotationTypeMemberDetails(Content target) - throws DocletException { - builderFactory.getAnnotationTypeMemberBuilder(writer).build(target); - } - - /** - * The documentation for values() and valueOf() in Enums are set by the - * doclet only iff the user or overridden methods are missing. - * @param elem the enum element - */ - private void setEnumDocumentation(TypeElement elem) { - CommentUtils cmtUtils = configuration.cmtUtils; - for (ExecutableElement ee : utils.getMethods(elem)) { - if (!utils.getFullBody(ee).isEmpty()) // ignore if already set - continue; - Name name = ee.getSimpleName(); - if (name.contentEquals("values") && ee.getParameters().isEmpty()) { - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setEnumValuesTree(ee); - } else if (name.contentEquals("valueOf") && ee.getParameters().size() == 1) { - // TODO: check parameter type - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setEnumValueOfTree(ee); - } - } - } - - /** - * Sets the documentation as needed for the mandated parts of a record type. - * This includes the canonical constructor, methods like {@code equals}, - * {@code hashCode}, {@code toString}, the accessor methods, and the underlying - * field. - * @param elem the record element - */ - - private void setRecordDocumentation(TypeElement elem) { - CommentUtils cmtUtils = configuration.cmtUtils; - Set<Name> componentNames = elem.getRecordComponents().stream() - .map(Element::getSimpleName) - .collect(Collectors.toSet()); - - for (ExecutableElement ee : utils.getConstructors(elem)) { - if (utils.isCanonicalRecordConstructor(ee)) { - if (utils.getFullBody(ee).isEmpty()) { - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setRecordConstructorTree(ee); - } - // only one canonical constructor; no need to keep looking - break; - } - } - - var fields = utils.isSerializable(elem) - ? utils.getFieldsUnfiltered(elem) - : utils.getFields(elem); - for (VariableElement ve : fields) { - // The fields for the record component cannot be declared by the - // user and so cannot have any pre-existing comment. - Name name = ve.getSimpleName(); - if (componentNames.contains(name)) { - utils.removeCommentHelper(ve); // purge previous entry - cmtUtils.setRecordFieldTree(ve); - } - } - - TypeMirror objectType = utils.getObjectType(); - - for (ExecutableElement ee : utils.getMethods(elem)) { - if (!utils.getFullBody(ee).isEmpty()) { - continue; - } - - Name name = ee.getSimpleName(); - List<? extends VariableElement> params = ee.getParameters(); - if (name.contentEquals("equals")) { - if (params.size() == 1 && utils.typeUtils.isSameType(params.get(0).asType(), objectType)) { - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setRecordEqualsTree(ee); - } - } else if (name.contentEquals("hashCode")) { - if (params.isEmpty()) { - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setRecordHashCodeTree(ee); - } - } else if (name.contentEquals("toString")) { - if (params.isEmpty()) { - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setRecordToStringTree(ee); - } - } else if (componentNames.contains(name)) { - if (params.isEmpty()) { - utils.removeCommentHelper(ee); // purge previous entry - cmtUtils.setRecordAccessorTree(ee); - } - } - } - - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstantsSummaryBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstantsSummaryBuilder.java deleted file mode 100644 index 23b2c663999..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstantsSummaryBuilder.java +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; - -import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds the Constants Summary Page. - */ -public class ConstantsSummaryBuilder extends AbstractBuilder { - - /** - * The maximum number of package directories shown in the headings of - * the constant values contents list and headings. - */ - private static final int MAX_CONSTANT_VALUE_INDEX_LENGTH = 2; - - /** - * The writer used to write the results. - */ - protected ConstantsSummaryWriter writer; - - /** - * The set of type elements that have constant fields. - */ - protected final Set<TypeElement> typeElementsWithConstFields; - - /** - * The set of package-group headings. - */ - protected final Set<String> packageGroupHeadings; - - /** - * The current package being documented. - */ - private PackageElement currentPackage; - - /** - * The current class being documented. - */ - private TypeElement currentClass; - - /** - * Constructs a new {@code ConstantsSummaryBuilder}. - * - * @param context the build context - */ - private ConstantsSummaryBuilder(Context context) { - super(context); - this.typeElementsWithConstFields = new HashSet<>(); - this.packageGroupHeadings = new TreeSet<>(utils::compareStrings); - } - - /** - * Constructs a {@code ConstantsSummaryBuilder}. - * - * @param context the build context - * @return the new ConstantsSummaryBuilder - */ - public static ConstantsSummaryBuilder getInstance(Context context) { - return new ConstantsSummaryBuilder(context); - } - - @Override - public void build() throws DocletException { - boolean anyConstants = configuration.packages.stream().anyMatch(this::hasConstantField); - if (!anyConstants) { - return; - } - - writer = configuration.getWriterFactory().getConstantsSummaryWriter(); - if (writer == null) { - //Doclet does not support this output. - return; - } - buildConstantSummary(); - } - - /** - * Builds the constant summary page. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildConstantSummary() throws DocletException { - Content content = writer.getHeader(); - - buildContents(); - buildConstantSummaries(); - - writer.addFooter(); - writer.printDocument(content); - } - - /** - * Builds the list of contents for the groups of packages appearing in the constants summary page. - */ - protected void buildContents() { - Content contentList = writer.getContentsHeader(); - packageGroupHeadings.clear(); - for (PackageElement pkg : configuration.packages) { - String abbrevPackageName = getAbbrevPackageName(pkg); - if (hasConstantField(pkg) && !packageGroupHeadings.contains(abbrevPackageName)) { - writer.addLinkToPackageContent(abbrevPackageName, contentList); - packageGroupHeadings.add(abbrevPackageName); - } - } - writer.addContentsList(contentList); - } - - /** - * Builds the summary for each documented package. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildConstantSummaries() throws DocletException { - packageGroupHeadings.clear(); - Content summaries = writer.getConstantSummaries(); - for (PackageElement aPackage : configuration.packages) { - if (hasConstantField(aPackage)) { - currentPackage = aPackage; - //Build the documentation for the current package. - buildPackageHeader(summaries); - buildClassConstantSummary(); - } - } - writer.addConstantSummaries(summaries); - } - - /** - * Builds the header for the given package. - * - * @param target the content to which the package header will be added - */ - protected void buildPackageHeader(Content target) { - String abbrevPkgName = getAbbrevPackageName(currentPackage); - if (!packageGroupHeadings.contains(abbrevPkgName)) { - writer.addPackageGroup(abbrevPkgName, target); - packageGroupHeadings.add(abbrevPkgName); - } - } - - /** - * Builds the summary for the current class. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildClassConstantSummary() - throws DocletException { - SortedSet<TypeElement> classes = !currentPackage.isUnnamed() - ? utils.getAllClasses(currentPackage) - : configuration.typeElementCatalog.allUnnamedClasses(); - Content classConstantHeader = writer.getClassConstantHeader(); - for (TypeElement te : classes) { - if (!typeElementsWithConstFields.contains(te) || - !utils.isIncluded(te)) { - continue; - } - currentClass = te; - //Build the documentation for the current class. - - buildConstantMembers(classConstantHeader); - - } - writer.addClassConstant(classConstantHeader); - } - - /** - * Builds the summary of constant members in the class. - * - * @param target the content to which the table of constant members will be added - */ - protected void buildConstantMembers(Content target) { - new ConstantFieldBuilder(currentClass).buildMembersSummary(target); - } - - /** - * {@return true if the given package has constant fields to document} - * - * @param pkg the package to be checked - */ - private boolean hasConstantField(PackageElement pkg) { - SortedSet<TypeElement> classes = !pkg.isUnnamed() - ? utils.getAllClasses(pkg) - : configuration.typeElementCatalog.allUnnamedClasses(); - boolean found = false; - for (TypeElement te : classes) { - if (utils.isIncluded(te) && hasConstantField(te)) { - found = true; - } - } - return found; - } - - /** - * {@return true if the given class has constant fields to document} - * - * @param typeElement the class to be checked - */ - private boolean hasConstantField (TypeElement typeElement) { - VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); - List<? extends Element> fields = vmt.getVisibleMembers(FIELDS); - for (Element f : fields) { - VariableElement field = (VariableElement)f; - if (field.getConstantValue() != null) { - typeElementsWithConstFields.add(typeElement); - return true; - } - } - return false; - } - - /** - * {@return the abbreviated name for a package, containing the leading segments of the name} - * - * @param pkg the package - */ - public String getAbbrevPackageName(PackageElement pkg) { - if (pkg.isUnnamed()) { - return ""; - } - - String packageName = utils.getPackageName(pkg); - int index = -1; - for (int j = 0; j < MAX_CONSTANT_VALUE_INDEX_LENGTH; j++) { - index = packageName.indexOf(".", index + 1); - } - return index == -1 ? packageName : packageName.substring(0, index); - } - - /** - * Builder for the table of fields with constant values. - */ - private class ConstantFieldBuilder { - - /** - * The type element that we are examining constants for. - */ - protected TypeElement typeElement; - - /** - * Constructs a {@code ConstantFieldBuilder}. - * @param typeElement the type element that we are examining constants for - */ - public ConstantFieldBuilder(TypeElement typeElement) { - this.typeElement = typeElement; - } - - /** - * Builds the table of constants for a given class. - * - * @param target the content to which the table of class constants will be added - */ - protected void buildMembersSummary(Content target) { - SortedSet<VariableElement> members = members(); - if (!members.isEmpty()) { - writer.addConstantMembers(typeElement, members, target); - } - } - - /** - * {@return a set of visible constant fields for the given type} - */ - protected SortedSet<VariableElement> members() { - VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement); - List<Element> members = new ArrayList<>(); - members.addAll(vmt.getVisibleMembers(FIELDS)); - members.addAll(vmt.getVisibleMembers(ENUM_CONSTANTS)); - SortedSet<VariableElement> includes = - new TreeSet<>(utils.comparators.makeGeneralPurposeComparator()); - for (Element element : members) { - VariableElement member = (VariableElement)element; - if (member.getConstantValue() != null) { - includes.add(member); - } - } - return includes; - } - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstructorBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstructorBuilder.java deleted file mode 100644 index ed7ffa94e86..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstructorBuilder.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; - -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -import jdk.javadoc.internal.doclets.toolkit.ConstructorWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds documentation for a constructor. - */ -public class ConstructorBuilder extends AbstractMemberBuilder { - - /** - * The current constructor that is being documented at this point in time. - */ - private ExecutableElement currentConstructor; - - /** - * The writer to output the constructor documentation. - */ - private final ConstructorWriter writer; - - /** - * The constructors being documented. - */ - private final List<? extends Element> constructors; - - /** - * Construct a new ConstructorBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - */ - private ConstructorBuilder(Context context, - TypeElement typeElement, - ConstructorWriter writer) { - super(context, typeElement); - this.writer = Objects.requireNonNull(writer); - constructors = getVisibleMembers(CONSTRUCTORS); - for (Element ctor : constructors) { - if (utils.isProtected(ctor) || utils.isPrivate(ctor)) { - writer.setFoundNonPubConstructor(true); - } - } - } - - /** - * Construct a new ConstructorBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - * @return the new ConstructorBuilder - */ - public static ConstructorBuilder getInstance(Context context, - TypeElement typeElement, ConstructorWriter writer) { - return new ConstructorBuilder(context, typeElement, writer); - } - - @Override - public boolean hasMembersToDocument() { - return !constructors.isEmpty(); - } - - /** - * Return the constructor writer for this builder. - * - * @return the constructor writer for this builder. - */ - public ConstructorWriter getWriter() { - return writer; - } - - @Override - public void build(Content target) throws DocletException { - buildConstructorDoc(target); - } - - /** - * Build the constructor documentation. - * - * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildConstructorDoc(Content target) throws DocletException { - if (hasMembersToDocument()) { - Content constructorDetailsHeader = writer.getConstructorDetailsHeader(target); - Content memberList = writer.getMemberList(); - - for (Element constructor : constructors) { - currentConstructor = (ExecutableElement)constructor; - Content constructorContent = writer.getConstructorHeaderContent(currentConstructor); - - buildSignature(constructorContent); - buildDeprecationInfo(constructorContent); - buildPreviewInfo(constructorContent); - buildConstructorComments(constructorContent); - buildTagInfo(constructorContent); - - memberList.add(writer.getMemberListItem(constructorContent)); - } - Content constructorDetails = writer.getConstructorDetails(constructorDetailsHeader, memberList); - target.add(constructorDetails); - } - } - - /** - * Build the signature. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildSignature(Content constructorContent) { - constructorContent.add(writer.getSignature(currentConstructor)); - } - - /** - * Build the deprecation information. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content constructorContent) { - writer.addDeprecated(currentConstructor, constructorContent); - } - - /** - * Build the preview information. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content constructorContent) { - writer.addPreview(currentConstructor, constructorContent); - } - - /** - * Build the comments for the constructor. Do nothing if - * {@link BaseOptions#noComment()} is set to true. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildConstructorComments(Content constructorContent) { - if (!options.noComment()) { - writer.addComments(currentConstructor, constructorContent); - } - } - - /** - * Build the tag information. - * - * @param constructorContent the content to which the documentation will be added - */ - protected void buildTagInfo(Content constructorContent) { - writer.addTags(currentConstructor, constructorContent); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/EnumConstantBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/EnumConstantBuilder.java deleted file mode 100644 index da0d6361bd9..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/EnumConstantBuilder.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; - -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.EnumConstantWriter; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds documentation for a enum constants. - */ -public class EnumConstantBuilder extends AbstractMemberBuilder { - - /** - * The writer to output the enum constants documentation. - */ - private final EnumConstantWriter writer; - - /** - * The set of enum constants being documented. - */ - private final List<? extends Element> enumConstants; - - /** - * The current enum constant that is being documented at this point - * in time. - */ - private VariableElement currentElement; - - /** - * Construct a new EnumConstantsBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - */ - private EnumConstantBuilder(Context context, - TypeElement typeElement, EnumConstantWriter writer) { - super(context, typeElement); - this.writer = Objects.requireNonNull(writer); - enumConstants = getVisibleMembers(ENUM_CONSTANTS); - } - - /** - * Construct a new EnumConstantsBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - * @return the new EnumConstantsBuilder - */ - public static EnumConstantBuilder getInstance(Context context, - TypeElement typeElement, EnumConstantWriter writer) { - return new EnumConstantBuilder(context, typeElement, writer); - } - - /** - * Returns whether or not there are members to document. - * - * @return whether or not there are members to document - */ - @Override - public boolean hasMembersToDocument() { - return !enumConstants.isEmpty(); - } - - @Override - public void build(Content target) throws DocletException { - buildEnumConstant(target); - } - - /** - * Build the enum constant documentation. - * - * @param target the content to which the documentation will be added - * @throws DocletException is there is a problem while building the documentation - */ - protected void buildEnumConstant(Content target) throws DocletException { - if (hasMembersToDocument()) { - Content enumConstantsDetailsHeader = writer.getEnumConstantsDetailsHeader(typeElement, - target); - Content memberList = writer.getMemberList(); - - for (Element enumConstant : enumConstants) { - currentElement = (VariableElement)enumConstant; - Content enumConstants = writer.getEnumConstantsHeader(currentElement, - memberList); - - buildSignature(enumConstants); - buildDeprecationInfo(enumConstants); - buildPreviewInfo(enumConstants); - buildEnumConstantComments(enumConstants); - buildTagInfo(enumConstants); - - memberList.add(writer.getMemberListItem(enumConstants)); - } - Content enumConstantDetails = writer.getEnumConstantsDetails( - enumConstantsDetailsHeader, memberList); - target.add(enumConstantDetails); - } - } - - /** - * Build the signature. - * - * @param target the content to which the documentation will be added - */ - protected void buildSignature(Content target) { - target.add(writer.getSignature(currentElement)); - } - - /** - * Build the deprecation information. - * - * @param target the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content target) { - writer.addDeprecated(currentElement, target); - } - - /** - * Build the preview information. - * - * @param target the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content target) { - writer.addPreview(currentElement, target); - } - - /** - * Build the comments for the enum constant. Do nothing if - * {@link BaseOptions#noComment()} is set to true. - * - * @param target the content to which the documentation will be added - */ - protected void buildEnumConstantComments(Content target) { - if (!options.noComment()) { - writer.addComments(currentElement, target); - } - } - - /** - * Build the tag information. - * - * @param target the content to which the documentation will be added - */ - protected void buildTagInfo(Content target) { - writer.addTags(currentElement, target); - } - - /** - * Return the enum constant writer for this builder. - * - * @return the enum constant writer for this builder. - */ - public EnumConstantWriter getWriter() { - return writer; - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/FieldBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/FieldBuilder.java deleted file mode 100644 index 2fe8141e1ca..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/FieldBuilder.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; - -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.FieldWriter; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds documentation for a field. - */ -public class FieldBuilder extends AbstractMemberBuilder { - - /** - * The writer to output the field documentation. - */ - private final FieldWriter writer; - - /** - * The list of fields being documented. - */ - private final List<? extends Element> fields; - - /** - * The index of the current field that is being documented at this point - * in time. - */ - private VariableElement currentElement; - - /** - * Construct a new FieldBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - */ - private FieldBuilder(Context context, - TypeElement typeElement, - FieldWriter writer) { - super(context, typeElement); - this.writer = Objects.requireNonNull(writer); - fields = getVisibleMembers(FIELDS); - } - - /** - * Construct a new FieldBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - * @return the new FieldBuilder - */ - public static FieldBuilder getInstance(Context context, - TypeElement typeElement, - FieldWriter writer) { - return new FieldBuilder(context, typeElement, writer); - } - - /** - * Returns whether or not there are members to document. - * - * @return whether or not there are members to document - */ - @Override - public boolean hasMembersToDocument() { - return !fields.isEmpty(); - } - - @Override - public void build(Content target) throws DocletException { - buildFieldDoc(target); - } - - /** - * Build the field documentation. - * - * @param target the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildFieldDoc(Content target) throws DocletException { - if (!fields.isEmpty()) { - Content fieldDetailsHeader = writer.getFieldDetailsHeader(target); - Content memberList = writer.getMemberList(); - - for (Element element : fields) { - currentElement = (VariableElement)element; - Content fieldContent = writer.getFieldHeaderContent(currentElement); - - buildSignature(fieldContent); - buildDeprecationInfo(fieldContent); - buildPreviewInfo(fieldContent); - buildFieldComments(fieldContent); - buildTagInfo(fieldContent); - - memberList.add(writer.getMemberListItem(fieldContent)); - } - Content fieldDetails = writer.getFieldDetails(fieldDetailsHeader, memberList); - target.add(fieldDetails); - } - } - - /** - * Build the signature. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildSignature(Content fieldContent) { - fieldContent.add(writer.getSignature(currentElement)); - } - - /** - * Build the deprecation information. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content fieldContent) { - writer.addDeprecated(currentElement, fieldContent); - } - - /** - * Build the preview information. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content fieldContent) { - writer.addPreview(currentElement, fieldContent); - } - - /** - * Build the comments for the field. Do nothing if - * {@link BaseOptions#noComment()} is set to true. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildFieldComments(Content fieldContent) { - if (!options.noComment()) { - writer.addComments(currentElement, fieldContent); - } - } - - /** - * Build the tag information. - * - * @param fieldContent the content to which the documentation will be added - */ - protected void buildTagInfo(Content fieldContent) { - writer.addTags(currentElement, fieldContent); - } - - /** - * Return the field writer for this builder. - * - * @return the field writer for this builder. - */ - public FieldWriter getWriter() { - return writer; - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MemberSummaryBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MemberSummaryBuilder.java deleted file mode 100644 index 843566d41f6..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MemberSummaryBuilder.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.Collection; -import java.util.Comparator; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.SortedSet; -import java.util.TreeSet; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.util.ElementFilter; -import javax.tools.Diagnostic; - -import com.sun.source.doctree.DocCommentTree; -import com.sun.source.doctree.DocTree; -import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; -import jdk.javadoc.internal.doclets.toolkit.ClassWriter; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; -import jdk.javadoc.internal.doclets.toolkit.WriterFactory; -import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; -import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Result; -import jdk.javadoc.internal.doclets.toolkit.util.Utils; -import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds the member summary. - * There are two anonymous subtype variants of this builder, created - * in the {@link #getInstance} methods. One is for general types; - * the other is for annotation types. - */ -public abstract class MemberSummaryBuilder extends AbstractMemberBuilder { - - /* - * Comparator used to sort the members in the summary. - */ - private final Comparator<Element> comparator; - - /** - * The member summary writers for the given class. - */ - private final EnumMap<VisibleMemberTable.Kind, MemberSummaryWriter> memberSummaryWriters; - - final PropertyHelper pHelper; - - /** - * Construct a new MemberSummaryBuilder. - * - * @param context the build context. - * @param typeElement the type element. - */ - private MemberSummaryBuilder(Context context, TypeElement typeElement) { - super(context, typeElement); - memberSummaryWriters = new EnumMap<>(VisibleMemberTable.Kind.class); - comparator = utils.comparators.makeIndexElementComparator(); - pHelper = new PropertyHelper(this); - } - - /** - * Construct a new MemberSummaryBuilder for a general type. - * - * @param classWriter the writer for the class whose members are being - * summarized. - * @param context the build context. - * @return the instance - */ - public static MemberSummaryBuilder getInstance( - ClassWriter classWriter, Context context) { - MemberSummaryBuilder builder = new MemberSummaryBuilder(context, classWriter.getTypeElement()) { - @Override - public void build(Content target) { - buildPropertiesSummary(target); - buildNestedClassesSummary(target); - buildEnumConstantsSummary(target); - buildAnnotationTypeRequiredMemberSummary(target); - buildAnnotationTypeOptionalMemberSummary(target); - buildFieldsSummary(target); - buildConstructorsSummary(target); - buildMethodsSummary(target); - } - - @Override - public boolean hasMembersToDocument() { - return visibleMemberTable.hasVisibleMembers(); - } - }; - WriterFactory wf = context.configuration.getWriterFactory(); - for (VisibleMemberTable.Kind kind : VisibleMemberTable.Kind.values()) { - MemberSummaryWriter msw = builder.getVisibleMemberTable().hasVisibleMembers(kind) - ? wf.getMemberSummaryWriter(classWriter, kind) - : null; - builder.memberSummaryWriters.put(kind, msw); - } - return builder; - } - - /** - * Return the specified visible member map. - * - * @return the specified visible member map. - * @throws ArrayIndexOutOfBoundsException when the type is invalid. - * @see VisibleMemberTable - */ - public VisibleMemberTable getVisibleMemberTable() { - return visibleMemberTable; - } - - /**. - * Return the specified member summary writer. - * - * @param kind the kind of member summary writer to return. - * @return the specified member summary writer. - * @throws ArrayIndexOutOfBoundsException when the type is invalid. - * @see VisibleMemberTable - */ - public MemberSummaryWriter getMemberSummaryWriter(VisibleMemberTable.Kind kind) { - return memberSummaryWriters.get(kind); - } - - /** - * Returns a list of methods that will be documented for the given class. - * This information can be used for doclet specific documentation - * generation. - * - * @param kind the kind of elements to return. - * @return a list of methods that will be documented. - * @see VisibleMemberTable - */ - public SortedSet<Element> members(VisibleMemberTable.Kind kind) { - TreeSet<Element> out = new TreeSet<>(comparator); - out.addAll(getVisibleMembers(kind)); - return out; - } - - /** - * Builds the summary for any optional members of an annotation type. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildAnnotationTypeOptionalMemberSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(ANNOTATION_TYPE_MEMBER_OPTIONAL); - addSummary(writer, ANNOTATION_TYPE_MEMBER_OPTIONAL, false, summariesList); - } - - /** - * Builds the summary for any required members of an annotation type. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildAnnotationTypeRequiredMemberSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(ANNOTATION_TYPE_MEMBER_REQUIRED); - addSummary(writer, ANNOTATION_TYPE_MEMBER_REQUIRED, false, summariesList); - } - - /** - * Builds the summary for any enum constants of an enum type. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildEnumConstantsSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(ENUM_CONSTANTS); - addSummary(writer, ENUM_CONSTANTS, false, summariesList); - } - - /** - * Builds the summary for any fields. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildFieldsSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(FIELDS); - addSummary(writer, FIELDS, true, summariesList); - } - - /** - * Builds the summary for any properties. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildPropertiesSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(PROPERTIES); - addSummary(writer, PROPERTIES, true, summariesList); - } - - /** - * Builds the summary for any nested classes. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildNestedClassesSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(NESTED_CLASSES); - addSummary(writer, NESTED_CLASSES, true, summariesList); - } - - /** - * Builds the summary for any methods. - * - * @param summariesList the content to which the documentation will be added - */ - protected void buildMethodsSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(METHODS); - addSummary(writer, METHODS, true, summariesList); - } - - /** - * Builds the summary for any constructors. - * - * @param summariesList the content to which the documentation will be added - */ - protected void buildConstructorsSummary(Content summariesList) { - MemberSummaryWriter writer = memberSummaryWriters.get(CONSTRUCTORS); - addSummary(writer, CONSTRUCTORS, false, summariesList); - } - - /** - * Build the member summary for the given members. - * - * @param writer the summary writer to write the output. - * @param kind the kind of members to summarize. - * @param summaryTreeList the list of contents to which the documentation will be added - */ - private void buildSummary(MemberSummaryWriter writer, - VisibleMemberTable.Kind kind, LinkedList<Content> summaryTreeList) { - SortedSet<? extends Element> members = asSortedSet(getVisibleMembers(kind)); - if (!members.isEmpty()) { - for (Element member : members) { - final Element property = pHelper.getPropertyElement(member); - if (property != null && member instanceof ExecutableElement ee) { - configuration.cmtUtils.updatePropertyMethodComment(ee, property); - } - if (utils.isMethod(member)) { - var docFinder = utils.docFinder(); - Optional<List<? extends DocTree>> r = docFinder.search((ExecutableElement) member, (m -> { - var firstSentenceTrees = utils.getFirstSentenceTrees(m); - Optional<List<? extends DocTree>> optional = firstSentenceTrees.isEmpty() ? Optional.empty() : Optional.of(firstSentenceTrees); - return Result.fromOptional(optional); - })).toOptional(); - // The fact that we use `member` for possibly unrelated tags is suspicious - writer.addMemberSummary(typeElement, member, r.orElse(List.of())); - } else { - writer.addMemberSummary(typeElement, member, utils.getFirstSentenceTrees(member)); - } - } - summaryTreeList.add(writer.getSummaryTable(typeElement)); - } - } - - /** - * Build the inherited member summary for the given methods. - * - * @param writer the writer for this member summary. - * @param kind the kind of members to document. - * @param targets the list of contents to which the documentation will be added - */ - private void buildInheritedSummary(MemberSummaryWriter writer, - VisibleMemberTable.Kind kind, LinkedList<Content> targets) { - VisibleMemberTable visibleMemberTable = getVisibleMemberTable(); - SortedSet<? extends Element> inheritedMembersFromMap = asSortedSet(visibleMemberTable.getAllVisibleMembers(kind)); - - for (TypeElement inheritedClass : visibleMemberTable.getVisibleTypeElements()) { - if (!(utils.isPublic(inheritedClass) || utils.isLinkable(inheritedClass))) { - continue; - } - if (Objects.equals(inheritedClass, typeElement)) { - continue; - } - if (utils.hasHiddenTag(inheritedClass)) { - continue; - } - - List<? extends Element> members = inheritedMembersFromMap.stream() - .filter(e -> Objects.equals(utils.getEnclosingTypeElement(e), inheritedClass)) - .toList(); - - if (!members.isEmpty()) { - SortedSet<Element> inheritedMembers = new TreeSet<>(comparator); - inheritedMembers.addAll(members); - Content inheritedHeader = writer.getInheritedSummaryHeader(inheritedClass); - Content links = writer.getInheritedSummaryLinks(); - addSummaryFootNote(inheritedClass, inheritedMembers, links, writer); - inheritedHeader.add(links); - targets.add(inheritedHeader); - } - } - } - - private void addSummaryFootNote(TypeElement inheritedClass, Iterable<Element> inheritedMembers, - Content links, MemberSummaryWriter writer) { - boolean isFirst = true; - for (var iterator = inheritedMembers.iterator(); iterator.hasNext(); ) { - var member = iterator.next(); - TypeElement t = utils.isUndocumentedEnclosure(inheritedClass) - ? typeElement : inheritedClass; - writer.addInheritedMemberSummary(t, member, isFirst, !iterator.hasNext(), links); - isFirst = false; - } - } - - /** - * Adds the summary for the documentation. - * - * @param writer the writer for this member summary - * @param kind the kind of members to document - * @param showInheritedSummary true if a summary of any inherited elements should be documented - * @param summariesList the list of summaries to which the summary will be added - */ - private void addSummary(MemberSummaryWriter writer, - VisibleMemberTable.Kind kind, - boolean showInheritedSummary, - Content summariesList) - { - LinkedList<Content> summaryTreeList = new LinkedList<>(); - buildSummary(writer, kind, summaryTreeList); - if (showInheritedSummary) - buildInheritedSummary(writer, kind, summaryTreeList); - if (!summaryTreeList.isEmpty()) { - Content member = writer.getMemberSummaryHeader(typeElement, summariesList); - summaryTreeList.forEach(member::add); - writer.addSummary(summariesList, member); - } - } - - private SortedSet<? extends Element> asSortedSet(Collection<? extends Element> members) { - SortedSet<Element> out = new TreeSet<>(comparator); - out.addAll(members); - return out; - } - - /** - * A utility class to manage the property-related methods that should be - * synthesized or updated. - * - * A property may comprise a field (that is typically private, if present), - * a {@code fooProperty()} method (which is the defining characteristic for - * a property), a {@code getFoo()} method and/or a {@code setFoo(Foo foo)} method. - * - * Either the field (if present) or the {@code fooProperty()} method should have a - * comment. If there is no field, or no comment on the field, the description for - * the property will be derived from the description of the {@code fooProperty()} - * method. If any method does not have a comment, one will be provided. - */ - static class PropertyHelper { - - private final Map<Element, Element> classPropertiesMap = new HashMap<>(); - - private final MemberSummaryBuilder builder; - - PropertyHelper(MemberSummaryBuilder builder) { - this.builder = builder; - computeProperties(); - } - - private void computeProperties() { - VisibleMemberTable vmt = builder.getVisibleMemberTable(); - List<ExecutableElement> props = ElementFilter.methodsIn(vmt.getVisibleMembers(PROPERTIES)); - for (ExecutableElement propertyMethod : props) { - ExecutableElement getter = vmt.getPropertyGetter(propertyMethod); - ExecutableElement setter = vmt.getPropertySetter(propertyMethod); - VariableElement field = vmt.getPropertyField(propertyMethod); - - addToPropertiesMap(propertyMethod, field, getter, setter); - } - } - - private void addToPropertiesMap(ExecutableElement propertyMethod, - VariableElement field, - ExecutableElement getter, - ExecutableElement setter) { - // determine the preferred element from which to derive the property description - Element e = field == null || !builder.utils.hasDocCommentTree(field) - ? propertyMethod : field; - - if (e == field && builder.utils.hasDocCommentTree(propertyMethod)) { - BaseConfiguration configuration = builder.configuration; - configuration.getReporter().print(Diagnostic.Kind.WARNING, - propertyMethod, configuration.getDocResources().getText("doclet.duplicate.comment.for.property")); - } - - addToPropertiesMap(propertyMethod, e); - addToPropertiesMap(getter, e); - addToPropertiesMap(setter, e); - } - - private void addToPropertiesMap(Element propertyMethod, - Element commentSource) { - Objects.requireNonNull(commentSource); - if (propertyMethod == null) { - return; - } - - Utils utils = builder.utils; - DocCommentTree docTree = utils.hasDocCommentTree(propertyMethod) - ? utils.getDocCommentTree(propertyMethod) - : null; - - /* The second condition is required for the property buckets. In - * this case the comment is at the property method (not at the field) - * and it needs to be listed in the map. - */ - if ((docTree == null) || propertyMethod.equals(commentSource)) { - classPropertiesMap.put(propertyMethod, commentSource); - } - } - - /** - * Returns the element for the property documentation belonging to the given member. - * @param element the member for which the property documentation is needed. - * @return the element for the property documentation, null if there is none. - */ - public Element getPropertyElement(Element element) { - return classPropertiesMap.get(element); - } - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MethodBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MethodBuilder.java deleted file mode 100644 index c5c4bf11df0..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MethodBuilder.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.*; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.TypeMirror; - -import com.sun.source.doctree.DocTree; -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.MethodWriter; -import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; -import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Result; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*; - -/** - * Builds documentation for a method. - */ -public class MethodBuilder extends AbstractMemberBuilder { - - /** - * The index of the current field that is being documented at this point - * in time. - */ - private ExecutableElement currentMethod; - - /** - * The writer to output the method documentation. - */ - private final MethodWriter writer; - - /** - * The methods being documented. - */ - private final List<? extends Element> methods; - - - /** - * Construct a new MethodBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - */ - private MethodBuilder(Context context, - TypeElement typeElement, - MethodWriter writer) { - super(context, typeElement); - this.writer = Objects.requireNonNull(writer); - methods = getVisibleMembers(METHODS); - } - - /** - * Construct a new MethodBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - * - * @return an instance of a MethodBuilder. - */ - public static MethodBuilder getInstance(Context context, - TypeElement typeElement, MethodWriter writer) { - return new MethodBuilder(context, typeElement, writer); - } - - @Override - public boolean hasMembersToDocument() { - return !methods.isEmpty(); - } - - @Override - public void build(Content target) throws DocletException { - buildMethodDoc(target); - } - - /** - * Build the method documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildMethodDoc(Content detailsList) throws DocletException { - if (hasMembersToDocument()) { - Content methodDetailsHeader = writer.getMethodDetailsHeader(detailsList); - Content memberList = writer.getMemberList(); - - for (Element method : methods) { - currentMethod = (ExecutableElement)method; - Content methodContent = writer.getMethodHeader(currentMethod); - - buildSignature(methodContent); - buildDeprecationInfo(methodContent); - buildPreviewInfo(methodContent); - buildMethodComments(methodContent); - buildTagInfo(methodContent); - - memberList.add(writer.getMemberListItem(methodContent)); - } - Content methodDetails = writer.getMethodDetails(methodDetailsHeader, memberList); - detailsList.add(methodDetails); - } - } - - /** - * Build the signature. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildSignature(Content methodContent) { - methodContent.add(writer.getSignature(currentMethod)); - } - - /** - * Build the deprecation information. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content methodContent) { - writer.addDeprecated(currentMethod, methodContent); - } - - /** - * Build the preview information. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content methodContent) { - writer.addPreview(currentMethod, methodContent); - } - - /** - * Build the comments for the method. Do nothing if - * {@link BaseOptions#noComment()} is set to true. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildMethodComments(Content methodContent) { - if (!options.noComment()) { - assert utils.isMethod(currentMethod); // not all executables are methods - var docFinder = utils.docFinder(); - Optional<ExecutableElement> r = docFinder.search(currentMethod, - m -> Result.fromOptional(utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m))).toOptional(); - ExecutableElement method = r.orElse(currentMethod); - TypeMirror containingType = method.getEnclosingElement().asType(); - writer.addComments(containingType, method, methodContent); - } - } - - /** - * Build the tag information. - * - * @param methodContent the content to which the documentation will be added - */ - protected void buildTagInfo(Content methodContent) { - writer.addTags(currentMethod, methodContent); - } - - /** - * Return the method writer for this builder. - * - * @return the method writer for this builder. - */ - public MethodWriter getWriter() { - return writer; - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java deleted file mode 100644 index 1c20229652f..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import javax.lang.model.element.ModuleElement; - -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter; - - -/** - * Builds the summary for a given module. - */ -public class ModuleSummaryBuilder extends AbstractBuilder { - - /** - * The module being documented. - */ - private final ModuleElement mdle; - - /** - * The doclet specific writer that will output the result. - */ - private final ModuleSummaryWriter moduleWriter; - - /** - * Construct a new ModuleSummaryBuilder. - * - * @param context the build context. - * @param mdle the module being documented. - * @param moduleWriter the doclet specific writer that will output the - * result. - */ - private ModuleSummaryBuilder(Context context, - ModuleElement mdle, ModuleSummaryWriter moduleWriter) { - super(context); - this.mdle = mdle; - this.moduleWriter = moduleWriter; - } - - /** - * Construct a new ModuleSummaryBuilder. - * - * @param context the build context. - * @param mdle the module being documented. - * @param moduleWriter the doclet specific writer that will output the - * result. - * - * @return an instance of a ModuleSummaryBuilder. - */ - public static ModuleSummaryBuilder getInstance(Context context, - ModuleElement mdle, ModuleSummaryWriter moduleWriter) { - return new ModuleSummaryBuilder(context, mdle, moduleWriter); - } - - /** - * Build the module summary. - * - * @throws DocletException if there is a problem while building the documentation - */ - @Override - public void build() throws DocletException { - if (moduleWriter == null) { - //Doclet does not support this output. - return; - } - buildModuleDoc(); - } - - /** - * Build the module documentation. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildModuleDoc() throws DocletException { - Content content = moduleWriter.getModuleHeader(mdle.getQualifiedName().toString()); - - buildContent(); - - moduleWriter.addModuleFooter(); - moduleWriter.printDocument(content); - DocFilesHandler docFilesHandler = configuration.getWriterFactory().getDocFilesHandler(mdle); - docFilesHandler.copyDocFiles(); - } - - /** - * Build the content for the module doc. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildContent() throws DocletException { - Content moduleContent = moduleWriter.getContentHeader(); - - moduleWriter.addModuleSignature(moduleContent); - buildModuleDescription(moduleContent); - buildSummary(moduleContent); - - moduleWriter.addModuleContent(moduleContent); - } - - /** - * Builds the list of summary sections for this module. - * - * @param target the module content to which the summaries will - * be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildSummary(Content target) throws DocletException { - Content summariesList = moduleWriter.getSummariesList(); - - buildPackagesSummary(summariesList); - buildModulesSummary(summariesList); - buildServicesSummary(summariesList); - - target.add(moduleWriter.getSummary(summariesList)); - } - - /** - * Builds the summary of the module dependencies of this module. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildModulesSummary(Content summariesList) { - moduleWriter.addModulesSummary(summariesList); - } - - /** - * Builds the summary of the packages exported or opened by this module. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildPackagesSummary(Content summariesList) { - moduleWriter.addPackagesSummary(summariesList); - } - - /** - * Builds the summary of the services used or provided by this module. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildServicesSummary(Content summariesList) { - moduleWriter.addServicesSummary(summariesList); - } - - /** - * Builds the description for this module. - * - * @param moduleContent the content to which the module description will - * be added - */ - protected void buildModuleDescription(Content moduleContent) { - if (!options.noComment()) { - moduleWriter.addModuleDescription(moduleContent); - } - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java deleted file mode 100644 index a56a4ec268d..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PackageSummaryBuilder.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import javax.lang.model.element.PackageElement; - -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter; - - -/** - * Builds the summary for a given package. - */ -public class PackageSummaryBuilder extends AbstractBuilder { - - /** - * The package being documented. - */ - private final PackageElement packageElement; - - /** - * The doclet specific writer that will output the result. - */ - private final PackageSummaryWriter packageWriter; - - /** - * Construct a new PackageSummaryBuilder. - * - * @param context the build context. - * @param pkg the package being documented. - * @param packageWriter the doclet specific writer that will output the - * result. - */ - private PackageSummaryBuilder(Context context, - PackageElement pkg, - PackageSummaryWriter packageWriter) { - super(context); - this.packageElement = pkg; - this.packageWriter = packageWriter; - } - - /** - * Construct a new PackageSummaryBuilder. - * - * @param context the build context. - * @param pkg the package being documented. - * @param packageWriter the doclet specific writer that will output the - * result. - * - * @return an instance of a PackageSummaryBuilder. - */ - public static PackageSummaryBuilder getInstance(Context context, - PackageElement pkg, PackageSummaryWriter packageWriter) { - return new PackageSummaryBuilder(context, pkg, packageWriter); - } - - /** - * Build the package summary. - * - * @throws DocletException if there is a problem while building the documentation - */ - @Override - public void build() throws DocletException { - if (packageWriter == null) { - //Doclet does not support this output. - return; - } - buildPackageDoc(); - } - - /** - * Build the package documentation. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildPackageDoc() throws DocletException { - Content content = packageWriter.getPackageHeader(); - - buildContent(); - - packageWriter.addPackageFooter(); - packageWriter.printDocument(content); - DocFilesHandler docFilesHandler = configuration - .getWriterFactory() - .getDocFilesHandler(packageElement); - docFilesHandler.copyDocFiles(); - } - - /** - * Build the content for the package. - * - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildContent() throws DocletException { - Content packageContent = packageWriter.getContentHeader(); - - packageWriter.addPackageSignature(packageContent); - buildPackageDescription(packageContent); - buildPackageTags(packageContent); - buildSummary(packageContent); - - packageWriter.addPackageContent(packageContent); - } - - /** - * Builds the list of summaries for the different kinds of types in this package. - * - * @param packageContent the package content to which the summaries will - * be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildSummary(Content packageContent) throws DocletException { - Content summariesList = packageWriter.getSummariesList(); - - buildRelatedPackagesSummary(summariesList); - buildAllClassesAndInterfacesSummary(summariesList); - - packageContent.add(packageWriter.getPackageSummary(summariesList)); - } - - /** - * Builds a list of "nearby" packages (subpackages, superpackages, and sibling packages). - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildRelatedPackagesSummary(Content summariesList) { - packageWriter.addRelatedPackagesSummary(summariesList); - } - - /** - * Builds the summary for all classes and interfaces in this package. - * - * @param summariesList the list of summaries to which the summary will be added - */ - protected void buildAllClassesAndInterfacesSummary(Content summariesList) { - packageWriter.addAllClassesAndInterfacesSummary(summariesList); - } - - - /** - * Build the description of the summary. - * - * @param packageContent the content to which the package description will - * be added - */ - protected void buildPackageDescription(Content packageContent) { - if (options.noComment()) { - return; - } - packageWriter.addPackageDescription(packageContent); - } - - /** - * Build the tags of the summary. - * - * @param packageContent the content to which the package tags will be added - */ - protected void buildPackageTags(Content packageContent) { - if (options.noComment()) { - return; - } - packageWriter.addPackageTags(packageContent); - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PropertyBuilder.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PropertyBuilder.java deleted file mode 100644 index 7d5600824b3..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/PropertyBuilder.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.javadoc.internal.doclets.toolkit.builders; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; - -import com.sun.source.doctree.DocCommentTree; -import com.sun.source.doctree.DocTree; -import jdk.javadoc.internal.doclets.toolkit.BaseOptions; -import jdk.javadoc.internal.doclets.toolkit.CommentUtils; -import jdk.javadoc.internal.doclets.toolkit.Content; -import jdk.javadoc.internal.doclets.toolkit.DocletException; -import jdk.javadoc.internal.doclets.toolkit.PropertyWriter; - -import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.PROPERTIES; - -/** - * Builds documentation for a property. - */ -public class PropertyBuilder extends AbstractMemberBuilder { - - /** - * The writer to output the property documentation. - */ - private final PropertyWriter writer; - - /** - * The list of properties being documented. - */ - private final List<? extends Element> properties; - - /** - * The index of the current property that is being documented at this point - * in time. - */ - private ExecutableElement currentProperty; - - /** - * Construct a new PropertyBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - */ - private PropertyBuilder(Context context, - TypeElement typeElement, - PropertyWriter writer) { - super(context, typeElement); - this.writer = Objects.requireNonNull(writer); - properties = getVisibleMembers(PROPERTIES); - } - - /** - * Construct a new PropertyBuilder. - * - * @param context the build context. - * @param typeElement the class whose members are being documented. - * @param writer the doclet specific writer. - * @return the new PropertyBuilder - */ - public static PropertyBuilder getInstance(Context context, - TypeElement typeElement, - PropertyWriter writer) { - return new PropertyBuilder(context, typeElement, writer); - } - - /** - * Returns whether or not there are members to document. - * - * @return whether or not there are members to document - */ - @Override - public boolean hasMembersToDocument() { - return !properties.isEmpty(); - } - - @Override - public void build(Content target) throws DocletException { - buildPropertyDoc(target); - } - - /** - * Build the property documentation. - * - * @param detailsList the content to which the documentation will be added - * @throws DocletException if there is a problem while building the documentation - */ - protected void buildPropertyDoc(Content detailsList) throws DocletException { - if (hasMembersToDocument()) { - Content propertyDetailsHeader = writer.getPropertyDetailsHeader(detailsList); - Content memberList = writer.getMemberList(); - - for (Element property : properties) { - currentProperty = (ExecutableElement)property; - Content propertyContent = writer.getPropertyHeaderContent(currentProperty); - - buildSignature(propertyContent); - buildPropertyComments(propertyContent); - buildTagInfo(propertyContent); - - memberList.add(writer.getMemberListItem(propertyContent)); - } - Content propertyDetails = writer.getPropertyDetails(propertyDetailsHeader, memberList); - detailsList.add(propertyDetails); - } - } - - /** - * Build the signature. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildSignature(Content propertyContent) { - propertyContent.add(writer.getSignature(currentProperty)); - } - - /** - * Build the deprecation information. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildDeprecationInfo(Content propertyContent) { - writer.addDeprecated(currentProperty, propertyContent); - } - - /** - * Build the preview information. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildPreviewInfo(Content propertyContent) { - writer.addPreview(currentProperty, propertyContent); - } - - /** - * Build the comments for the property. Do nothing if - * {@link BaseOptions#noComment()} is set to true. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildPropertyComments(Content propertyContent) { - if (!options.noComment()) { - writer.addComments(currentProperty, propertyContent); - } - } - - /** - * Build the tag information. - * - * @param propertyContent the content to which the documentation will be added - */ - protected void buildTagInfo(Content propertyContent) { - CommentUtils cmtUtils = configuration.cmtUtils; - DocCommentTree dct = utils.getDocCommentTree(currentProperty); - var fullBody = dct.getFullBody(); - ArrayList<DocTree> blockTags = dct.getBlockTags().stream() - .filter(t -> t.getKind() != DocTree.Kind.RETURN) - .collect(Collectors.toCollection(ArrayList::new)); - String sig = "#" + currentProperty.getSimpleName() + "()"; - blockTags.add(cmtUtils.makeSeeTree(sig, currentProperty)); - // The property method is used as a proxy for the property - // (which does not have an explicit element of its own.) - // Temporarily override the doc comment for the property method - // by removing the `@return` tag, which should not be displayed for - // the property. - CommentUtils.DocCommentInfo prev = cmtUtils.setDocCommentTree(currentProperty, fullBody, blockTags); - try { - writer.addTags(currentProperty, propertyContent); - } finally { - cmtUtils.setDocCommentInfo(currentProperty, prev); - } - } - - /** - * Return the property writer for this builder. - * - * @return the property writer for this builder. - */ - public PropertyWriter getWriter() { - return writer; - } -} diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/package-info.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/package-info.java deleted file mode 100644 index 6dd739b0bcd..00000000000 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/package-info.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -/** - * This doclet-independent package has a set of classes and - * interfaces that are the building blocks for doclets. They - * define the basic structure of doclets and make doclet - * writing much easier because they provide the content generation - * code to be shared among different doclets. Builders only provide - * the structure and content of API documentation. - * They do not directly provide any style markup. - */ -package jdk.javadoc.internal.doclets.toolkit.builders; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/package-info.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/package-info.java index 856bdd2eed9..4f5601b9600 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/package-info.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/package-info.java @@ -70,23 +70,11 @@ * to create trees (or acyclic graphs) of * {@linkplain jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree HTML tree nodes}. * Apart from using a common format-neutral supertype, - * {@link jdk.javadoc.internal.doclets.toolkit.Content}, the {@code markup} library + * {@link jdk.javadoc.internal.doclets.formats.html.Content}, the {@code markup} library * is mostly independent of the rest of the javadoc software stack. * * <dt id="toolkit">Toolkit * <dd><p> - * The {@link jdk.javadoc.internal.doclets.toolkit toolkit} package provides - * support for a format-neutral - * {@linkplain jdk.javadoc.internal.doclets.toolkit.AbstractDoclet abstract doclet}, - * which uses - * {@linkplain jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder builders} - * to generate pages of abstract - * {@linkplain jdk.javadoc.internal.doclets.toolkit.Content content}. - * - * <p>The format-specific content for each page is provided by implementations - * of various <em>writer</em> interfaces, created by a format-specific - * {@linkplain jdk.javadoc.internal.doclets.toolkit.WriterFactory writer factory}. - * * <p>The {@link jdk.javadoc.internal.doclets.toolkit.BaseConfiguration} provides * configuration information that is relevant to all the generated pages. * Some of the information is provided by abstract methods which are implemented diff --git a/test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java b/test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java index a7437bccd15..b40133d857b 100644 --- a/test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java +++ b/test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java @@ -212,8 +212,8 @@ public class TestMetadata extends JavadocTester { "AllClassesIndexWriter", "AllPackagesIndexWriter", "ClassUseWriter", - "ClassWriterImpl", - "ConstantsSummaryWriterImpl", + "ClassWriter", + "ConstantsSummaryWriter", "DeprecatedListWriter", "DocFileWriter", "ExternalSpecsWriter", @@ -221,13 +221,13 @@ public class TestMetadata extends JavadocTester { "IndexRedirectWriter", "IndexWriter", "ModuleIndexWriter", - "ModuleWriterImpl", + "ModuleWriter", "PackageIndexWriter", "PackageTreeWriter", "PackageUseWriter", - "PackageWriterImpl", + "PackageWriter", "SearchWriter", - "SerializedFormWriterImpl", + "SerializedFormWriter", "SourceToHTMLConverter", "SystemPropertiesWriter", "TreeWriter" @@ -321,10 +321,10 @@ public class TestMetadata extends JavadocTester { break; - case "AnnotationTypeWriterImpl": - case "ClassWriterImpl": - case "ModuleWriterImpl": - case "PackageWriterImpl": + case "AnnotationTypeWriter": + case "ClassWriter": + case "ModuleWriter": + case "PackageWriter": check(generator, content, content.startsWith("declaration: ")); break; @@ -333,7 +333,7 @@ public class TestMetadata extends JavadocTester { check(generator, content, content.startsWith("use: ")); break; - case "ConstantsSummaryWriterImpl": + case "ConstantsSummaryWriter": check(generator, content, content.contains("constants")); break; @@ -370,7 +370,7 @@ public class TestMetadata extends JavadocTester { check(generator, content, content.contains("search")); break; - case "SerializedFormWriterImpl": + case "SerializedFormWriter": check(generator, content, content.contains("serialized")); break;