1 /* 2 * Copyright (c) 2013, 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.Entity; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 38 import jdk.javadoc.internal.doclets.formats.html.markup.Table; 39 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader; 40 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter; 41 import jdk.javadoc.internal.doclets.toolkit.Content; 42 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; 43 44 /** 45 * Writes annotation type field 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 * @author Bhavesh Patel 53 */ 54 public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter 55 implements AnnotationTypeFieldWriter, MemberSummaryWriter { 56 57 /** 58 * Construct a new AnnotationTypeFieldWriterImpl. 59 * 60 * @param writer the writer that will write the output. 61 * @param annotationType the AnnotationType that holds this member. 62 */ 63 public AnnotationTypeFieldWriterImpl(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_FIELD_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.fieldSummary, memberSummaryTree, memberTree); 92 } 93 94 /** 95 * {@inheritDoc} 96 */ 97 public void addAnnotationFieldDetailsMarker(Content memberDetails) { 98 memberDetails.add(MarkerComments.START_OF_ANNOTATION_TYPE_FIELD_DETAILS); 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 public Content getAnnotationDetailsTreeHeader(TypeElement typeElement) { 105 Content memberDetailsTree = new ContentBuilder(); 106 if (!writer.printedAnnotationFieldHeading) { 107 Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, 108 contents.fieldDetailsLabel); 109 memberDetailsTree.add(heading); 110 memberDetailsTree.add(links.createAnchor( 111 SectionName.ANNOTATION_TYPE_FIELD_DETAIL)); 112 writer.printedAnnotationFieldHeading = true; 113 } 114 return memberDetailsTree; 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 public Content getAnnotationDocTreeHeader(Element member, 121 Content annotationDetailsTree) { 122 Content annotationDocTree = new ContentBuilder(); 123 Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING); 124 heading.add(name(member)); 125 annotationDocTree.add(heading); 126 annotationDocTree.add(links.createAnchor(name(member))); 127 return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree); 128 } 129 130 /** 131 * {@inheritDoc} 132 */ 133 public Content getSignature(Element member) { 134 return new MemberSignature(member) 135 .addType(getType(member)) 136 .toContent(); 137 } 138 139 /** 140 * {@inheritDoc} 141 */ 142 public void addDeprecated(Element member, Content annotationDocTree) { 143 addDeprecatedInfo(member, annotationDocTree); 144 } 145 146 /** 147 * {@inheritDoc} 148 */ 149 public void addComments(Element member, Content annotationDocTree) { 150 addComment(member, annotationDocTree); 151 } 152 153 /** 154 * {@inheritDoc} 155 */ 156 public void addTags(Element member, Content annotationDocTree) { 157 writer.addTagsInfo(member, annotationDocTree); 158 } 159 160 /** 161 * {@inheritDoc} 162 */ 163 public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) { 164 Content annotationDetails = new ContentBuilder(); 165 annotationDetails.add(annotationDetailsTreeHeader); 166 annotationDetails.add(annotationDetailsTree); 167 return getMemberTree(HtmlTree.SECTION(HtmlStyle.fieldDetails, 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.fieldSummaryLabel); 184 memberTree.add(label); 185 } 186 187 /** 188 * {@inheritDoc} 189 */ 190 @Override 191 public TableHeader getSummaryTableHeader(Element member) { 192 return new TableHeader(contents.modifierAndTypeLabel, contents.fields, 193 contents.descriptionLabel); 194 } 195 196 @Override 197 protected Table createSummaryTable() { 198 Content caption = contents.getContent("doclet.Fields"); 199 200 TableHeader header = new TableHeader(contents.modifierAndTypeLabel, contents.fields, 201 contents.descriptionLabel); 202 203 return new Table(HtmlStyle.memberSummary) 204 .setCaption(caption) 205 .setHeader(header) 206 .setRowScopeColumn(1) 207 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); 208 } 209 210 /** 211 * {@inheritDoc} 212 */ 213 @Override 214 public void addSummaryAnchor(TypeElement typeElement, Content memberTree) { 215 memberTree.add(links.createAnchor( 216 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY)); 217 } 218 219 /** 220 * {@inheritDoc} 221 */ 222 @Override 223 public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) { 224 } 225 226 /** 227 * {@inheritDoc} 228 */ 229 @Override 230 public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) { 231 } 232 233 /** 234 * {@inheritDoc} 235 */ 236 @Override 237 protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member, 238 Content tdSummary) { 239 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 240 writer.getDocLink(context, member, name(member), false)); 241 Content code = HtmlTree.CODE(memberLink); 242 tdSummary.add(code); 243 } 244 245 /** 246 * {@inheritDoc} 247 */ 248 protected void addInheritedSummaryLink(TypeElement typeElement, 249 Element member, Content linksTree) { 250 //Not applicable. 251 } 252 253 /** 254 * {@inheritDoc} 255 */ 256 protected void addSummaryType(Element member, Content tdSummaryType) { 257 addModifierAndType(member, getType(member), tdSummaryType); 258 } 259 260 /** 261 * {@inheritDoc} 262 */ 263 protected Content getDeprecatedLink(Element member) { 264 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 265 member, utils.getFullyQualifiedName(member)); 266 } 267 268 private TypeMirror getType(Element member) { 269 if (utils.isConstructor(member)) 270 return null; 271 if (utils.isExecutableElement(member)) 272 return utils.getReturnType((ExecutableElement)member); 273 return member.asType(); 274 } 275 }