AnnotationTypeFieldWriterImpl.java revision 2571:10fc81ac75b4
12849Sphk/* 22849Sphk * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 32849Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 493151Sphk * 52849Sphk * This code is free software; you can redistribute it and/or modify it 62849Sphk * under the terms of the GNU General Public License version 2 only, as 72849Sphk * published by the Free Software Foundation. Oracle designates this 82849Sphk * particular file as subject to the "Classpath" exception as provided 950479Speter * by Oracle in the LICENSE file that accompanied this code. 102849Sphk * 112849Sphk * This code is distributed in the hope that it will be useful, but WITHOUT 122849Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13206622Suqs * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1479537Sru * version 2 for more details (a copy is included in the LICENSE file that 152849Sphk * accompanied this code). 162849Sphk * 172849Sphk * You should have received a copy of the GNU General Public License version 182849Sphk * 2 along with this work; if not, write to the Free Software Foundation, 1968965Sru * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2029559Scharnier * 2129559Scharnier * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2229559Scharnier * or visit www.oracle.com if you need additional information or have any 2329559Scharnier * questions. 242849Sphk */ 2595127Scharnier 2695127Scharnierpackage com.sun.tools.doclets.formats.html; 2795127Scharnier 282849Sphkimport java.io.*; 2968575Sru 3095127Scharnierimport com.sun.javadoc.*; 3195127Scharnierimport com.sun.tools.doclets.formats.html.markup.*; 3295127Scharnierimport com.sun.tools.doclets.internal.toolkit.*; 3381251Sru 3481251Sru/** 352849Sphk * Writes annotation type field documentation in HTML format. 3625932Seivind * 372849Sphk * <p><b>This is NOT part of any supported API. 382849Sphk * If you write code that depends on this, you do so at your own risk. 392849Sphk * This code and its internal interfaces are subject to change or 4037207Ssteve * deletion without notice.</b> 412849Sphk * 422849Sphk * @author Bhavesh Patel 4368575Sru */ 442849Sphkpublic class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter 452849Sphk implements AnnotationTypeFieldWriter, MemberSummaryWriter { 462849Sphk 4729559Scharnier /** 482849Sphk * Construct a new AnnotationTypeFieldWriterImpl. 4979755Sdd * 502849Sphk * @param writer the writer that will write the output. 512849Sphk * @param annotationType the AnnotationType that holds this member. 522849Sphk */ 532849Sphk public AnnotationTypeFieldWriterImpl(SubWriterHolderWriter writer, 542849Sphk AnnotationTypeDoc annotationType) { 552849Sphk super(writer, annotationType); 5629559Scharnier } 57141846Sru 5857673Ssheldonh /** 5929559Scharnier * {@inheritDoc} 602849Sphk */ 61131500Sru public Content getMemberSummaryHeader(ClassDoc classDoc, 62131500Sru Content memberSummaryTree) { 632849Sphk memberSummaryTree.addContent( 64131500Sru HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY); 65131500Sru Content memberTree = writer.getMemberTreeHeader(); 6659651Sobrien writer.addSummaryHeader(this, classDoc, memberTree); 672849Sphk return memberTree; 6868575Sru } 6995127Scharnier 7095127Scharnier /** 7195127Scharnier * {@inheritDoc} 722849Sphk */ 732849Sphk public Content getMemberTreeHeader() { 742849Sphk return writer.getMemberTreeHeader(); 752849Sphk } 7668575Sru 772849Sphk /** 782849Sphk * {@inheritDoc} 792849Sphk */ 802849Sphk public void addAnnotationFieldDetailsMarker(Content memberDetails) { 812849Sphk memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_DETAILS); 822849Sphk } 8368854Sru 8495127Scharnier /** 8595127Scharnier * {@inheritDoc} 8695127Scharnier */ 872849Sphk public void addAnnotationDetailsTreeHeader(ClassDoc classDoc, 882849Sphk Content memberDetailsTree) { 8968575Sru if (!writer.printedAnnotationFieldHeading) { 90233510Sjoel memberDetailsTree.addContent(writer.getMarkerAnchor( 9168575Sru SectionName.ANNOTATION_TYPE_FIELD_DETAIL)); 922849Sphk Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 9371102Sru writer.fieldDetailsLabel); 942849Sphk memberDetailsTree.addContent(heading); 952849Sphk writer.printedAnnotationFieldHeading = true; 962849Sphk } 972849Sphk } 9834809Scharnier 992849Sphk /** 10095127Scharnier * {@inheritDoc} 10195127Scharnier */ 10295127Scharnier public Content getAnnotationDocTreeHeader(MemberDoc member, 1032849Sphk Content annotationDetailsTree) { 1042849Sphk annotationDetailsTree.addContent( 10534809Scharnier writer.getMarkerAnchor(member.name())); 1062849Sphk Content annotationDocTree = writer.getMemberTreeHeader(); 10793151Sphk Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 1082849Sphk heading.addContent(member.name()); 1092849Sphk annotationDocTree.addContent(heading); 11068575Sru return annotationDocTree; 1112849Sphk } 1122849Sphk 1132849Sphk /** 1142849Sphk * {@inheritDoc} 11568575Sru */ 1162849Sphk public Content getSignature(MemberDoc member) { 11737079Smph Content pre = new HtmlTree(HtmlTag.PRE); 11868575Sru writer.addAnnotationInfo(member, pre); 1192849Sphk addModifiers(member, pre); 1202849Sphk Content link = 12168575Sru writer.getLink(new LinkInfoImpl(configuration, 1222849Sphk LinkInfoImpl.Kind.MEMBER, getType(member))); 1232849Sphk pre.addContent(link); 1242849Sphk pre.addContent(writer.getSpace()); 1252849Sphk if (configuration.linksource) { 1262849Sphk Content memberName = new StringContent(member.name()); 1272849Sphk writer.addSrcLink(member, memberName, pre); 1282849Sphk } else { 12937079Smph addName(member.name(), pre); 130 } 131 return pre; 132 } 133 134 /** 135 * {@inheritDoc} 136 */ 137 public void addDeprecated(MemberDoc member, Content annotationDocTree) { 138 addDeprecatedInfo(member, annotationDocTree); 139 } 140 141 /** 142 * {@inheritDoc} 143 */ 144 public void addComments(MemberDoc member, Content annotationDocTree) { 145 addComment(member, annotationDocTree); 146 } 147 148 /** 149 * {@inheritDoc} 150 */ 151 public void addTags(MemberDoc member, Content annotationDocTree) { 152 writer.addTagsInfo(member, annotationDocTree); 153 } 154 155 /** 156 * {@inheritDoc} 157 */ 158 public Content getAnnotationDetails(Content annotationDetailsTree) { 159 return getMemberTree(annotationDetailsTree); 160 } 161 162 /** 163 * {@inheritDoc} 164 */ 165 public Content getAnnotationDoc(Content annotationDocTree, 166 boolean isLastContent) { 167 return getMemberTree(annotationDocTree, isLastContent); 168 } 169 170 /** 171 * Close the writer. 172 */ 173 public void close() throws IOException { 174 writer.close(); 175 } 176 177 /** 178 * {@inheritDoc} 179 */ 180 public void addSummaryLabel(Content memberTree) { 181 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 182 writer.getResource("doclet.Field_Summary")); 183 memberTree.addContent(label); 184 } 185 186 /** 187 * {@inheritDoc} 188 */ 189 public String getTableSummary() { 190 return configuration.getText("doclet.Member_Table_Summary", 191 configuration.getText("doclet.Field_Summary"), 192 configuration.getText("doclet.fields")); 193 } 194 195 /** 196 * {@inheritDoc} 197 */ 198 public Content getCaption() { 199 return configuration.getResource("doclet.Fields"); 200 } 201 202 /** 203 * {@inheritDoc} 204 */ 205 public String[] getSummaryTableHeader(ProgramElementDoc member) { 206 String[] header = new String[] { 207 writer.getModifierTypeHeader(), 208 configuration.getText("doclet.0_and_1", 209 configuration.getText("doclet.Fields"), 210 configuration.getText("doclet.Description")) 211 }; 212 return header; 213 } 214 215 /** 216 * {@inheritDoc} 217 */ 218 public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 219 memberTree.addContent(writer.getMarkerAnchor( 220 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY)); 221 } 222 223 /** 224 * {@inheritDoc} 225 */ 226 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { 227 } 228 229 /** 230 * {@inheritDoc} 231 */ 232 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { 233 } 234 235 /** 236 * {@inheritDoc} 237 */ 238 protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, 239 Content tdSummary) { 240 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 241 writer.getDocLink(context, (MemberDoc) member, member.name(), false)); 242 Content code = HtmlTree.CODE(memberLink); 243 tdSummary.addContent(code); 244 } 245 246 /** 247 * {@inheritDoc} 248 */ 249 protected void addInheritedSummaryLink(ClassDoc cd, 250 ProgramElementDoc member, Content linksTree) { 251 //Not applicable. 252 } 253 254 /** 255 * {@inheritDoc} 256 */ 257 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { 258 MemberDoc m = (MemberDoc)member; 259 addModifierAndType(m, getType(m), tdSummaryType); 260 } 261 262 /** 263 * {@inheritDoc} 264 */ 265 protected Content getDeprecatedLink(ProgramElementDoc member) { 266 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 267 (MemberDoc) member, ((MemberDoc)member).qualifiedName()); 268 } 269 270 /** 271 * {@inheritDoc} 272 */ 273 protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 274 if (link) { 275 return writer.getHyperLink( 276 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY, 277 writer.getResource("doclet.navField")); 278 } else { 279 return writer.getResource("doclet.navField"); 280 } 281 } 282 283 /** 284 * {@inheritDoc} 285 */ 286 protected void addNavDetailLink(boolean link, Content liNav) { 287 if (link) { 288 liNav.addContent(writer.getHyperLink( 289 SectionName.ANNOTATION_TYPE_FIELD_DETAIL, 290 writer.getResource("doclet.navField"))); 291 } else { 292 liNav.addContent(writer.getResource("doclet.navField")); 293 } 294 } 295 296 private Type getType(MemberDoc member) { 297 if (member instanceof FieldDoc) { 298 return ((FieldDoc) member).type(); 299 } else { 300 return ((MethodDoc) member).returnType(); 301 } 302 } 303} 304