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