8242056: Merge support for AnnotationType builders/writers into support for other types

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2020-04-07 09:50:36 -07:00
parent cceee2c638
commit 8523e37f7e
22 changed files with 197 additions and 1474 deletions

@ -626,21 +626,16 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe
set.remove(STRICTFP);
// According to JLS, we should not be showing public modifier for
// interface methods.
if ((utils.isField(element) || utils.isMethod(element))
&& ((writer instanceof ClassWriterImpl
&& utils.isInterface(((ClassWriterImpl) writer).getTypeElement()) ||
writer instanceof AnnotationTypeWriterImpl) )) {
// Remove the implicit abstract and public modifiers
if (utils.isMethod(element) &&
(utils.isInterface(element.getEnclosingElement()) ||
utils.isAnnotationType(element.getEnclosingElement()))) {
set.remove(ABSTRACT);
set.remove(PUBLIC);
}
if (!utils.isMethod(element)) {
set.remove(PUBLIC);
}
// interface methods and fields.
if ((utils.isField(element) || utils.isMethod(element))) {
Element te = element.getEnclosingElement();
if (utils.isInterface(te) || utils.isAnnotationType(te)) {
// Remove the implicit abstract and public modifiers
if (utils.isMethod(element)) {
set.remove(ABSTRACT);
}
set.remove(PUBLIC);
}
}
if (!set.isEmpty()) {
String mods = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));

@ -1,207 +0,0 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
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.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
/**
* Writes annotation type field documentation in HTML format.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
implements AnnotationTypeFieldWriter, MemberSummaryWriter {
/**
* Construct a new AnnotationTypeFieldWriterImpl.
*
* @param writer the writer that will write the output.
* @param annotationType the AnnotationType that holds this member.
*/
public AnnotationTypeFieldWriterImpl(SubWriterHolderWriter writer,
TypeElement annotationType) {
super(writer, annotationType);
}
@Override
public Content getMemberSummaryHeader(TypeElement typeElement,
Content memberSummaryTree) {
memberSummaryTree.add(
MarkerComments.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY);
Content memberTree = new ContentBuilder();
writer.addSummaryHeader(this, memberTree);
return memberTree;
}
@Override
public Content getMemberTreeHeader() {
return writer.getMemberTreeHeader();
}
@Override
public void addMemberTree(Content memberSummaryTree, Content memberTree) {
writer.addMemberTree(HtmlStyle.fieldSummary,
SectionName.ANNOTATION_TYPE_FIELD_SUMMARY, memberSummaryTree, memberTree);
}
@Override
public void addAnnotationFieldDetailsMarker(Content memberDetails) {
memberDetails.add(MarkerComments.START_OF_ANNOTATION_TYPE_FIELD_DETAILS);
}
@Override
public Content getAnnotationDetailsTreeHeader() {
Content memberDetailsTree = new ContentBuilder();
if (!writer.printedAnnotationFieldHeading) {
Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
contents.fieldDetailsLabel);
memberDetailsTree.add(heading);
writer.printedAnnotationFieldHeading = true;
}
return memberDetailsTree;
}
@Override
public Content getAnnotationDocTreeHeader(Element member) {
Content annotationDocTree = new ContentBuilder();
Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING,
new StringContent(name(member)));
annotationDocTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree).setId(name(member));
}
@Override
public Content getSignature(Element member) {
return new MemberSignature(member)
.addType(getType(member))
.toContent();
}
@Override
public void addDeprecated(Element member, Content annotationDocTree) {
addDeprecatedInfo(member, annotationDocTree);
}
@Override
public void addComments(Element member, Content annotationDocTree) {
addComment(member, annotationDocTree);
}
@Override
public void addTags(Element member, Content annotationDocTree) {
writer.addTagsInfo(member, annotationDocTree);
}
@Override
public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) {
Content annotationDetails = new ContentBuilder();
annotationDetails.add(annotationDetailsTreeHeader);
annotationDetails.add(annotationDetailsTree);
return getMemberTree(HtmlTree.SECTION(HtmlStyle.fieldDetails, annotationDetails)
.setId(SectionName.ANNOTATION_TYPE_FIELD_DETAIL.getName()));
}
@Override
public void addSummaryLabel(Content memberTree) {
HtmlTree label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
contents.fieldSummaryLabel);
memberTree.add(label);
}
@Override
public TableHeader getSummaryTableHeader(Element member) {
return new TableHeader(contents.modifierAndTypeLabel, contents.fields,
contents.descriptionLabel);
}
@Override
protected Table createSummaryTable() {
Content caption = contents.getContent("doclet.Fields");
TableHeader header = new TableHeader(contents.modifierAndTypeLabel, contents.fields,
contents.descriptionLabel);
return new Table(HtmlStyle.memberSummary)
.setCaption(caption)
.setHeader(header)
.setRowScopeColumn(1)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast);
}
@Override
public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
}
@Override
protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
Content tdSummary) {
Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
writer.getDocLink(context, member, name(member), false));
Content code = HtmlTree.CODE(memberLink);
tdSummary.add(code);
}
@Override
protected void addInheritedSummaryLink(TypeElement typeElement,
Element member, Content linksTree) {
//Not applicable.
}
@Override
protected void addSummaryType(Element member, Content tdSummaryType) {
addModifierAndType(member, getType(member), tdSummaryType);
}
@Override
protected Content getDeprecatedLink(Element member) {
return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
member, utils.getFullyQualifiedName(member));
}
private TypeMirror getType(Element member) {
if (utils.isConstructor(member))
return null;
if (utils.isExecutableElement(member))
return utils.getReturnType(typeElement, (ExecutableElement)member);
return member.asType();
}
}

@ -1,223 +0,0 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.List;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
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.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.StringContent;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
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;
/**
* Generate the Class Information Page.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*
* @see java.util.Collections
* @see java.util.List
* @see java.util.ArrayList
* @see java.util.HashMap
*/
public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
implements AnnotationTypeWriter {
protected TypeElement annotationType;
private final Navigation navBar;
/**
* @param configuration the configuration
* @param annotationType the annotation type being documented.
*/
public AnnotationTypeWriterImpl(HtmlConfiguration configuration,
TypeElement annotationType) {
super(configuration, configuration.docPaths.forClass(annotationType));
this.annotationType = annotationType;
configuration.currentTypeElement = annotationType;
this.navBar = new Navigation(annotationType, configuration, PageMode.CLASS, path);
}
@Override
public Content getHeader(String header) {
Content headerContent = new ContentBuilder();
addTop(headerContent);
Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(annotationType),
contents.moduleLabel);
navBar.setNavLinkModule(linkContent);
navBar.setMemberSummaryBuilder(configuration.getBuilderFactory().getMemberSummaryBuilder(this));
navBar.setUserHeader(getUserHeaderFooter(true));
headerContent.add(navBar.getContent(Navigation.Position.TOP));
HtmlTree div = new HtmlTree(TagName.DIV);
div.setStyle(HtmlStyle.header);
if (configuration.showModules) {
ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(annotationType);
Content typeModuleLabel = HtmlTree.SPAN(HtmlStyle.moduleLabelInType, contents.moduleLabel);
Content moduleNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, typeModuleLabel);
moduleNameDiv.add(Entity.NO_BREAK_SPACE);
moduleNameDiv.add(getModuleLink(mdle, new StringContent(mdle.getQualifiedName())));
div.add(moduleNameDiv);
}
PackageElement pkg = utils.containingPackage(annotationType);
if (!pkg.isUnnamed()) {
Content typePackageLabel = HtmlTree.SPAN(HtmlStyle.packageLabelInType, contents.packageLabel);
Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, typePackageLabel);
pkgNameDiv.add(Entity.NO_BREAK_SPACE);
Content pkgNameContent = getPackageLink(pkg, new StringContent(utils.getPackageName(pkg)));
pkgNameDiv.add(pkgNameContent);
div.add(pkgNameDiv);
}
LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_HEADER, annotationType);
Content heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, new StringContent(header));
heading.add(getTypeParameterLinks(linkInfo));
div.add(heading);
bodyContents.setHeader(headerContent)
.addMainContent(MarkerComments.START_OF_CLASS_DATA)
.addMainContent(div);
return getBody(getWindowTitle(utils.getSimpleName(annotationType)));
}
@Override
public Content getAnnotationContentHeader() {
return getContentHeader();
}
@Override
public void addFooter() {
Content htmlTree = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
htmlTree.add(navBar.getContent(Navigation.Position.BOTTOM));
addBottom(htmlTree);
bodyContents.addMainContent(MarkerComments.END_OF_CLASS_DATA)
.setFooter(htmlTree);
}
@Override
public void printDocument(Content contentTree) throws DocFileIOException {
String description = getDescription("declaration", annotationType);
PackageElement pkg = utils.containingPackage(this.annotationType);
List<DocPath> localStylesheets = getLocalStylesheets(pkg);
contentTree.add(bodyContents);
printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
description, localStylesheets, contentTree);
}
@Override
public Content getAnnotationInfoTreeHeader() {
return getMemberTreeHeader();
}
@Override
public Content getAnnotationInfo(Content annotationInfoTree) {
return HtmlTree.SECTION(HtmlStyle.description, annotationInfoTree);
}
@Override
public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) {
Content hr = new HtmlTree(TagName.HR);
annotationInfoTree.add(hr);
Content pre = new HtmlTree(TagName.PRE);
addAnnotationInfo(annotationType, pre);
pre.add(modifiers);
LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_SIGNATURE, annotationType);
Content annotationName = new StringContent(utils.getSimpleName(annotationType));
Content parameterLinks = getTypeParameterLinks(linkInfo);
if (options.linkSource()) {
addSrcLink(annotationType, annotationName, pre);
pre.add(parameterLinks);
} else {
Content span = HtmlTree.SPAN(HtmlStyle.memberNameLabel, annotationName);
span.add(parameterLinks);
pre.add(span);
}
annotationInfoTree.add(pre);
}
@Override
public void addAnnotationTypeDescription(Content annotationInfoTree) {
if (!options.noComment()) {
if (!utils.getFullBody(annotationType).isEmpty()) {
addInlineComment(annotationType, annotationInfoTree);
}
}
}
@Override
public void addAnnotationTypeTagInfo(Content annotationInfoTree) {
if (!options.noComment()) {
addTagsInfo(annotationType, annotationInfoTree);
}
}
@Override
public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) {
List<? extends DocTree> deprs = utils.getBlockTags(annotationType, DocTree.Kind.DEPRECATED);
if (utils.isDeprecated(annotationType)) {
CommentHelper ch = utils.getCommentHelper(annotationType);
Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(annotationType));
Content div = HtmlTree.DIV(HtmlStyle.deprecationBlock, deprLabel);
if (!deprs.isEmpty()) {
List<? extends DocTree> commentTags = ch.getDescription(deprs.get(0));
if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(annotationType, deprs.get(0), div);
}
}
annotationInfoTree.add(div);
}
}
@Override
public TypeElement getAnnotationTypeElement() {
return annotationType;
}
@Override
public Content getMemberDetailsTree(Content contentTree) {
return HtmlTree.SECTION(HtmlStyle.details, contentTree)
.setId(SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL.getName());
}
}

@ -214,36 +214,38 @@ public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWrite
if (utils.isRecord(typeElement)) {
pre.add(getRecordComponents(typeElement));
}
if (!utils.isInterface(typeElement)) {
TypeMirror superclass = utils.getFirstVisibleSuperClass(typeElement);
if (superclass != null) {
pre.add(DocletConstants.NL);
pre.add("extends ");
Content link = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
superclass));
pre.add(link);
}
}
List<? extends TypeMirror> interfaces = typeElement.getInterfaces();
if (!interfaces.isEmpty()) {
boolean isFirst = true;
for (TypeMirror type : interfaces) {
TypeElement tDoc = utils.asTypeElement(type);
if (!(utils.isPublic(tDoc) || utils.isLinkable(tDoc))) {
continue;
}
if (isFirst) {
if (!utils.isAnnotationType(typeElement)) {
if (!utils.isInterface(typeElement)) {
TypeMirror superclass = utils.getFirstVisibleSuperClass(typeElement);
if (superclass != null) {
pre.add(DocletConstants.NL);
pre.add(utils.isInterface(typeElement) ? "extends " : "implements ");
isFirst = false;
} else {
pre.add(", ");
pre.add("extends ");
Content link = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
superclass));
pre.add(link);
}
}
List<? extends TypeMirror> interfaces = typeElement.getInterfaces();
if (!interfaces.isEmpty()) {
boolean isFirst = true;
for (TypeMirror type : interfaces) {
TypeElement tDoc = utils.asTypeElement(type);
if (!(utils.isPublic(tDoc) || utils.isLinkable(tDoc))) {
continue;
}
if (isFirst) {
pre.add(DocletConstants.NL);
pre.add(utils.isInterface(typeElement) ? "extends " : "implements ");
isFirst = false;
} else {
pre.add(", ");
}
Content link = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
type));
pre.add(link);
}
Content link = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
type));
pre.add(link);
}
}
classInfoTree.add(pre);
@ -534,4 +536,19 @@ public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWrite
public TypeElement getTypeElement() {
return typeElement;
}
/**
* Get the member details tree
*
* @param contentTree the tree used to generate the member details tree
* @return a content tree for the member details
*/
public Content getMemberDetailsTree(Content contentTree) {
HtmlTree section = HtmlTree.SECTION(HtmlStyle.details, contentTree);
// The following id is required by the Navigation bar
if (utils.isAnnotationType(typeElement)) {
section.setId(SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL.getName());
}
return section;
}
}

@ -38,6 +38,7 @@ 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.DocFile;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
@ -244,21 +245,13 @@ 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;
}
if (utils.isAnnotationType(te)) {
AbstractBuilder annotationTypeBuilder =
configuration.getBuilderFactory()
.getAnnotationTypeBuilder(te);
annotationTypeBuilder.build();
} else {
AbstractBuilder classBuilder =
configuration.getBuilderFactory().getClassBuilder(te, classTree);
classBuilder.build();
}
f.getClassBuilder(te, classTree).build();
}
}

@ -87,7 +87,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
import jdk.javadoc.internal.doclets.formats.html.markup.Script;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.Messages;
@ -1608,8 +1607,7 @@ public class HtmlDocletWriter {
* @return Return true if a relative link should not be redirected.
*/
private boolean shouldNotRedirectRelativeLinks() {
return this instanceof AnnotationTypeWriter ||
this instanceof ClassWriter ||
return this instanceof ClassWriter ||
this instanceof PackageSummaryWriter;
}

@ -366,7 +366,7 @@ public class Navigation {
case CLASS:
if (element.getKind() == ElementKind.ANNOTATION_TYPE) {
addAnnotationTypeSummaryLink("doclet.navField",
ANNOTATION_TYPE_FIELDS, listContents);
FIELDS, listContents);
addAnnotationTypeSummaryLink("doclet.navAnnotationTypeRequiredMember",
ANNOTATION_TYPE_MEMBER_REQUIRED, listContents);
addAnnotationTypeSummaryLink("doclet.navAnnotationTypeOptionalMember",
@ -565,9 +565,9 @@ public class Navigation {
} else {
boolean link = memberSummaryBuilder.getVisibleMemberTable().hasVisibleMembers(kind);
switch (kind) {
case ANNOTATION_TYPE_FIELDS:
case FIELDS:
if (link) {
addContentToList(listContents, links.createLink(SectionName.ANNOTATION_TYPE_FIELD_SUMMARY,
addContentToList(listContents, links.createLink(SectionName.FIELD_SUMMARY,
contents.navField));
} else {
addContentToList(listContents, contents.navField);
@ -697,7 +697,7 @@ public class Navigation {
TypeElement annotationType = (TypeElement) element;
AbstractMemberWriter writerField
= ((AbstractMemberWriter) memberSummaryBuilder.
getMemberSummaryWriter(ANNOTATION_TYPE_FIELDS));
getMemberSummaryWriter(FIELDS));
AbstractMemberWriter writerOptional
= ((AbstractMemberWriter) memberSummaryBuilder.
getMemberSummaryWriter(ANNOTATION_TYPE_MEMBER_OPTIONAL));
@ -705,8 +705,8 @@ public class Navigation {
= ((AbstractMemberWriter) memberSummaryBuilder.
getMemberSummaryWriter(ANNOTATION_TYPE_MEMBER_REQUIRED));
if (writerField != null) {
addAnnotationTypeDetailLink(ANNOTATION_TYPE_FIELDS,
!configuration.utils.getAnnotationFields(annotationType).isEmpty(),
addAnnotationTypeDetailLink(FIELDS,
!configuration.utils.getFields(annotationType).isEmpty(),
listContents);
} else {
addContentToList(listContents, contents.navField);
@ -731,9 +731,9 @@ public class Navigation {
*/
protected void addAnnotationTypeDetailLink(VisibleMemberTable.Kind type, boolean link, List<Content> listContents) {
switch (type) {
case ANNOTATION_TYPE_FIELDS:
case FIELDS:
if (link) {
addContentToList(listContents, links.createLink(SectionName.ANNOTATION_TYPE_FIELD_DETAIL,
addContentToList(listContents, links.createLink(SectionName.FIELD_DETAIL,
contents.navField));
} else {
addContentToList(listContents, contents.navField);

@ -36,8 +36,6 @@ package jdk.javadoc.internal.doclets.formats.html;
public enum SectionName {
ANNOTATION_TYPE_ELEMENT_DETAIL("annotation.type.element.detail"),
ANNOTATION_TYPE_FIELD_DETAIL("annotation.type.field.detail"),
ANNOTATION_TYPE_FIELD_SUMMARY("annotation.type.field.summary"),
ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY("annotation.type.optional.element.summary"),
ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY("annotation.type.required.element.summary"),
CONSTRUCTOR_DETAIL("constructor.detail"),

@ -31,10 +31,8 @@ import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter;
import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
@ -81,33 +79,20 @@ public class WriterFactoryImpl implements WriterFactory {
return new ClassWriterImpl(configuration, typeElement, classTree);
}
@Override
public AnnotationTypeWriter getAnnotationTypeWriter(TypeElement annotationType) {
return new AnnotationTypeWriterImpl(configuration, annotationType);
}
@Override
public AnnotationTypeFieldWriter getAnnotationTypeFieldWriter(
AnnotationTypeWriter annotationTypeWriter) {
TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
return new AnnotationTypeFieldWriterImpl(
(SubWriterHolderWriter) annotationTypeWriter, te);
}
@Override
public AnnotationTypeOptionalMemberWriter getAnnotationTypeOptionalMemberWriter(
AnnotationTypeWriter annotationTypeWriter) {
TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
ClassWriter classWriter) {
TypeElement te = classWriter.getTypeElement();
return new AnnotationTypeOptionalMemberWriterImpl(
(SubWriterHolderWriter) annotationTypeWriter, te);
(ClassWriterImpl) classWriter, te);
}
@Override
public AnnotationTypeRequiredMemberWriter getAnnotationTypeRequiredMemberWriter(
AnnotationTypeWriter annotationTypeWriter) {
TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
ClassWriter classWriter) {
TypeElement te = classWriter.getTypeElement();
return new AnnotationTypeRequiredMemberWriterImpl(
(SubWriterHolderWriter) annotationTypeWriter, te);
(ClassWriterImpl) classWriter, te);
}
@Override
@ -146,6 +131,12 @@ public class WriterFactoryImpl implements WriterFactory {
return getConstructorWriter(classWriter);
case ENUM_CONSTANTS:
return getEnumConstantWriter(classWriter);
case ANNOTATION_TYPE_MEMBER_OPTIONAL:
return (AnnotationTypeOptionalMemberWriterImpl)
getAnnotationTypeOptionalMemberWriter(classWriter);
case ANNOTATION_TYPE_MEMBER_REQUIRED:
return (AnnotationTypeRequiredMemberWriterImpl)
getAnnotationTypeRequiredMemberWriter(classWriter);
case FIELDS:
return getFieldWriter(classWriter);
case PROPERTIES:
@ -160,24 +151,6 @@ public class WriterFactoryImpl implements WriterFactory {
}
}
@Override
public MemberSummaryWriter getMemberSummaryWriter(AnnotationTypeWriter annotationTypeWriter,
VisibleMemberTable.Kind memberType) {
switch (memberType) {
case ANNOTATION_TYPE_FIELDS:
return (AnnotationTypeFieldWriterImpl)
getAnnotationTypeFieldWriter(annotationTypeWriter);
case ANNOTATION_TYPE_MEMBER_OPTIONAL:
return (AnnotationTypeOptionalMemberWriterImpl)
getAnnotationTypeOptionalMemberWriter(annotationTypeWriter);
case ANNOTATION_TYPE_MEMBER_REQUIRED:
return (AnnotationTypeRequiredMemberWriterImpl)
getAnnotationTypeRequiredMemberWriter(annotationTypeWriter);
default:
return null;
}
}
@Override
public SerializedFormWriter getSerializedFormWriter() {
return new SerializedFormWriterImpl(configuration);

@ -1,111 +0,0 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.TypeElement;
/**
* The interface for writing annotation type field output.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public interface AnnotationTypeFieldWriter extends MemberWriter {
/**
* Add the annotation type member tree header.
*
* @return content tree for the member tree header
*/
Content getMemberTreeHeader();
/**
* Add the annotation type field details marker.
*
* @param memberDetails the content tree representing field details marker
*/
void addAnnotationFieldDetailsMarker(Content memberDetails);
/**
* Add the annotation type details tree header.
*
* @return content tree for the annotation details header
*/
Content getAnnotationDetailsTreeHeader();
/**
* Get the annotation type documentation tree header.
*
* @param member the annotation type being documented
* @return content tree for the annotation type documentation header
*/
Content getAnnotationDocTreeHeader(Element member);
/**
* Get the annotation type details tree.
*
* @param annotationDetailsTreeHeader the content tree representing annotation type details header
* @param annotationDetailsTree the content tree representing annotation type details
* @return content tree for the annotation type details
*/
Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree);
/**
* Get the signature for the given member.
*
* @param member the member being documented
* @return content tree for the annotation type signature
*/
Content getSignature(Element member);
/**
* Add the deprecated output for the given member.
*
* @param member the member being documented
* @param annotationDocTree content tree to which the deprecated information will be added
*/
void addDeprecated(Element member, Content annotationDocTree);
/**
* Add the comments for the given member.
*
* @param member the member being documented
* @param annotationDocTree the content tree to which the comments will be added
*/
void addComments(Element member, Content annotationDocTree);
/**
* Add the tags for the given member.
*
* @param member the member being documented
* @param annotationDocTree the content tree to which the tags will be added
*/
void addTags(Element member, Content annotationDocTree);
}

@ -1,159 +0,0 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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 annotation type output.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public interface AnnotationTypeWriter {
/**
* Get the header of the page.
*
* @param header the header string to write
* @return a content tree for the header documentation
*/
Content getHeader(String header);
/**
* Get the annotation content header.
*
* @return annotation content header that needs to be added to the documentation
*/
Content getAnnotationContentHeader();
/**
* Get the annotation information tree header.
*
* @return annotation information tree header that needs to be added to the documentation
*/
Content getAnnotationInfoTreeHeader();
/**
* Get the annotation information.
*
* @param annotationInfoTree content tree containing the annotation information
* @return a content tree for the annotation
*/
Content getAnnotationInfo(Content annotationInfoTree);
/**
* Add the signature of the current annotation type.
*
* @param modifiers the modifiers for the signature
* @param annotationInfoTree the annotation content tree to which the signature will be added
*/
void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree);
/**
* Build the annotation type description.
*
* @param annotationInfoTree content tree to which the description will be added
*/
void addAnnotationTypeDescription(Content annotationInfoTree);
/**
* Add the tag information for the current annotation type.
*
* @param annotationInfoTree content tree to which the tag information will be added
*/
void addAnnotationTypeTagInfo(Content annotationInfoTree);
/**
* If this annotation is deprecated, add the appropriate information.
*
* @param annotationInfoTree content tree to which the deprecated information will be added
*/
void addAnnotationTypeDeprecationInfo(Content annotationInfoTree);
/**
* Get the member tree header for the annotation type.
*
* @return a content tree for the member tree header
*/
Content getMemberTreeHeader();
/**
* Add the annotation content tree to the documentation content tree.
*
* @param annotationContentTree annotation content tree which will be added to the content tree
*/
void addAnnotationContentTree(Content annotationContentTree);
/**
* Get the member tree.
*
* @param memberTree the content tree that will be modified and returned
* @return a content tree for the member
*/
Content getMemberTree(Content memberTree);
/**
* Get the member summary tree.
*
* @param memberTree the content tree that will be used to build the summary tree
* @return a content tree for the member summary
*/
Content getMemberSummaryTree(Content memberTree);
/**
* Get the member details tree.
*
* @param memberTree the content tree that will be used to build the details tree
* @return a content tree for the member details
*/
Content getMemberDetailsTree(Content memberTree);
/**
* Add the footer of the page.
*/
void addFooter();
/**
* Print the document.
*
* @param contentTree content tree that will be printed as a document
* @throws DocFileIOException if there is a problem while writing the document
*/
void printDocument(Content contentTree) throws DocFileIOException;
/**
* Return the {@link TypeElement} being documented.
*
* @return the TypeElement representing the annotation being documented.
*/
TypeElement getAnnotationTypeElement();
}

@ -71,143 +71,106 @@ public interface WriterFactory {
ModuleSummaryWriter getModuleSummaryWriter(ModuleElement mdle);
/**
* Return the writer for a class.
* 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 for the class. Return 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 writer for an annotation type.
* Return the method writer for a given type element,
* or null if this writer is not supported by the doclet.
*
* @param annotationType the type being documented.
* @return the writer for the annotation type. Return null if this
* writer is not supported by the doclet.
*/
AnnotationTypeWriter getAnnotationTypeWriter(TypeElement annotationType);
/**
* Return the method writer for a given class.
*
* @param classWriter the writer for the class being documented.
* @return the method writer for the give class. Return 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 field writer for a given annotation type.
*
* @param annotationTypeWriter the writer for the annotation type
* being documented.
* @return the member writer for the given annotation type. Return null if
* this writer is not supported by the doclet.
*/
AnnotationTypeFieldWriter getAnnotationTypeFieldWriter(
AnnotationTypeWriter annotationTypeWriter);
/**
* Return the annotation type optional member writer for a given annotation
* type.
* type, or null if this writer is not supported by the doclet.
*
* @param annotationTypeWriter the writer for the annotation type
* being documented.
* @return the member writer for the given annotation type. Return null if
* this writer is not supported by the doclet.
* @param classWriter the writer for the annotation type being documented
* @return the member writer
*/
AnnotationTypeOptionalMemberWriter getAnnotationTypeOptionalMemberWriter(
AnnotationTypeWriter annotationTypeWriter);
ClassWriter classWriter);
/**
* Return the annotation type required member writer for a given annotation type.
* Return the annotation type required member writer for a given annotation
* type, or null if this writer is not supported by the doclet.
*
* @param annotationTypeWriter the writer for the annotation type
* being documented.
* @return the member writer for the given annotation type. Return null if
* this writer is not supported by the doclet.
* @param classWriter the writer for the annotation type being documented
* @return the member writer
*/
AnnotationTypeRequiredMemberWriter getAnnotationTypeRequiredMemberWriter(
AnnotationTypeWriter annotationTypeWriter);
ClassWriter classWriter);
/**
* Return the enum constant writer for a given class.
* 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 class being documented.
* @return the enum constant writer for the give class. Return 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 class.
* 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 give class. Return null if this
* @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.
* 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 class being documented.
* @return the property writer for the give class. Return null if this
* writer is not supported by the doclet.
* @param classWriter the writer for the type elemen t being documented.
* @return the property writer
*/
PropertyWriter getPropertyWriter(ClassWriter classWriter);
/**
* Return the constructor writer for a given class.
* 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 class being documented.
* @return the method writer for the give class. Return 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 class.
* 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 for the give class. Return null if this
* writer is not supported by the doclet.
* @return the summary writer
*
* @see VisibleMemberTable
*/
MemberSummaryWriter getMemberSummaryWriter(ClassWriter classWriter,
VisibleMemberTable.Kind memberType);
/**
* Return the specified member summary writer for a given annotation type.
*
* @param annotationTypeWriter the writer for the annotation type being
* documented.
* @param memberType the {@link VisibleMemberTable} member type indicating
* the type of member summary that should be returned.
* @return the summary writer for the give class. Return null if this
* writer is not supported by the doclet.
*
* @see VisibleMemberTable
*/
MemberSummaryWriter getMemberSummaryWriter(AnnotationTypeWriter annotationTypeWriter,
VisibleMemberTable.Kind memberType);
/**
* Return the writer for the serialized form.
*
* @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.
* @return the handler for the doc files
*/
DocFilesHandler getDocFilesHandler(Element pkg);
}

@ -1,250 +0,0 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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 javax.lang.model.element.TypeElement;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
import jdk.javadoc.internal.doclets.toolkit.DocletException;
/**
* Builds the summary for a given annotation type.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class AnnotationTypeBuilder extends AbstractBuilder {
/**
* The annotation type being documented.
*/
private final TypeElement annotationType;
/**
* The doclet specific writer.
*/
private final AnnotationTypeWriter writer;
/**
* Construct a new ClassBuilder.
*
* @param context the build context.
* @param annotationTypeElement the class being documented.
* @param writer the doclet specific writer.
*/
private AnnotationTypeBuilder(Context context,
TypeElement annotationTypeElement,
AnnotationTypeWriter writer) {
super(context);
this.annotationType = annotationTypeElement;
this.writer = writer;
}
/**
* Construct a new AnnotationTypeBuilder.
*
* @param context the build context.
* @param annotationTypeDoc the class being documented.
* @param writer the doclet specific writer.
* @return an AnnotationTypeBuilder
*/
public static AnnotationTypeBuilder getInstance(Context context,
TypeElement annotationTypeDoc,
AnnotationTypeWriter writer) {
return new AnnotationTypeBuilder(context, annotationTypeDoc, writer);
}
@Override
public void build() throws DocletException {
buildAnnotationTypeDoc();
}
/**
* Build the annotation type documentation.
*
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeDoc() throws DocletException {
Content contentTree = writer.getHeader(resources.getText("doclet.AnnotationType") +
" " + utils.getSimpleName(annotationType));
Content annotationContentTree = writer.getAnnotationContentHeader();
buildAnnotationTypeInfo(annotationContentTree);
buildMemberSummary(annotationContentTree);
buildAnnotationTypeMemberDetails(annotationContentTree);
writer.addAnnotationContentTree(annotationContentTree);
writer.addFooter();
writer.printDocument(contentTree);
copyDocFiles();
}
/**
* Copy the doc files for the current TypeElement if necessary.
*
* @throws DocletException if there is a problem building the documentation
*/
private void copyDocFiles() throws DocletException {
PackageElement containingPackage = utils.containingPackage(annotationType);
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 annotation information tree documentation.
*
* @param annotationContentTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeInfo(Content annotationContentTree)
throws DocletException {
Content annotationInfoTree = new ContentBuilder();
buildAnnotationTypeSignature(annotationInfoTree);
buildDeprecationInfo(annotationInfoTree);
buildAnnotationTypeDescription(annotationInfoTree);
buildAnnotationTypeTagInfo(annotationInfoTree);
annotationContentTree.add(writer.getAnnotationInfo(annotationInfoTree));
}
/**
* If this annotation is deprecated, build the appropriate information.
*
* @param annotationInfoTree the content tree to which the documentation will be added
*/
protected void buildDeprecationInfo(Content annotationInfoTree) {
writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
}
/**
* Build the signature of the current annotation type.
*
* @param annotationInfoTree the content tree to which the documentation will be added
*/
protected void buildAnnotationTypeSignature(Content annotationInfoTree) {
writer.addAnnotationTypeSignature(utils.modifiersToString(annotationType, true),
annotationInfoTree);
}
/**
* Build the annotation type description.
*
* @param annotationInfoTree the content tree to which the documentation will be added
*/
protected void buildAnnotationTypeDescription(Content annotationInfoTree) {
writer.addAnnotationTypeDescription(annotationInfoTree);
}
/**
* Build the tag information for the current annotation type.
*
* @param annotationInfoTree the content tree to which the documentation will be added
*/
protected void buildAnnotationTypeTagInfo(Content annotationInfoTree) {
writer.addAnnotationTypeTagInfo(annotationInfoTree);
}
/**
* Build the member summary contents of the page.
*
* @param annotationContentTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildMemberSummary(Content annotationContentTree) throws DocletException {
Content memberSummaryTree = writer.getMemberTreeHeader();
builderFactory.getMemberSummaryBuilder(writer).build(memberSummaryTree);
annotationContentTree.add(writer.getMemberSummaryTree(memberSummaryTree));
}
/**
* Build the member details contents of the page.
*
* @param annotationContentTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeMemberDetails(Content annotationContentTree)
throws DocletException {
Content memberDetailsTree = writer.getMemberTreeHeader();
buildAnnotationTypeFieldDetails(memberDetailsTree);
buildAnnotationTypeRequiredMemberDetails(memberDetailsTree);
buildAnnotationTypeOptionalMemberDetails(memberDetailsTree);
if (memberDetailsTree.isValid()) {
annotationContentTree.add(writer.getMemberDetailsTree(memberDetailsTree));
}
}
/**
* Build the annotation type field documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeFieldDetails(Content memberDetailsTree)
throws DocletException {
builderFactory.getAnnotationTypeFieldsBuilder(writer).build(memberDetailsTree);
}
/**
* Build the annotation type optional member documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeOptionalMemberDetails(Content memberDetailsTree)
throws DocletException {
builderFactory.getAnnotationTypeOptionalMemberBuilder(writer).build(memberDetailsTree);
}
/**
* Build the annotation type required member documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeRequiredMemberDetails(Content memberDetailsTree)
throws DocletException {
builderFactory.getAnnotationTypeRequiredMemberBuilder(writer).build(memberDetailsTree);
}
}

@ -1,203 +0,0 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.AnnotationTypeFieldWriter;
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.util.VisibleMemberTable;
/**
* Builds documentation for annotation type fields.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class AnnotationTypeFieldBuilder extends AbstractMemberBuilder {
/**
* The writer to output the member documentation.
*/
protected AnnotationTypeFieldWriter writer;
/**
* The list of members being documented.
*/
protected List<? extends Element> members;
/**
* The index of the current member that is being documented at this point
* in time.
*/
protected Element currentMember;
/**
* Construct a new AnnotationTypeFieldsBuilder.
*
* @param context the build context.
* @param typeElement the class whose members are being documented.
* @param writer the doclet specific writer.
* @param memberType the type of member that is being documented.
*/
protected AnnotationTypeFieldBuilder(Context context,
TypeElement typeElement,
AnnotationTypeFieldWriter writer,
VisibleMemberTable.Kind memberType) {
super(context, typeElement);
this.writer = writer;
this.members = getVisibleMembers(memberType);
}
/**
* Construct a new AnnotationTypeFieldBuilder.
*
* @param context the build context.
* @param typeElement the class whose members are being documented.
* @param writer the doclet specific writer.
* @return the new AnnotationTypeFieldBuilder
*/
public static AnnotationTypeFieldBuilder getInstance(
Context context, TypeElement typeElement,
AnnotationTypeFieldWriter writer) {
return new AnnotationTypeFieldBuilder(context, typeElement,
writer, VisibleMemberTable.Kind.ANNOTATION_TYPE_FIELDS);
}
/**
* 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 contentTree) throws DocletException {
buildAnnotationTypeField(contentTree);
}
/**
* Build the annotation type field documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem while building the documentation
*/
protected void buildAnnotationTypeField(Content memberDetailsTree)
throws DocletException {
buildAnnotationTypeMember(memberDetailsTree);
}
/**
* Build the member documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem while building the documentation
*/
protected void buildAnnotationTypeMember(Content memberDetailsTree)
throws DocletException {
if (writer == null) {
return;
}
if (hasMembersToDocument()) {
writer.addAnnotationFieldDetailsMarker(memberDetailsTree);
Content annotationDetailsTreeHeader = writer.getAnnotationDetailsTreeHeader();
Content memberList = writer.getMemberList();
for (Element member : members) {
currentMember = member;
Content annotationDocTree = writer.getAnnotationDocTreeHeader(currentMember);
buildSignature(annotationDocTree);
buildDeprecationInfo(annotationDocTree);
buildMemberComments(annotationDocTree);
buildTagInfo(annotationDocTree);
memberList.add(writer.getMemberListItem(annotationDocTree));
}
memberDetailsTree.add(writer.getAnnotationDetails(annotationDetailsTreeHeader, memberList));
}
}
/**
* Build the signature.
*
* @param annotationDocTree the content tree to which the documentation will be added
*/
protected void buildSignature(Content annotationDocTree) {
annotationDocTree.add(
writer.getSignature(currentMember));
}
/**
* Build the deprecation information.
*
* @param annotationDocTree the content tree to which the documentation will be added
*/
protected void buildDeprecationInfo(Content annotationDocTree) {
writer.addDeprecated(currentMember, annotationDocTree);
}
/**
* Build the comments for the member. Do nothing if
* {@link BaseOptions#noComment()} is set to true.
*
* @param annotationDocTree the content tree to which the documentation will be added
*/
protected void buildMemberComments(Content annotationDocTree) {
if (!options.noComment()) {
writer.addComments(currentMember, annotationDocTree);
}
}
/**
* Build the tag information.
*
* @param annotationDocTree the content tree to which the documentation will be added
*/
protected void buildTagInfo(Content annotationDocTree) {
writer.addTags(currentMember, annotationDocTree);
}
/**
* Return the annotation type field writer for this builder.
*
* @return the annotation type field writer for this builder.
*/
public AnnotationTypeFieldWriter getWriter() {
return writer;
}
}

@ -33,7 +33,6 @@ import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
import jdk.javadoc.internal.doclets.toolkit.PropertyWriter;
@ -117,18 +116,6 @@ public class BuilderFactory {
writerFactory.getClassWriter(typeElement, classTree));
}
/**
* Return the builder for the annotation type.
*
* @param annotationType the annotation type being documented.
* @return the writer for the annotation type. Return null if this
* writer is not supported by the doclet.
*/
public AbstractBuilder getAnnotationTypeBuilder(TypeElement annotationType) {
return AnnotationTypeBuilder.getInstance(context, annotationType,
writerFactory.getAnnotationTypeWriter(annotationType));
}
/**
* Return an instance of the method builder for the given class.
*
@ -140,49 +127,34 @@ public class BuilderFactory {
writerFactory.getMethodWriter(classWriter));
}
/**
* Return an instance of the annotation type fields builder for the given
* class.
*
* @param annotationTypeWriter the writer for the enclosing annotation type
* @return an instance of the annotation type field builder for the given
* annotation type.
*/
public AbstractMemberBuilder getAnnotationTypeFieldsBuilder(
AnnotationTypeWriter annotationTypeWriter) {
return AnnotationTypeFieldBuilder.getInstance(context,
annotationTypeWriter.getAnnotationTypeElement(),
writerFactory.getAnnotationTypeFieldWriter(annotationTypeWriter));
}
/**
* Return an instance of the annotation type member builder for the given
* class.
*
* @param annotationTypeWriter the writer for the enclosing annotation type
* @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 getAnnotationTypeOptionalMemberBuilder(
AnnotationTypeWriter annotationTypeWriter) {
ClassWriter classWriter) {
return AnnotationTypeOptionalMemberBuilder.getInstance(context,
annotationTypeWriter.getAnnotationTypeElement(),
writerFactory.getAnnotationTypeOptionalMemberWriter(annotationTypeWriter));
classWriter.getTypeElement(),
writerFactory.getAnnotationTypeOptionalMemberWriter(classWriter));
}
/**
* Return an instance of the annotation type member builder for the given
* class.
*
* @param annotationTypeWriter the writer for the enclosing annotation type
* @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 getAnnotationTypeRequiredMemberBuilder(
AnnotationTypeWriter annotationTypeWriter) {
ClassWriter classWriter) {
return AnnotationTypeRequiredMemberBuilder.getInstance(context,
annotationTypeWriter.getAnnotationTypeElement(),
writerFactory.getAnnotationTypeRequiredMemberWriter(annotationTypeWriter));
classWriter.getTypeElement(),
writerFactory.getAnnotationTypeRequiredMemberWriter(classWriter));
}
/**
@ -242,18 +214,6 @@ public class BuilderFactory {
return MemberSummaryBuilder.getInstance(classWriter, context);
}
/**
* Return an instance of the member summary builder for the given annotation
* type.
*
* @param annotationTypeWriter the writer for the enclosing annotation type
* @return an instance of the member summary builder for the given
* annotation type.
*/
public MemberSummaryBuilder getMemberSummaryBuilder(AnnotationTypeWriter annotationTypeWriter) {
return MemberSummaryBuilder.getInstance(annotationTypeWriter, context);
}
/**
* Return the builder that builds the serialized form.
*

@ -66,21 +66,6 @@ public class ClassBuilder extends AbstractBuilder {
*/
private final ClassWriter writer;
/**
* Keep track of whether or not this typeElement is an interface.
*/
private final boolean isInterface;
/**
* Keep track of whether or not this typeElement is an enum.
*/
private final boolean isEnum;
/**
* Keep track of whether or not this typeElement is a record.
*/
private final boolean isRecord;
/**
* The content tree for the class documentation.
*/
@ -100,24 +85,14 @@ public class ClassBuilder extends AbstractBuilder {
this.typeElement = typeElement;
this.writer = writer;
this.utils = configuration.utils;
if (utils.isInterface(typeElement)) {
isInterface = true;
isEnum = false;
isRecord = false;
} else if (utils.isEnum(typeElement)) {
isInterface = false;
isEnum = true;
isRecord = false;
setEnumDocumentation(typeElement);
} else if (utils.isRecord(typeElement)) {
isInterface = false;
isEnum = false;
isRecord = true;
setRecordDocumentation(typeElement);
} else {
isInterface = false;
isEnum = false;
isRecord = false;
switch (typeElement.getKind()) {
case ENUM:
setEnumDocumentation(typeElement);
break;
case RECORD:
setRecordDocumentation(typeElement);
break;
}
}
@ -145,15 +120,25 @@ public class ClassBuilder extends AbstractBuilder {
*/
protected void buildClassDoc() throws DocletException {
String key;
if (isInterface) {
key = "doclet.Interface";
} else if (isEnum) {
key = "doclet.Enum";
} else if (isRecord) {
key = "doclet.Record";
} else {
key = "doclet.Class";
}
switch (typeElement.getKind()) {
case INTERFACE:
key = "doclet.Interface";
break;
case ENUM:
key = "doclet.Enum";
break;
case RECORD:
key = "doclet.Record";
break;
case ANNOTATION_TYPE:
key = "doclet.AnnotationType";
break;
case CLASS:
key = "doclet.Class";
break;
default:
throw new IllegalStateException(typeElement.getKind() + " " + typeElement);
}
Content contentTree = writer.getHeader(resources.getText(key) + " "
+ utils.getSimpleName(typeElement));
Content classContentTree = writer.getClassContentHeader();
@ -356,6 +341,8 @@ public class ClassBuilder extends AbstractBuilder {
buildPropertyDetails(memberDetailsTree);
buildFieldDetails(memberDetailsTree);
buildConstructorDetails(memberDetailsTree);
buildAnnotationTypeRequiredMemberDetails(memberDetailsTree);
buildAnnotationTypeOptionalMemberDetails(memberDetailsTree);
buildMethodDetails(memberDetailsTree);
classContentTree.add(writer.getMemberDetailsTree(memberDetailsTree));
@ -411,6 +398,28 @@ public class ClassBuilder extends AbstractBuilder {
builderFactory.getMethodBuilder(writer).build(memberDetailsTree);
}
/**
* Build the annotation type optional member documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeOptionalMemberDetails(Content memberDetailsTree)
throws DocletException {
builderFactory.getAnnotationTypeOptionalMemberBuilder(writer).build(memberDetailsTree);
}
/**
* Build the annotation type required member documentation.
*
* @param memberDetailsTree the content tree to which the documentation will be added
* @throws DocletException if there is a problem building the documentation
*/
protected void buildAnnotationTypeRequiredMemberDetails(Content memberDetailsTree)
throws DocletException {
builderFactory.getAnnotationTypeRequiredMemberBuilder(writer).build(memberDetailsTree);
}
/**
* The documentation for values() and valueOf() in Enums are set by the
* doclet only iff the user or overridden methods are missing.

@ -39,7 +39,6 @@ import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.DocTree.Kind;
import com.sun.source.doctree.UnknownBlockTagTree;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
@ -105,6 +104,8 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
buildPropertiesSummary(contentTree);
buildNestedClassesSummary(contentTree);
buildEnumConstantsSummary(contentTree);
buildAnnotationTypeRequiredMemberSummary(contentTree);
buildAnnotationTypeOptionalMemberSummary(contentTree);
buildFieldsSummary(contentTree);
buildConstructorsSummary(contentTree);
buildMethodsSummary(contentTree);
@ -125,40 +126,6 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
return builder;
}
/**
* Construct a new MemberSummaryBuilder for an annotation type.
*
* @param annotationTypeWriter the writer for the class whose members are
* being summarized.
* @param context the build context.
* @return the instance
*/
public static MemberSummaryBuilder getInstance(
AnnotationTypeWriter annotationTypeWriter, Context context) {
MemberSummaryBuilder builder = new MemberSummaryBuilder(context,
annotationTypeWriter.getAnnotationTypeElement()) {
@Override
public void build(Content contentTree) {
buildAnnotationTypeFieldsSummary(contentTree);
buildAnnotationTypeRequiredMemberSummary(contentTree);
buildAnnotationTypeOptionalMemberSummary(contentTree);
}
@Override
public boolean hasMembersToDocument() {
return !utils.getAnnotationMembers(typeElement).isEmpty();
}
};
WriterFactory wf = context.configuration.getWriterFactory();
for (VisibleMemberTable.Kind kind : VisibleMemberTable.Kind.values()) {
MemberSummaryWriter msw = builder.getVisibleMemberTable().hasVisibleMembers(kind)
? wf.getMemberSummaryWriter(annotationTypeWriter, kind)
: null;
builder.memberSummaryWriters.put(kind, msw);
}
return builder;
}
/**
* Return the specified visible member map.
*
@ -222,8 +189,8 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
* @param memberSummaryTree the content tree to which the documentation will be added
*/
protected void buildAnnotationTypeFieldsSummary(Content memberSummaryTree) {
MemberSummaryWriter writer = memberSummaryWriters.get(ANNOTATION_TYPE_FIELDS);
addSummary(writer, ANNOTATION_TYPE_FIELDS, false, memberSummaryTree);
MemberSummaryWriter writer = memberSummaryWriters.get(FIELDS);
addSummary(writer, FIELDS, false, memberSummaryTree);
}
/**

@ -147,8 +147,9 @@ public class IndexBuilder {
*/
private void indexMembers(TypeElement te) {
VisibleMemberTable vmt = configuration.getVisibleMemberTable(te);
indexElements(vmt.getMembers(ANNOTATION_TYPE_FIELDS));
indexElements(vmt.getMembers(FIELDS));
indexElements(vmt.getMembers(ANNOTATION_TYPE_MEMBER_OPTIONAL));
indexElements(vmt.getMembers(ANNOTATION_TYPE_MEMBER_REQUIRED));
indexElements(vmt.getMembers(METHODS));
indexElements(vmt.getMembers(CONSTRUCTORS));
indexElements(vmt.getMembers(ENUM_CONSTANTS));

@ -94,7 +94,6 @@ public class VisibleMemberTable {
FIELDS,
CONSTRUCTORS,
METHODS,
ANNOTATION_TYPE_FIELDS,
ANNOTATION_TYPE_MEMBER_OPTIONAL,
ANNOTATION_TYPE_MEMBER_REQUIRED,
PROPERTIES;
@ -352,6 +351,11 @@ public class VisibleMemberTable {
}
private void computeParents() {
// suppress parents of annotation types
if (utils.isAnnotationType(te)) {
return;
}
for (TypeMirror intfType : te.getInterfaces()) {
TypeElement intfc = utils.asTypeElement(intfType);
if (intfc != null) {
@ -673,16 +677,16 @@ public class VisibleMemberTable {
break;
case FIELD:
addMember(e, Kind.FIELDS);
addMember(e, Kind.ANNOTATION_TYPE_FIELDS);
break;
case METHOD:
ExecutableElement ee = (ExecutableElement)e;
if (utils.isAnnotationType(te)) {
ExecutableElement ee = (ExecutableElement) e;
addMember(e, ee.getDefaultValue() == null
? Kind.ANNOTATION_TYPE_MEMBER_REQUIRED
: Kind.ANNOTATION_TYPE_MEMBER_OPTIONAL);
} else {
addMember(e, Kind.METHODS);
}
addMember(e, Kind.METHODS);
break;
case CONSTRUCTOR:
addMember(e, Kind.CONSTRUCTORS);

@ -24,6 +24,7 @@
/*
* @test
* @bug 4973609 8015249 8025633 8026567 6469561 8071982 8162363 8182765 8223364
8242056
* @summary Make sure that annotation types with 0 members does not have
* extra HR tags.
* @library ../../lib
@ -50,16 +51,14 @@ public class TestAnnotationTypes extends JavadocTester {
checkOutput("pkg/AnnotationTypeField.html", true,
"<li>Summary:&nbsp;</li>\n"
+ "<li><a href=\"#annotation.type."
+ "field.summary\">Field</a>&nbsp;|&nbsp;</li>",
+ "<li><a href=\"#field.summary\">Field</a>&nbsp;|&nbsp;</li>",
"<li>Detail:&nbsp;</li>\n"
+ "<li><a href=\"#annotation.type."
+ "field.detail\">Field</a>&nbsp;|&nbsp;</li>",
"<!-- =========== ANNOTATION TYPE FIELD SUMMARY =========== -->",
+ "<li><a href=\"#field.detail\">Field</a>&nbsp;|&nbsp;</li>",
"<!-- =========== FIELD SUMMARY =========== -->",
"<h2>Field Summary</h2>",
"<th class=\"col-second\" scope=\"row\"><code><span class=\"member-name-link\"><a href=\"#DEFAULT_NAME\">DEFAULT_NAME</a></span>"
+ "</code></th>",
"<!-- ============ ANNOTATION TYPE FIELD DETAIL =========== -->",
"<!-- ============ FIELD DETAIL =========== -->",
"<section class=\"detail\" id=\"DEFAULT_NAME\">\n"
+ "<h3>DEFAULT_NAME</h3>\n"
+ "<div class=\"member-signature\"><span class=\"modifiers\">static final</span>&nbsp;"

@ -97,7 +97,7 @@ public class TestDeprecatedDocs extends JavadocTester {
"<hr>\n"
+ "<pre>@Deprecated(forRemoval=true)\n"
+ "@Documented\n"
+ "public @interface <span class=\"member-name-label\">TestAnnotationType</span></pre>\n"
+ "public @interface <span class=\"type-name-label\">TestAnnotationType</span></pre>\n"
+ "<div class=\"deprecation-block\"><span class=\"deprecated-label\">Deprecated, for removal: This API element is subject to removal in a future version.</span>\n"
+ "<div class=\"deprecation-comment\">annotation_test1 passes.</div>\n"
+ "</div>",

@ -23,7 +23,7 @@
/*
* @test
* @bug 8218998 8219946 8219060 8241190
* @bug 8218998 8219946 8219060 8241190 8242056
* @summary Add metadata to generated API documentation files
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -206,7 +206,6 @@ public class TestMetadata extends JavadocTester {
final Set<String> allGenerators = Set.of(
"AllClassesIndexWriter",
"AllPackagesIndexWriter",
"AnnotationTypeWriterImpl",
"ClassUseWriter",
"ClassWriterImpl",
"ConstantsSummaryWriterImpl",