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 MemberSignature sig = new MemberSignature(member); 135 sig.addType(getType(member)); 136 sig.addName(member); 137 return sig.toContent(); 138 } 139 140 /** 141 * {@inheritDoc} 142 */ 143 public void addDeprecated(Element member, Content annotationDocTree) { 144 addDeprecatedInfo(member, annotationDocTree); 145 } 146 147 /** 148 * {@inheritDoc} 149 */ 150 public void addComments(Element member, Content annotationDocTree) { 151 addComment(member, annotationDocTree); 152 } 153 154 /** 155 * {@inheritDoc} 156 */ 157 public void addTags(Element member, Content annotationDocTree) { 158 writer.addTagsInfo(member, annotationDocTree); 159 } 160 161 /** 162 * {@inheritDoc} 163 */ 164 public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) { 165 Content annotationDetails = new ContentBuilder(); 166 annotationDetails.add(annotationDetailsTreeHeader); 167 annotationDetails.add(annotationDetailsTree); 168 return getMemberTree(HtmlTree.SECTION(HtmlStyle.fieldDetails, annotationDetails)); 169 } 170 171 /** 172 * {@inheritDoc} 173 */ 174 public Content getAnnotationDoc(Content annotationDocTree, 175 boolean isLastContent) { 176 return getMemberTree(annotationDocTree, isLastContent); 177 } 178 179 /** 180 * {@inheritDoc} 181 */ 182 public void addSummaryLabel(Content memberTree) { 183 Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING, 184 contents.fieldSummaryLabel); 185 memberTree.add(label); 186 } 187 188 /** 189 * {@inheritDoc} 190 */ 191 @Override 192 public TableHeader getSummaryTableHeader(Element member) { 193 return new TableHeader(contents.modifierAndTypeLabel, contents.fields, 194 contents.descriptionLabel); 195 } 196 197 @Override 198 protected Table createSummaryTable() { 199 Content caption = contents.getContent("doclet.Fields"); 200 201 TableHeader header = new TableHeader(contents.modifierAndTypeLabel, contents.fields, 202 contents.descriptionLabel); 203 204 return new Table(HtmlStyle.memberSummary) 205 .setCaption(caption) 206 .setHeader(header) 207 .setRowScopeColumn(1) 208 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast); 209 } 210 211 /** 212 * {@inheritDoc} 213 */ 214 @Override 215 public void addSummaryAnchor(TypeElement typeElement, Content memberTree) { 216 memberTree.add(links.createAnchor( 217 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY)); 218 } 219 220 /** 221 * {@inheritDoc} 222 */ 223 @Override 224 public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) { 225 } 226 227 /** 228 * {@inheritDoc} 229 */ 230 @Override 231 public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) { 232 } 233 234 /** 235 * {@inheritDoc} 236 */ 237 @Override 238 protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member, 239 Content tdSummary) { 240 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 241 writer.getDocLink(context, member, name(member), false)); 242 Content code = HtmlTree.CODE(memberLink); 243 tdSummary.add(code); 244 } 245 246 /** 247 * {@inheritDoc} 248 */ 249 protected void addInheritedSummaryLink(TypeElement typeElement, 250 Element member, Content linksTree) { 251 //Not applicable. 252 } 253 254 /** 255 * {@inheritDoc} 256 */ 257 protected void addSummaryType(Element member, Content tdSummaryType) { 258 addModifierAndType(member, getType(member), tdSummaryType); 259 } 260 261 /** 262 * {@inheritDoc} 263 */ 264 protected Content getDeprecatedLink(Element member) { 265 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 266 member, utils.getFullyQualifiedName(member)); 267 } 268 269 private TypeMirror getType(Element member) { 270 if (utils.isConstructor(member)) 271 return null; 272 if (utils.isExecutableElement(member)) 273 return utils.getReturnType((ExecutableElement)member); 274 return member.asType(); 275 } 276 } --- EOF ---