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.Table; 37 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader; 38 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter; 39 import jdk.javadoc.internal.doclets.toolkit.Content; 40 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; 41 42 43 /** 44 * Writes annotation type required member documentation in HTML format. 45 * 46 * <p><b>This is NOT part of any supported API. 47 * If you write code that depends on this, you do so at your own risk. 48 * This code and its internal interfaces are subject to change or 49 * deletion without notice.</b> 50 * 51 * @author Jamie Ho 52 * @author Bhavesh Patel (Modified) 53 */ 54 public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter 55 implements AnnotationTypeRequiredMemberWriter, MemberSummaryWriter { 56 57 /** 58 * Construct a new AnnotationTypeRequiredMemberWriterImpl. 59 * 60 * @param writer the writer that will write the output. 61 * @param annotationType the AnnotationType that holds this member. 62 */ 63 public AnnotationTypeRequiredMemberWriterImpl(SubWriterHolderWriter writer, 64 TypeElement annotationType) { 65 super(writer, annotationType); 66 } 67 68 /** 69 * {@inheritDoc} 70 */ 71 public Content getMemberSummaryHeader(TypeElement typeElement, 72 Content memberSummaryTree) { 73 memberSummaryTree.add( 74 MarkerComments.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY); 75 Content memberTree = new ContentBuilder(); 76 writer.addSummaryHeader(this, typeElement, memberTree); 77 return memberTree; 78 } 79 80 /** 81 * {@inheritDoc} 82 */ 83 public Content getMemberTreeHeader() { 84 return writer.getMemberTreeHeader(); 85 } 86 87 /** 88 * {@inheritDoc} 89 */ 90 public void addMemberTree(Content memberSummaryTree, Content memberTree) { 91 writer.addMemberTree(HtmlStyle.memberSummary, memberSummaryTree, memberTree); 92 } 93 94 /** 95 * {@inheritDoc} 96 */ 97 public void addAnnotationDetailsMarker(Content memberDetails) { 98 memberDetails.add(MarkerComments.START_OF_ANNOTATION_TYPE_DETAILS); 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 public Content getAnnotationDetailsTreeHeader(TypeElement te) { 105 Content memberDetailsTree = new ContentBuilder(); 106 if (!writer.printedAnnotationHeading) { 107 Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, 108 contents.annotationTypeDetailsLabel); 109 memberDetailsTree.add(heading); 110 memberDetailsTree.add(links.createAnchor( 111 SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL)); 112 writer.printedAnnotationHeading = true; 113 } 114 return memberDetailsTree; 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 @Override 121 public Content getAnnotationDocTreeHeader(Element member, Content annotationDetailsTree) { 122 String simpleName = name(member); 123 Content annotationDocTree = new ContentBuilder(); 124 Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING); 125 heading.add(simpleName); 126 annotationDocTree.add(heading); 127 annotationDocTree.add(links.createAnchor( 128 simpleName + utils.signature((ExecutableElement) member))); 129 return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree); 130 } 131 132 /** 133 * {@inheritDoc} 134 */ 135 public Content getSignature(Element member) { 136 return new MemberSignature(member) 137 .addType(getType(member)) 138 .toContent(); 139 } 140 141 /** 142 * {@inheritDoc} 143 */ 144 public void addDeprecated(Element member, Content annotationDocTree) { 145 addDeprecatedInfo(member, annotationDocTree); 146 } 147 148 /** 149 * {@inheritDoc} 150 */ 151 public void addComments(Element member, Content annotationDocTree) { 152 addComment(member, annotationDocTree); 153 } 154 155 /** 156 * {@inheritDoc} 157 */ 158 public void addTags(Element member, Content annotationDocTree) { 159 writer.addTagsInfo(member, annotationDocTree); 160 } 161 162 /** 163 * {@inheritDoc} 164 */ 165 public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) { 166 Content annotationDetails = new ContentBuilder(annotationDetailsTreeHeader, annotationDetailsTree); 167 return getMemberTree(HtmlTree.SECTION(HtmlStyle.memberDetails, annotationDetails)); 168 } 169 170 /** 171 * {@inheritDoc} 172 */ 173 public Content getAnnotationDoc(Content annotationDocTree, 174 boolean isLastContent) { 175 return getMemberTree(annotationDocTree, isLastContent); 176 } 177 178 /** 179 * {@inheritDoc} 180 */ 181 public void addSummaryLabel(Content memberTree) { 182 Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING, 183 contents.annotateTypeRequiredMemberSummaryLabel); 184 memberTree.add(label); 185 } 186 187 /** 188 * Get the caption for the summary table. 189 * @return the caption 190 */ 191 // Overridden by AnnotationTypeOptionalMemberWriterImpl 192 protected Content getCaption() { 193 return contents.getContent("doclet.Annotation_Type_Required_Members"); 194 } 195 196 /** 197 * {@inheritDoc} 198 */ 199 @Override 200 public TableHeader getSummaryTableHeader(Element member) { 201 return new TableHeader(contents.modifierAndTypeLabel, 202 contents.annotationTypeRequiredMemberLabel, contents.descriptionLabel); 203 } 204 205 /** 206 * {@inheritDoc} 207 */ 208 @Override 209 protected Table createSummaryTable() { 210 return new Table(HtmlStyle.memberSummary) 211 .setCaption(getCaption()) 212 .setHeader(getSummaryTableHeader(typeElement)) 213 .setRowScopeColumn(1) 214 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); 215 } 216 217 /** 218 * {@inheritDoc} 219 */ 220 public void addSummaryAnchor(TypeElement typeElement, Content memberTree) { 221 memberTree.add(links.createAnchor( 222 SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY)); 223 } 224 225 /** 226 * {@inheritDoc} 227 */ 228 public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) { 229 } 230 231 /** 232 * {@inheritDoc} 233 */ 234 public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) { 235 } 236 237 /** 238 * {@inheritDoc} 239 */ 240 protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member, 241 Content tdSummary) { 242 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 243 writer.getDocLink(context, member, name(member), false)); 244 Content code = HtmlTree.CODE(memberLink); 245 tdSummary.add(code); 246 } 247 248 /** 249 * {@inheritDoc} 250 */ 251 protected void addInheritedSummaryLink(TypeElement typeElement, 252 Element member, Content linksTree) { 253 //Not applicable. 254 } 255 256 /** 257 * {@inheritDoc} 258 */ 259 protected void addSummaryType(Element member, Content tdSummaryType) { 260 addModifierAndType(member, getType(member), tdSummaryType); 261 } 262 263 /** 264 * {@inheritDoc} 265 */ 266 protected Content getDeprecatedLink(Element member) { 267 String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName(); 268 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name); 269 } 270 271 private TypeMirror getType(Element member) { 272 return utils.isExecutableElement(member) 273 ? utils.getReturnType((ExecutableElement) member) 274 : member.asType(); 275 } 276 } --- EOF ---