src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java

Wed, 18 Dec 2013 19:48:47 -0800

author
bpatel
date
Wed, 18 Dec 2013 19:48:47 -0800
changeset 2225
b8ebde062692
parent 2147
130b8c0e570e
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8016549: jdk7 javadocs are hard to read
Reviewed-by: jjg

duke@1 1 /*
jjg@1735 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
jjg@1364 28 import java.io.IOException;
jjg@1364 29
bpatel@233 30 import com.sun.javadoc.*;
jjg@1357 31 import com.sun.tools.doclets.formats.html.markup.*;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.*;
jjg@1357 33 import com.sun.tools.doclets.internal.toolkit.builders.*;
duke@1 34 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 35
duke@1 36 /**
duke@1 37 * Generate the Class Information Page.
jjg@1359 38 *
jjg@1359 39 * <p><b>This is NOT part of any supported API.
jjg@1359 40 * If you write code that depends on this, you do so at your own risk.
jjg@1359 41 * This code and its internal interfaces are subject to change or
jjg@1359 42 * deletion without notice.</b>
jjg@1359 43 *
duke@1 44 * @see com.sun.javadoc.ClassDoc
duke@1 45 * @see java.util.Collections
duke@1 46 * @see java.util.List
duke@1 47 * @see java.util.ArrayList
duke@1 48 * @see java.util.HashMap
duke@1 49 *
duke@1 50 * @author Atul M Dambalkar
duke@1 51 * @author Robert Field
bpatel@766 52 * @author Bhavesh Patel (Modified)
duke@1 53 */
duke@1 54 public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
duke@1 55 implements AnnotationTypeWriter {
duke@1 56
duke@1 57 protected AnnotationTypeDoc annotationType;
duke@1 58
duke@1 59 protected Type prev;
duke@1 60
duke@1 61 protected Type next;
duke@1 62
duke@1 63 /**
duke@1 64 * @param annotationType the annotation type being documented.
duke@1 65 * @param prevType the previous class that was documented.
duke@1 66 * @param nextType the next class being documented.
duke@1 67 */
jjg@1410 68 public AnnotationTypeWriterImpl(ConfigurationImpl configuration,
jjg@1410 69 AnnotationTypeDoc annotationType, Type prevType, Type nextType)
jjg@1372 70 throws Exception {
jjg@1410 71 super(configuration, DocPath.forClass(annotationType));
duke@1 72 this.annotationType = annotationType;
duke@1 73 configuration.currentcd = annotationType.asClassDoc();
duke@1 74 this.prev = prevType;
duke@1 75 this.next = nextType;
duke@1 76 }
duke@1 77
duke@1 78 /**
bpatel@766 79 * Get this package link.
bpatel@766 80 *
bpatel@766 81 * @return a content tree for the package link
duke@1 82 */
bpatel@766 83 protected Content getNavLinkPackage() {
jjg@1373 84 Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
bpatel@766 85 packageLabel);
bpatel@766 86 Content li = HtmlTree.LI(linkContent);
bpatel@766 87 return li;
duke@1 88 }
duke@1 89
duke@1 90 /**
bpatel@766 91 * Get the class link.
bpatel@766 92 *
bpatel@766 93 * @return a content tree for the class link
duke@1 94 */
bpatel@766 95 protected Content getNavLinkClass() {
bpatel@766 96 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel);
bpatel@766 97 return li;
duke@1 98 }
duke@1 99
duke@1 100 /**
bpatel@766 101 * Get the class use link.
bpatel@766 102 *
bpatel@766 103 * @return a content tree for the class use link
duke@1 104 */
bpatel@766 105 protected Content getNavLinkClassUse() {
jjg@1373 106 Content linkContent = getHyperLink(DocPaths.CLASS_USE.resolve(filename), useLabel);
bpatel@766 107 Content li = HtmlTree.LI(linkContent);
bpatel@766 108 return li;
duke@1 109 }
duke@1 110
duke@1 111 /**
bpatel@766 112 * Get link to previous class.
bpatel@766 113 *
bpatel@766 114 * @return a content tree for the previous class link
duke@1 115 */
bpatel@766 116 public Content getNavLinkPrevious() {
bpatel@766 117 Content li;
bpatel@766 118 if (prev != null) {
jjg@1736 119 Content prevLink = getLink(new LinkInfoImpl(configuration,
jjg@1738 120 LinkInfoImpl.Kind.CLASS, prev.asClassDoc())
jjg@1993 121 .label(prevclassLabel).strong(true));
bpatel@766 122 li = HtmlTree.LI(prevLink);
duke@1 123 }
bpatel@766 124 else
bpatel@766 125 li = HtmlTree.LI(prevclassLabel);
bpatel@766 126 return li;
duke@1 127 }
duke@1 128
duke@1 129 /**
bpatel@766 130 * Get link to next class.
bpatel@766 131 *
bpatel@766 132 * @return a content tree for the next class link
duke@1 133 */
bpatel@766 134 public Content getNavLinkNext() {
bpatel@766 135 Content li;
bpatel@766 136 if (next != null) {
jjg@1736 137 Content nextLink = getLink(new LinkInfoImpl(configuration,
jjg@1738 138 LinkInfoImpl.Kind.CLASS, next.asClassDoc())
jjg@1993 139 .label(nextclassLabel).strong(true));
bpatel@766 140 li = HtmlTree.LI(nextLink);
duke@1 141 }
bpatel@766 142 else
bpatel@766 143 li = HtmlTree.LI(nextclassLabel);
bpatel@766 144 return li;
duke@1 145 }
duke@1 146
duke@1 147 /**
duke@1 148 * {@inheritDoc}
duke@1 149 */
bpatel@766 150 public Content getHeader(String header) {
duke@1 151 String pkgname = (annotationType.containingPackage() != null)?
duke@1 152 annotationType.containingPackage().name(): "";
duke@1 153 String clname = annotationType.name();
bpatel@766 154 Content bodyTree = getBody(true, getWindowTitle(clname));
bpatel@766 155 addTop(bodyTree);
bpatel@766 156 addNavLinks(true, bodyTree);
bpatel@766 157 bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
bpatel@766 158 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 159 div.addStyle(HtmlStyle.header);
duke@1 160 if (pkgname.length() > 0) {
bpatel@766 161 Content pkgNameContent = new StringContent(pkgname);
bpatel@943 162 Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent);
bpatel@943 163 div.addContent(pkgNameDiv);
duke@1 164 }
jjg@1410 165 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
jjg@1738 166 LinkInfoImpl.Kind.CLASS_HEADER, annotationType);
bpatel@766 167 Content headerContent = new StringContent(header);
bpatel@766 168 Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
bpatel@766 169 HtmlStyle.title, headerContent);
jjg@1736 170 heading.addContent(getTypeParameterLinks(linkInfo));
bpatel@766 171 div.addContent(heading);
bpatel@766 172 bodyTree.addContent(div);
bpatel@766 173 return bodyTree;
duke@1 174 }
duke@1 175
duke@1 176 /**
duke@1 177 * {@inheritDoc}
duke@1 178 */
bpatel@766 179 public Content getAnnotationContentHeader() {
bpatel@766 180 return getContentHeader();
duke@1 181 }
duke@1 182
duke@1 183 /**
duke@1 184 * {@inheritDoc}
duke@1 185 */
bpatel@766 186 public void addFooter(Content contentTree) {
bpatel@766 187 contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
bpatel@766 188 addNavLinks(false, contentTree);
bpatel@766 189 addBottom(contentTree);
duke@1 190 }
duke@1 191
duke@1 192 /**
duke@1 193 * {@inheritDoc}
duke@1 194 */
jjg@1364 195 public void printDocument(Content contentTree) throws IOException {
bpatel@766 196 printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
bpatel@766 197 true, contentTree);
bpatel@766 198 }
bpatel@766 199
bpatel@766 200 /**
bpatel@766 201 * {@inheritDoc}
bpatel@766 202 */
bpatel@766 203 public Content getAnnotationInfoTreeHeader() {
bpatel@766 204 return getMemberTreeHeader();
bpatel@766 205 }
bpatel@766 206
bpatel@766 207 /**
bpatel@766 208 * {@inheritDoc}
bpatel@766 209 */
bpatel@766 210 public Content getAnnotationInfo(Content annotationInfoTree) {
bpatel@766 211 return getMemberTree(HtmlStyle.description, annotationInfoTree);
bpatel@766 212 }
bpatel@766 213
bpatel@766 214 /**
bpatel@766 215 * {@inheritDoc}
bpatel@766 216 */
bpatel@766 217 public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) {
bpatel@766 218 annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR));
bpatel@766 219 Content pre = new HtmlTree(HtmlTag.PRE);
bpatel@766 220 addAnnotationInfo(annotationType, pre);
bpatel@766 221 pre.addContent(modifiers);
jjg@1410 222 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
jjg@1738 223 LinkInfoImpl.Kind.CLASS_SIGNATURE, annotationType);
bpatel@958 224 Content annotationName = new StringContent(annotationType.name());
jjg@1736 225 Content parameterLinks = getTypeParameterLinks(linkInfo);
jjg@1410 226 if (configuration.linksource) {
bpatel@958 227 addSrcLink(annotationType, annotationName, pre);
bpatel@958 228 pre.addContent(parameterLinks);
bpatel@766 229 } else {
bpatel@2147 230 Content span = HtmlTree.SPAN(HtmlStyle.memberNameLabel, annotationName);
bpatel@958 231 span.addContent(parameterLinks);
bpatel@958 232 pre.addContent(span);
bpatel@766 233 }
bpatel@766 234 annotationInfoTree.addContent(pre);
bpatel@766 235 }
bpatel@766 236
bpatel@766 237 /**
bpatel@766 238 * {@inheritDoc}
bpatel@766 239 */
bpatel@766 240 public void addAnnotationTypeDescription(Content annotationInfoTree) {
duke@1 241 if(!configuration.nocomment) {
duke@1 242 if (annotationType.inlineTags().length > 0) {
bpatel@766 243 addInlineComment(annotationType, annotationInfoTree);
duke@1 244 }
duke@1 245 }
duke@1 246 }
duke@1 247
duke@1 248 /**
duke@1 249 * {@inheritDoc}
duke@1 250 */
bpatel@766 251 public void addAnnotationTypeTagInfo(Content annotationInfoTree) {
duke@1 252 if(!configuration.nocomment) {
bpatel@766 253 addTagsInfo(annotationType, annotationInfoTree);
duke@1 254 }
duke@1 255 }
duke@1 256
duke@1 257 /**
duke@1 258 * {@inheritDoc}
duke@1 259 */
bpatel@766 260 public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) {
bpatel@766 261 Content hr = new HtmlTree(HtmlTag.HR);
bpatel@766 262 annotationInfoTree.addContent(hr);
duke@1 263 Tag[] deprs = annotationType.tags("deprecated");
duke@1 264 if (Util.isDeprecated(annotationType)) {
bpatel@2147 265 Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase);
bpatel@2147 266 Content div = HtmlTree.DIV(HtmlStyle.block, deprLabel);
duke@1 267 if (deprs.length > 0) {
duke@1 268 Tag[] commentTags = deprs[0].inlineTags();
duke@1 269 if (commentTags.length > 0) {
bpatel@766 270 div.addContent(getSpace());
bpatel@766 271 addInlineDeprecatedComment(annotationType, deprs[0], div);
duke@1 272 }
duke@1 273 }
bpatel@766 274 annotationInfoTree.addContent(div);
duke@1 275 }
duke@1 276 }
duke@1 277
bpatel@766 278 /**
bpatel@766 279 * {@inheritDoc}
bpatel@766 280 */
bpatel@766 281 protected Content getNavLinkTree() {
jjg@1372 282 Content treeLinkContent = getHyperLink(DocPaths.PACKAGE_TREE,
jjg@1373 283 treeLabel, "", "");
bpatel@766 284 Content li = HtmlTree.LI(treeLinkContent);
bpatel@766 285 return li;
bpatel@766 286 }
bpatel@766 287
bpatel@766 288 /**
bpatel@766 289 * Add summary details to the navigation bar.
bpatel@766 290 *
bpatel@766 291 * @param subDiv the content tree to which the summary detail links will be added
bpatel@766 292 */
bpatel@766 293 protected void addSummaryDetailLinks(Content subDiv) {
duke@1 294 try {
bpatel@766 295 Content div = HtmlTree.DIV(getNavSummaryLinks());
bpatel@766 296 div.addContent(getNavDetailLinks());
bpatel@766 297 subDiv.addContent(div);
duke@1 298 } catch (Exception e) {
duke@1 299 e.printStackTrace();
jjg@1985 300 throw new DocletAbortException(e);
duke@1 301 }
duke@1 302 }
duke@1 303
bpatel@766 304 /**
bpatel@766 305 * Get summary links for navigation bar.
bpatel@766 306 *
bpatel@766 307 * @return the content tree for the navigation summary links
bpatel@766 308 */
bpatel@766 309 protected Content getNavSummaryLinks() throws Exception {
bpatel@766 310 Content li = HtmlTree.LI(summaryLabel);
bpatel@766 311 li.addContent(getSpace());
bpatel@766 312 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
duke@1 313 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
bpatel@766 314 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
bpatel@2035 315 Content liNavField = new HtmlTree(HtmlTag.LI);
bpatel@2035 316 addNavSummaryLink(memberSummaryBuilder,
bpatel@2035 317 "doclet.navField",
bpatel@2035 318 VisibleMemberMap.ANNOTATION_TYPE_FIELDS, liNavField);
bpatel@2035 319 addNavGap(liNavField);
bpatel@2035 320 ulNav.addContent(liNavField);
bpatel@766 321 Content liNavReq = new HtmlTree(HtmlTag.LI);
bpatel@766 322 addNavSummaryLink(memberSummaryBuilder,
bpatel@766 323 "doclet.navAnnotationTypeRequiredMember",
bpatel@766 324 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq);
bpatel@766 325 addNavGap(liNavReq);
bpatel@766 326 ulNav.addContent(liNavReq);
bpatel@766 327 Content liNavOpt = new HtmlTree(HtmlTag.LI);
bpatel@766 328 addNavSummaryLink(memberSummaryBuilder,
bpatel@766 329 "doclet.navAnnotationTypeOptionalMember",
bpatel@766 330 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt);
bpatel@766 331 ulNav.addContent(liNavOpt);
bpatel@766 332 return ulNav;
duke@1 333 }
duke@1 334
bpatel@766 335 /**
bpatel@766 336 * Add the navigation summary link.
bpatel@766 337 *
bpatel@766 338 * @param builder builder for the member to be documented
bpatel@766 339 * @param label the label for the navigation
bpatel@766 340 * @param type type to be documented
bpatel@766 341 * @param liNav the content tree to which the navigation summary link will be added
bpatel@766 342 */
bpatel@766 343 protected void addNavSummaryLink(MemberSummaryBuilder builder,
bpatel@766 344 String label, int type, Content liNav) {
duke@1 345 AbstractMemberWriter writer = ((AbstractMemberWriter) builder.
bpatel@766 346 getMemberSummaryWriter(type));
duke@1 347 if (writer == null) {
bpatel@766 348 liNav.addContent(getResource(label));
duke@1 349 } else {
bpatel@766 350 liNav.addContent(writer.getNavSummaryLink(null,
bpatel@766 351 ! builder.getVisibleMemberMap(type).noVisibleMembers()));
duke@1 352 }
duke@1 353 }
duke@1 354
duke@1 355 /**
bpatel@766 356 * Get detail links for the navigation bar.
duke@1 357 *
bpatel@766 358 * @return the content tree for the detail links
duke@1 359 */
bpatel@766 360 protected Content getNavDetailLinks() throws Exception {
bpatel@766 361 Content li = HtmlTree.LI(detailLabel);
bpatel@766 362 li.addContent(getSpace());
bpatel@766 363 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
duke@1 364 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
bpatel@766 365 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
bpatel@2035 366 AbstractMemberWriter writerField =
bpatel@2035 367 ((AbstractMemberWriter) memberSummaryBuilder.
bpatel@2035 368 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_FIELDS));
duke@1 369 AbstractMemberWriter writerOptional =
bpatel@766 370 ((AbstractMemberWriter) memberSummaryBuilder.
duke@1 371 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
duke@1 372 AbstractMemberWriter writerRequired =
bpatel@766 373 ((AbstractMemberWriter) memberSummaryBuilder.
duke@1 374 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
bpatel@2035 375 Content liNavField = new HtmlTree(HtmlTag.LI);
bpatel@2035 376 if (writerField != null){
bpatel@2035 377 writerField.addNavDetailLink(annotationType.fields().length > 0, liNavField);
bpatel@2035 378 } else {
bpatel@2035 379 liNavField.addContent(getResource("doclet.navField"));
bpatel@2035 380 }
bpatel@2035 381 addNavGap(liNavField);
bpatel@2035 382 ulNav.addContent(liNavField);
duke@1 383 if (writerOptional != null){
bpatel@766 384 Content liNavOpt = new HtmlTree(HtmlTag.LI);
bpatel@766 385 writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt);
bpatel@766 386 ulNav.addContent(liNavOpt);
duke@1 387 } else if (writerRequired != null){
bpatel@766 388 Content liNavReq = new HtmlTree(HtmlTag.LI);
bpatel@766 389 writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq);
bpatel@766 390 ulNav.addContent(liNavReq);
duke@1 391 } else {
bpatel@766 392 Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember"));
bpatel@766 393 ulNav.addContent(liNav);
duke@1 394 }
bpatel@766 395 return ulNav;
duke@1 396 }
duke@1 397
duke@1 398 /**
bpatel@766 399 * Add gap between navigation bar elements.
bpatel@766 400 *
bpatel@766 401 * @param liNav the content tree to which the gap will be added
duke@1 402 */
bpatel@766 403 protected void addNavGap(Content liNav) {
bpatel@766 404 liNav.addContent(getSpace());
bpatel@766 405 liNav.addContent("|");
bpatel@766 406 liNav.addContent(getSpace());
duke@1 407 }
duke@1 408
duke@1 409 /**
duke@1 410 * {@inheritDoc}
duke@1 411 */
duke@1 412 public AnnotationTypeDoc getAnnotationTypeDoc() {
duke@1 413 return annotationType;
duke@1 414 }
duke@1 415 }

mercurial