1 /* 2 * Copyright (c) 2013, 2016, 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.TableHeader; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 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.toolkit.AnnotationTypeFieldWriter; 40 import jdk.javadoc.internal.doclets.toolkit.Content; 41 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; 42 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.addContent( 74 HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY); 75 Content memberTree = writer.getMemberTreeHeader(); 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(memberSummaryTree, memberTree); 92 } 93 94 /** 95 * {@inheritDoc} 96 */ 97 public void addAnnotationFieldDetailsMarker(Content memberDetails) { 98 memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_DETAILS); 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 public void addAnnotationDetailsTreeHeader(TypeElement typeElement, 105 Content memberDetailsTree) { 106 if (!writer.printedAnnotationFieldHeading) { 107 memberDetailsTree.addContent(writer.getMarkerAnchor( 108 SectionName.ANNOTATION_TYPE_FIELD_DETAIL)); 109 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 110 contents.fieldDetailsLabel); 111 memberDetailsTree.addContent(heading); 112 writer.printedAnnotationFieldHeading = true; 113 } 114 } 115 116 /** 117 * {@inheritDoc} 118 */ 119 public Content getAnnotationDocTreeHeader(Element member, 120 Content annotationDetailsTree) { 121 annotationDetailsTree.addContent( 122 writer.getMarkerAnchor(name(member))); 123 Content annotationDocTree = writer.getMemberTreeHeader(); 124 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 125 heading.addContent(name(member)); 126 annotationDocTree.addContent(heading); 127 return annotationDocTree; 128 } 129 130 /** 131 * {@inheritDoc} 132 */ 133 public Content getSignature(Element member) { 134 Content pre = new HtmlTree(HtmlTag.PRE); 135 writer.addAnnotationInfo(member, pre); 136 addModifiers(member, pre); 137 Content link = 138 writer.getLink(new LinkInfoImpl(configuration, 139 LinkInfoImpl.Kind.MEMBER, getType(member))); 140 pre.addContent(link); 141 pre.addContent(Contents.SPACE); 142 if (configuration.linksource) { 143 Content memberName = new StringContent(name(member)); 144 writer.addSrcLink(member, memberName, pre); 145 } else { 146 addName(name(member), pre); 147 } 148 return pre; 149 } 150 151 /** 152 * {@inheritDoc} 153 */ 154 public void addDeprecated(Element member, Content annotationDocTree) { 155 addDeprecatedInfo(member, annotationDocTree); 156 } 157 158 /** 159 * {@inheritDoc} 160 */ 161 public void addComments(Element member, Content annotationDocTree) { 162 addComment(member, annotationDocTree); 163 } 164 165 /** 166 * {@inheritDoc} 167 */ 168 public void addTags(Element member, Content annotationDocTree) { 169 writer.addTagsInfo(member, annotationDocTree); 170 } 171 172 /** 173 * {@inheritDoc} 174 */ 175 public Content getAnnotationDetails(Content annotationDetailsTree) { 176 if (configuration.allowTag(HtmlTag.SECTION)) { 177 HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree)); 178 return htmlTree; 179 } 180 return getMemberTree(annotationDetailsTree); 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(HtmlConstants.SUMMARY_HEADING, 196 contents.fieldSummaryLabel); 197 memberTree.addContent(label); 198 } 199 200 /** 201 * {@inheritDoc} 202 */ 203 public String getTableSummary() { 204 return configuration.getText("doclet.Member_Table_Summary", 205 configuration.getText("doclet.Field_Summary"), 206 configuration.getText("doclet.fields")); 207 } 208 209 /** 210 * {@inheritDoc} 211 */ 212 public Content getCaption() { 213 return configuration.getContent("doclet.Fields"); 214 } 215 216 /** 217 * {@inheritDoc} 218 */ 219 @Override 220 public TableHeader getSummaryTableHeader(Element member) { 221 return new TableHeader(contents.modifierAndTypeLabel, contents.fields, 222 contents.descriptionLabel); 223 } 224 225 /** 226 * {@inheritDoc} 227 */ 228 public void addSummaryAnchor(TypeElement typeElement, Content memberTree) { 229 memberTree.addContent(writer.getMarkerAnchor( 230 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY)); 231 } 232 233 /** 234 * {@inheritDoc} 235 */ 236 public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) { 237 } 238 239 /** 240 * {@inheritDoc} 241 */ 242 public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) { 243 } 244 245 /** 246 * {@inheritDoc} 247 */ 248 protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member, 249 Content tdSummary) { 250 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 251 writer.getDocLink(context, member, name(member), false)); 252 Content code = HtmlTree.CODE(memberLink); 253 tdSummary.addContent(code); 254 } 255 256 /** 257 * {@inheritDoc} 258 */ 259 protected void addInheritedSummaryLink(TypeElement typeElement, 260 Element member, Content linksTree) { 261 //Not applicable. 262 } 263 264 /** 265 * {@inheritDoc} 266 */ 267 protected void addSummaryType(Element member, Content tdSummaryType) { 268 addModifierAndType(member, getType(member), tdSummaryType); 269 } 270 271 /** 272 * {@inheritDoc} 273 */ 274 protected Content getDeprecatedLink(Element member) { 275 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 276 member, utils.getFullyQualifiedName(member)); 277 } 278 279 /** 280 * {@inheritDoc} 281 */ 282 protected Content getNavSummaryLink(TypeElement typeElement, boolean link) { 283 if (link) { 284 return writer.getHyperLink( 285 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY, 286 contents.navField); 287 } else { 288 return contents.navField; 289 } 290 } 291 292 /** 293 * {@inheritDoc} 294 */ 295 protected void addNavDetailLink(boolean link, Content liNav) { 296 if (link) { 297 liNav.addContent(writer.getHyperLink( 298 SectionName.ANNOTATION_TYPE_FIELD_DETAIL, 299 contents.navField)); 300 } else { 301 liNav.addContent(contents.navField); 302 } 303 } 304 private TypeMirror getType(Element member) { 305 if (utils.isConstructor(member)) 306 return null; 307 if (utils.isExecutableElement(member)) 308 return utils.getReturnType((ExecutableElement)member); 309 return member.asType(); 310 } 311 }