1 /* 2 * Copyright (c) 2013, 2015, 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 com.sun.tools.doclets.formats.html; 27 28 import java.io.*; 29 30 import com.sun.javadoc.*; 31 import com.sun.tools.doclets.formats.html.markup.*; 32 import com.sun.tools.doclets.internal.toolkit.*; 33 34 /** 35 * Writes annotation type field documentation in HTML format. 36 * 37 * <p><b>This is NOT part of any supported API. 38 * If you write code that depends on this, you do so at your own risk. 39 * This code and its internal interfaces are subject to change or 40 * deletion without notice.</b> 41 * 42 * @author Bhavesh Patel 43 */ 44 public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter 45 implements AnnotationTypeFieldWriter, MemberSummaryWriter { 46 47 /** 48 * Construct a new AnnotationTypeFieldWriterImpl. 49 * 50 * @param writer the writer that will write the output. 51 * @param annotationType the AnnotationType that holds this member. 52 */ 53 public AnnotationTypeFieldWriterImpl(SubWriterHolderWriter writer, 54 AnnotationTypeDoc annotationType) { 55 super(writer, annotationType); 56 } 57 58 /** 59 * {@inheritDoc} 60 */ 61 public Content getMemberSummaryHeader(ClassDoc classDoc, 62 Content memberSummaryTree) { 63 memberSummaryTree.addContent( 64 HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY); 65 Content memberTree = writer.getMemberTreeHeader(); 66 writer.addSummaryHeader(this, classDoc, memberTree); 67 return memberTree; 68 } 69 70 /** 71 * {@inheritDoc} 72 */ 73 public Content getMemberTreeHeader() { 74 return writer.getMemberTreeHeader(); 75 } 76 77 /** 78 * {@inheritDoc} 79 */ 80 public void addMemberTree(Content memberSummaryTree, Content memberTree) { 81 writer.addMemberTree(memberSummaryTree, memberTree); 82 } 83 84 /** 85 * {@inheritDoc} 86 */ 87 public void addAnnotationFieldDetailsMarker(Content memberDetails) { 88 memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_DETAILS); 89 } 90 91 /** 92 * {@inheritDoc} 93 */ 94 public void addAnnotationDetailsTreeHeader(ClassDoc classDoc, 95 Content memberDetailsTree) { 96 if (!writer.printedAnnotationFieldHeading) { 97 memberDetailsTree.addContent(writer.getMarkerAnchor( 98 SectionName.ANNOTATION_TYPE_FIELD_DETAIL)); 99 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 100 writer.fieldDetailsLabel); 101 memberDetailsTree.addContent(heading); 102 writer.printedAnnotationFieldHeading = true; 103 } 104 } 105 106 /** 107 * {@inheritDoc} 108 */ 109 public Content getAnnotationDocTreeHeader(MemberDoc member, 110 Content annotationDetailsTree) { 111 annotationDetailsTree.addContent( 112 writer.getMarkerAnchor(member.name())); 113 Content annotationDocTree = writer.getMemberTreeHeader(); 114 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 115 heading.addContent(member.name()); 116 annotationDocTree.addContent(heading); 117 return annotationDocTree; 118 } 119 120 /** 121 * {@inheritDoc} 122 */ 123 public Content getSignature(MemberDoc member) { 124 Content pre = new HtmlTree(HtmlTag.PRE); 125 writer.addAnnotationInfo(member, pre); 126 addModifiers(member, pre); 127 Content link = 128 writer.getLink(new LinkInfoImpl(configuration, 129 LinkInfoImpl.Kind.MEMBER, getType(member))); 130 pre.addContent(link); 131 pre.addContent(writer.getSpace()); 132 if (configuration.linksource) { 133 Content memberName = new StringContent(member.name()); 134 writer.addSrcLink(member, memberName, pre); 135 } else { 136 addName(member.name(), pre); 137 } 138 return pre; 139 } 140 141 /** 142 * {@inheritDoc} 143 */ 144 public void addDeprecated(MemberDoc member, Content annotationDocTree) { 145 addDeprecatedInfo(member, annotationDocTree); 146 } 147 148 /** 149 * {@inheritDoc} 150 */ 151 public void addComments(MemberDoc member, Content annotationDocTree) { 152 addComment(member, annotationDocTree); 153 } 154 155 /** 156 * {@inheritDoc} 157 */ 158 public void addTags(MemberDoc member, Content annotationDocTree) { 159 writer.addTagsInfo(member, annotationDocTree); 160 } 161 162 /** 163 * {@inheritDoc} 164 */ 165 public Content getAnnotationDetails(Content annotationDetailsTree) { 166 if (configuration.allowTag(HtmlTag.SECTION)) { 167 HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree)); 168 return htmlTree; 169 } 170 return getMemberTree(annotationDetailsTree); 171 } 172 173 /** 174 * {@inheritDoc} 175 */ 176 public Content getAnnotationDoc(Content annotationDocTree, 177 boolean isLastContent) { 178 return getMemberTree(annotationDocTree, isLastContent); 179 } 180 181 /** 182 * Close the writer. 183 */ 184 public void close() throws IOException { 185 writer.close(); 186 } 187 188 /** 189 * {@inheritDoc} 190 */ 191 public void addSummaryLabel(Content memberTree) { 192 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 193 writer.getResource("doclet.Field_Summary")); 194 memberTree.addContent(label); 195 } 196 197 /** 198 * {@inheritDoc} 199 */ 200 public String getTableSummary() { 201 return configuration.getText("doclet.Member_Table_Summary", 202 configuration.getText("doclet.Field_Summary"), 203 configuration.getText("doclet.fields")); 204 } 205 206 /** 207 * {@inheritDoc} 208 */ 209 public Content getCaption() { 210 return configuration.getResource("doclet.Fields"); 211 } 212 213 /** 214 * {@inheritDoc} 215 */ 216 public String[] getSummaryTableHeader(ProgramElementDoc member) { 217 String[] header = new String[] { 218 writer.getModifierTypeHeader(), 219 configuration.getText("doclet.0_and_1", 220 configuration.getText("doclet.Fields"), 221 configuration.getText("doclet.Description")) 222 }; 223 return header; 224 } 225 226 /** 227 * {@inheritDoc} 228 */ 229 public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 230 memberTree.addContent(writer.getMarkerAnchor( 231 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY)); 232 } 233 234 /** 235 * {@inheritDoc} 236 */ 237 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { 238 } 239 240 /** 241 * {@inheritDoc} 242 */ 243 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { 244 } 245 246 /** 247 * {@inheritDoc} 248 */ 249 protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, 250 Content tdSummary) { 251 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 252 writer.getDocLink(context, (MemberDoc) member, member.name(), false)); 253 Content code = HtmlTree.CODE(memberLink); 254 tdSummary.addContent(code); 255 } 256 257 /** 258 * {@inheritDoc} 259 */ 260 protected void addInheritedSummaryLink(ClassDoc cd, 261 ProgramElementDoc member, Content linksTree) { 262 //Not applicable. 263 } 264 265 /** 266 * {@inheritDoc} 267 */ 268 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { 269 MemberDoc m = (MemberDoc)member; 270 addModifierAndType(m, getType(m), tdSummaryType); 271 } 272 273 /** 274 * {@inheritDoc} 275 */ 276 protected Content getDeprecatedLink(ProgramElementDoc member) { 277 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 278 (MemberDoc) member, ((MemberDoc)member).qualifiedName()); 279 } 280 281 /** 282 * {@inheritDoc} 283 */ 284 protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 285 if (link) { 286 return writer.getHyperLink( 287 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY, 288 writer.getResource("doclet.navField")); 289 } else { 290 return writer.getResource("doclet.navField"); 291 } 292 } 293 294 /** 295 * {@inheritDoc} 296 */ 297 protected void addNavDetailLink(boolean link, Content liNav) { 298 if (link) { 299 liNav.addContent(writer.getHyperLink( 300 SectionName.ANNOTATION_TYPE_FIELD_DETAIL, 301 writer.getResource("doclet.navField"))); 302 } else { 303 liNav.addContent(writer.getResource("doclet.navField")); 304 } 305 } 306 307 private Type getType(MemberDoc member) { 308 if (member instanceof FieldDoc) { 309 return ((FieldDoc) member).type(); 310 } else { 311 return ((MethodDoc) member).returnType(); 312 } 313 } 314 }