1 /* 2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.javadoc.internal.doclets.formats.html; 27 28 import javax.lang.model.element.Element; 29 import javax.lang.model.element.ExecutableElement; 30 import javax.lang.model.element.TypeElement; 31 import javax.lang.model.type.TypeMirror; 32 33 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 36 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 37 import jdk.javadoc.internal.doclets.formats.html.markup.Table; 38 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader; 39 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter; 40 import jdk.javadoc.internal.doclets.toolkit.Content; 41 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; 42 43 44 /** 45 * Writes annotation type required member documentation in HTML format. 46 * 47 * <p><b>This is NOT part of any supported API. 48 * If you write code that depends on this, you do so at your own risk. 49 * This code and its internal interfaces are subject to change or 50 * deletion without notice.</b> 51 */ 52 public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter 53 implements AnnotationTypeRequiredMemberWriter, MemberSummaryWriter { 54 55 /** 56 * Construct a new AnnotationTypeRequiredMemberWriterImpl. 57 * 58 * @param writer the writer that will write the output. 59 * @param annotationType the AnnotationType that holds this member. 60 */ 61 public AnnotationTypeRequiredMemberWriterImpl(SubWriterHolderWriter writer, 62 TypeElement annotationType) { 63 super(writer, annotationType); 64 } 65 66 /** 67 * {@inheritDoc} 68 */ 69 public Content getMemberSummaryHeader(TypeElement typeElement, 70 Content memberSummaryTree) { 71 memberSummaryTree.add( 72 MarkerComments.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY); 73 Content memberTree = new ContentBuilder(); 74 writer.addSummaryHeader(this, memberTree); 75 return memberTree; 76 } 77 78 /** 79 * {@inheritDoc} 80 */ 81 public Content getMemberTreeHeader() { 82 return writer.getMemberTreeHeader(); 83 } 84 85 /** 86 * {@inheritDoc} 87 */ 88 public void addMemberTree(Content memberSummaryTree, Content memberTree) { 89 writer.addMemberTree(HtmlStyle.memberSummary, 90 SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY, memberSummaryTree, memberTree); 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 public void addAnnotationDetailsMarker(Content memberDetails) { 97 memberDetails.add(MarkerComments.START_OF_ANNOTATION_TYPE_DETAILS); 98 } 99 100 /** 101 * {@inheritDoc} 102 */ 103 public Content getAnnotationDetailsTreeHeader() { 104 Content memberDetailsTree = new ContentBuilder(); 105 if (!writer.printedAnnotationHeading) { 106 Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, 107 contents.annotationTypeDetailsLabel); 108 memberDetailsTree.add(heading); 109 writer.printedAnnotationHeading = true; 110 } 111 return memberDetailsTree; 112 } 113 114 /** 115 * {@inheritDoc} 116 */ 117 @Override 118 public Content getAnnotationDocTreeHeader(Element member) { 119 String simpleName = name(member); 120 Content annotationDocTree = new ContentBuilder(); 121 Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING, 122 new StringContent(simpleName)); 123 annotationDocTree.add(heading); 124 return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree) 125 .setId(simpleName + utils.signature((ExecutableElement) member)); 126 } 127 128 /** 129 * {@inheritDoc} 130 */ 131 public Content getSignature(Element member) { 132 return new MemberSignature(member) 133 .addType(getType(member)) 134 .toContent(); 135 } 136 137 /** 138 * {@inheritDoc} 139 */ 140 public void addDeprecated(Element member, Content annotationDocTree) { 141 addDeprecatedInfo(member, annotationDocTree); 142 } 143 144 /** 145 * {@inheritDoc} 146 */ 147 public void addComments(Element member, Content annotationDocTree) { 148 addComment(member, annotationDocTree); 149 } 150 151 /** 152 * {@inheritDoc} 153 */ 154 public void addTags(Element member, Content annotationDocTree) { 155 writer.addTagsInfo(member, annotationDocTree); 156 } 157 158 /** 159 * {@inheritDoc} 160 */ 161 public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) { 162 Content annotationDetails = new ContentBuilder(annotationDetailsTreeHeader, annotationDetailsTree); 163 return getMemberTree(HtmlTree.SECTION(HtmlStyle.memberDetails, annotationDetails)); 164 } 165 166 /** 167 * {@inheritDoc} 168 */ 169 public Content getAnnotationDoc(Content annotationDocTree) { 170 return getMemberTree(annotationDocTree); 171 } 172 173 /** 174 * {@inheritDoc} 175 */ 176 public void addSummaryLabel(Content memberTree) { 177 HtmlTree label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING, 178 contents.annotateTypeRequiredMemberSummaryLabel); 179 memberTree.add(label); 180 } 181 182 /** 183 * Get the caption for the summary table. 184 * @return the caption 185 */ 186 // Overridden by AnnotationTypeOptionalMemberWriterImpl 187 protected Content getCaption() { 188 return contents.getContent("doclet.Annotation_Type_Required_Members"); 189 } 190 191 /** 192 * {@inheritDoc} 193 */ 194 @Override 195 public TableHeader getSummaryTableHeader(Element member) { 196 return new TableHeader(contents.modifierAndTypeLabel, 197 contents.annotationTypeRequiredMemberLabel, contents.descriptionLabel); 198 } 199 200 /** 201 * {@inheritDoc} 202 */ 203 @Override 204 protected Table createSummaryTable() { 205 return new Table(HtmlStyle.memberSummary) 206 .setCaption(getCaption()) 207 .setHeader(getSummaryTableHeader(typeElement)) 208 .setRowScopeColumn(1) 209 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); 210 } 211 212 /** 213 * {@inheritDoc} 214 */ 215 public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) { 216 } 217 218 /** 219 * {@inheritDoc} 220 */ 221 protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member, 222 Content tdSummary) { 223 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 224 writer.getDocLink(context, member, name(member), false)); 225 Content code = HtmlTree.CODE(memberLink); 226 tdSummary.add(code); 227 } 228 229 /** 230 * {@inheritDoc} 231 */ 232 protected void addInheritedSummaryLink(TypeElement typeElement, 233 Element member, Content linksTree) { 234 //Not applicable. 235 } 236 237 /** 238 * {@inheritDoc} 239 */ 240 protected void addSummaryType(Element member, Content tdSummaryType) { 241 addModifierAndType(member, getType(member), tdSummaryType); 242 } 243 244 /** 245 * {@inheritDoc} 246 */ 247 protected Content getDeprecatedLink(Element member) { 248 String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName(); 249 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name); 250 } 251 252 private TypeMirror getType(Element member) { 253 return utils.isExecutableElement(member) 254 ? utils.getReturnType((ExecutableElement) member) 255 : member.asType(); 256 } 257 }