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

Mon, 15 Oct 2012 17:07:55 -0700

author
jjg
date
Mon, 15 Oct 2012 17:07:55 -0700
changeset 1364
8db45b13526e
parent 1359
25e14ad23cef
child 1372
78962d89f283
permissions
-rw-r--r--

8000666: javadoc should write directly to Writer instead of composing strings
Reviewed-by: bpatel

duke@1 1 /*
jjg@1357 2 * Copyright (c) 2003, 2012, 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 */
duke@1 68 public AnnotationTypeWriterImpl (AnnotationTypeDoc annotationType,
duke@1 69 Type prevType, Type nextType)
duke@1 70 throws Exception {
duke@1 71 super(ConfigurationImpl.getInstance(),
duke@1 72 DirectoryManager.getDirectoryPath(annotationType.containingPackage()),
duke@1 73 annotationType.name() + ".html",
duke@1 74 DirectoryManager.getRelativePath(annotationType.containingPackage().name()));
duke@1 75 this.annotationType = annotationType;
duke@1 76 configuration.currentcd = annotationType.asClassDoc();
duke@1 77 this.prev = prevType;
duke@1 78 this.next = nextType;
duke@1 79 }
duke@1 80
duke@1 81 /**
bpatel@766 82 * Get this package link.
bpatel@766 83 *
bpatel@766 84 * @return a content tree for the package link
duke@1 85 */
bpatel@766 86 protected Content getNavLinkPackage() {
bpatel@766 87 Content linkContent = getHyperLink("package-summary.html", "",
bpatel@766 88 packageLabel);
bpatel@766 89 Content li = HtmlTree.LI(linkContent);
bpatel@766 90 return li;
duke@1 91 }
duke@1 92
duke@1 93 /**
bpatel@766 94 * Get the class link.
bpatel@766 95 *
bpatel@766 96 * @return a content tree for the class link
duke@1 97 */
bpatel@766 98 protected Content getNavLinkClass() {
bpatel@766 99 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel);
bpatel@766 100 return li;
duke@1 101 }
duke@1 102
duke@1 103 /**
bpatel@766 104 * Get the class use link.
bpatel@766 105 *
bpatel@766 106 * @return a content tree for the class use link
duke@1 107 */
bpatel@766 108 protected Content getNavLinkClassUse() {
bpatel@766 109 Content linkContent = getHyperLink("class-use/" + filename, "", useLabel);
bpatel@766 110 Content li = HtmlTree.LI(linkContent);
bpatel@766 111 return li;
duke@1 112 }
duke@1 113
duke@1 114 /**
bpatel@766 115 * Get link to previous class.
bpatel@766 116 *
bpatel@766 117 * @return a content tree for the previous class link
duke@1 118 */
bpatel@766 119 public Content getNavLinkPrevious() {
bpatel@766 120 Content li;
bpatel@766 121 if (prev != null) {
bpatel@766 122 Content prevLink = new RawHtml(getLink(new LinkInfoImpl(
bpatel@766 123 LinkInfoImpl.CONTEXT_CLASS, prev.asClassDoc(), "",
bpatel@766 124 configuration.getText("doclet.Prev_Class"), true)));
bpatel@766 125 li = HtmlTree.LI(prevLink);
duke@1 126 }
bpatel@766 127 else
bpatel@766 128 li = HtmlTree.LI(prevclassLabel);
bpatel@766 129 return li;
duke@1 130 }
duke@1 131
duke@1 132 /**
bpatel@766 133 * Get link to next class.
bpatel@766 134 *
bpatel@766 135 * @return a content tree for the next class link
duke@1 136 */
bpatel@766 137 public Content getNavLinkNext() {
bpatel@766 138 Content li;
bpatel@766 139 if (next != null) {
bpatel@766 140 Content nextLink = new RawHtml(getLink(new LinkInfoImpl(
bpatel@766 141 LinkInfoImpl.CONTEXT_CLASS, next.asClassDoc(), "",
bpatel@766 142 configuration.getText("doclet.Next_Class"), true)));
bpatel@766 143 li = HtmlTree.LI(nextLink);
duke@1 144 }
bpatel@766 145 else
bpatel@766 146 li = HtmlTree.LI(nextclassLabel);
bpatel@766 147 return li;
duke@1 148 }
duke@1 149
duke@1 150 /**
duke@1 151 * {@inheritDoc}
duke@1 152 */
bpatel@766 153 public Content getHeader(String header) {
duke@1 154 String pkgname = (annotationType.containingPackage() != null)?
duke@1 155 annotationType.containingPackage().name(): "";
duke@1 156 String clname = annotationType.name();
bpatel@766 157 Content bodyTree = getBody(true, getWindowTitle(clname));
bpatel@766 158 addTop(bodyTree);
bpatel@766 159 addNavLinks(true, bodyTree);
bpatel@766 160 bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
bpatel@766 161 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 162 div.addStyle(HtmlStyle.header);
duke@1 163 if (pkgname.length() > 0) {
bpatel@766 164 Content pkgNameContent = new StringContent(pkgname);
bpatel@943 165 Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent);
bpatel@943 166 div.addContent(pkgNameDiv);
duke@1 167 }
bpatel@766 168 LinkInfoImpl linkInfo = new LinkInfoImpl(
bpatel@766 169 LinkInfoImpl.CONTEXT_CLASS_HEADER, annotationType, false);
bpatel@766 170 Content headerContent = new StringContent(header);
bpatel@766 171 Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
bpatel@766 172 HtmlStyle.title, headerContent);
bpatel@766 173 heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo)));
bpatel@766 174 div.addContent(heading);
bpatel@766 175 bodyTree.addContent(div);
bpatel@766 176 return bodyTree;
duke@1 177 }
duke@1 178
duke@1 179 /**
duke@1 180 * {@inheritDoc}
duke@1 181 */
bpatel@766 182 public Content getAnnotationContentHeader() {
bpatel@766 183 return getContentHeader();
duke@1 184 }
duke@1 185
duke@1 186 /**
duke@1 187 * {@inheritDoc}
duke@1 188 */
bpatel@766 189 public void addFooter(Content contentTree) {
bpatel@766 190 contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
bpatel@766 191 addNavLinks(false, contentTree);
bpatel@766 192 addBottom(contentTree);
duke@1 193 }
duke@1 194
duke@1 195 /**
duke@1 196 * {@inheritDoc}
duke@1 197 */
jjg@1364 198 public void printDocument(Content contentTree) throws IOException {
bpatel@766 199 printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
bpatel@766 200 true, contentTree);
bpatel@766 201 }
bpatel@766 202
bpatel@766 203 /**
bpatel@766 204 * {@inheritDoc}
bpatel@766 205 */
bpatel@766 206 public Content getAnnotationInfoTreeHeader() {
bpatel@766 207 return getMemberTreeHeader();
bpatel@766 208 }
bpatel@766 209
bpatel@766 210 /**
bpatel@766 211 * {@inheritDoc}
bpatel@766 212 */
bpatel@766 213 public Content getAnnotationInfo(Content annotationInfoTree) {
bpatel@766 214 return getMemberTree(HtmlStyle.description, annotationInfoTree);
bpatel@766 215 }
bpatel@766 216
bpatel@766 217 /**
bpatel@766 218 * {@inheritDoc}
bpatel@766 219 */
bpatel@766 220 public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) {
bpatel@766 221 annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR));
bpatel@766 222 Content pre = new HtmlTree(HtmlTag.PRE);
bpatel@766 223 addAnnotationInfo(annotationType, pre);
bpatel@766 224 pre.addContent(modifiers);
bpatel@766 225 LinkInfoImpl linkInfo = new LinkInfoImpl(
bpatel@766 226 LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false);
bpatel@958 227 Content annotationName = new StringContent(annotationType.name());
bpatel@958 228 Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo));
bpatel@766 229 if (configuration().linksource) {
bpatel@958 230 addSrcLink(annotationType, annotationName, pre);
bpatel@958 231 pre.addContent(parameterLinks);
bpatel@766 232 } else {
bpatel@958 233 Content span = HtmlTree.SPAN(HtmlStyle.strong, annotationName);
bpatel@958 234 span.addContent(parameterLinks);
bpatel@958 235 pre.addContent(span);
bpatel@766 236 }
bpatel@766 237 annotationInfoTree.addContent(pre);
bpatel@766 238 }
bpatel@766 239
bpatel@766 240 /**
bpatel@766 241 * {@inheritDoc}
bpatel@766 242 */
bpatel@766 243 public void addAnnotationTypeDescription(Content annotationInfoTree) {
duke@1 244 if(!configuration.nocomment) {
duke@1 245 if (annotationType.inlineTags().length > 0) {
bpatel@766 246 addInlineComment(annotationType, annotationInfoTree);
duke@1 247 }
duke@1 248 }
duke@1 249 }
duke@1 250
duke@1 251 /**
duke@1 252 * {@inheritDoc}
duke@1 253 */
bpatel@766 254 public void addAnnotationTypeTagInfo(Content annotationInfoTree) {
duke@1 255 if(!configuration.nocomment) {
bpatel@766 256 addTagsInfo(annotationType, annotationInfoTree);
duke@1 257 }
duke@1 258 }
duke@1 259
duke@1 260 /**
duke@1 261 * {@inheritDoc}
duke@1 262 */
bpatel@766 263 public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) {
bpatel@766 264 Content hr = new HtmlTree(HtmlTag.HR);
bpatel@766 265 annotationInfoTree.addContent(hr);
duke@1 266 Tag[] deprs = annotationType.tags("deprecated");
duke@1 267 if (Util.isDeprecated(annotationType)) {
bpatel@766 268 Content strong = HtmlTree.STRONG(deprecatedPhrase);
bpatel@766 269 Content div = HtmlTree.DIV(HtmlStyle.block, strong);
duke@1 270 if (deprs.length > 0) {
duke@1 271 Tag[] commentTags = deprs[0].inlineTags();
duke@1 272 if (commentTags.length > 0) {
bpatel@766 273 div.addContent(getSpace());
bpatel@766 274 addInlineDeprecatedComment(annotationType, deprs[0], div);
duke@1 275 }
duke@1 276 }
bpatel@766 277 annotationInfoTree.addContent(div);
duke@1 278 }
duke@1 279 }
duke@1 280
bpatel@766 281 /**
bpatel@766 282 * {@inheritDoc}
bpatel@766 283 */
bpatel@766 284 public void addAnnotationDetailsMarker(Content memberDetails) {
bpatel@766 285 memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
duke@1 286 }
duke@1 287
bpatel@766 288 /**
bpatel@766 289 * {@inheritDoc}
bpatel@766 290 */
bpatel@766 291 protected Content getNavLinkTree() {
bpatel@766 292 Content treeLinkContent = getHyperLink("package-tree.html",
bpatel@766 293 "", treeLabel, "", "");
bpatel@766 294 Content li = HtmlTree.LI(treeLinkContent);
bpatel@766 295 return li;
bpatel@766 296 }
bpatel@766 297
bpatel@766 298 /**
bpatel@766 299 * Add summary details to the navigation bar.
bpatel@766 300 *
bpatel@766 301 * @param subDiv the content tree to which the summary detail links will be added
bpatel@766 302 */
bpatel@766 303 protected void addSummaryDetailLinks(Content subDiv) {
duke@1 304 try {
bpatel@766 305 Content div = HtmlTree.DIV(getNavSummaryLinks());
bpatel@766 306 div.addContent(getNavDetailLinks());
bpatel@766 307 subDiv.addContent(div);
duke@1 308 } catch (Exception e) {
duke@1 309 e.printStackTrace();
duke@1 310 throw new DocletAbortException();
duke@1 311 }
duke@1 312 }
duke@1 313
bpatel@766 314 /**
bpatel@766 315 * Get summary links for navigation bar.
bpatel@766 316 *
bpatel@766 317 * @return the content tree for the navigation summary links
bpatel@766 318 */
bpatel@766 319 protected Content getNavSummaryLinks() throws Exception {
bpatel@766 320 Content li = HtmlTree.LI(summaryLabel);
bpatel@766 321 li.addContent(getSpace());
bpatel@766 322 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
duke@1 323 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
bpatel@766 324 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
bpatel@766 325 Content liNavReq = new HtmlTree(HtmlTag.LI);
bpatel@766 326 addNavSummaryLink(memberSummaryBuilder,
bpatel@766 327 "doclet.navAnnotationTypeRequiredMember",
bpatel@766 328 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq);
bpatel@766 329 addNavGap(liNavReq);
bpatel@766 330 ulNav.addContent(liNavReq);
bpatel@766 331 Content liNavOpt = new HtmlTree(HtmlTag.LI);
bpatel@766 332 addNavSummaryLink(memberSummaryBuilder,
bpatel@766 333 "doclet.navAnnotationTypeOptionalMember",
bpatel@766 334 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt);
bpatel@766 335 ulNav.addContent(liNavOpt);
bpatel@766 336 return ulNav;
duke@1 337 }
duke@1 338
bpatel@766 339 /**
bpatel@766 340 * Add the navigation summary link.
bpatel@766 341 *
bpatel@766 342 * @param builder builder for the member to be documented
bpatel@766 343 * @param label the label for the navigation
bpatel@766 344 * @param type type to be documented
bpatel@766 345 * @param liNav the content tree to which the navigation summary link will be added
bpatel@766 346 */
bpatel@766 347 protected void addNavSummaryLink(MemberSummaryBuilder builder,
bpatel@766 348 String label, int type, Content liNav) {
duke@1 349 AbstractMemberWriter writer = ((AbstractMemberWriter) builder.
bpatel@766 350 getMemberSummaryWriter(type));
duke@1 351 if (writer == null) {
bpatel@766 352 liNav.addContent(getResource(label));
duke@1 353 } else {
bpatel@766 354 liNav.addContent(writer.getNavSummaryLink(null,
bpatel@766 355 ! builder.getVisibleMemberMap(type).noVisibleMembers()));
duke@1 356 }
duke@1 357 }
duke@1 358
duke@1 359 /**
bpatel@766 360 * Get detail links for the navigation bar.
duke@1 361 *
bpatel@766 362 * @return the content tree for the detail links
duke@1 363 */
bpatel@766 364 protected Content getNavDetailLinks() throws Exception {
bpatel@766 365 Content li = HtmlTree.LI(detailLabel);
bpatel@766 366 li.addContent(getSpace());
bpatel@766 367 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
duke@1 368 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
bpatel@766 369 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
duke@1 370 AbstractMemberWriter writerOptional =
bpatel@766 371 ((AbstractMemberWriter) memberSummaryBuilder.
duke@1 372 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
duke@1 373 AbstractMemberWriter writerRequired =
bpatel@766 374 ((AbstractMemberWriter) memberSummaryBuilder.
duke@1 375 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
duke@1 376 if (writerOptional != null){
bpatel@766 377 Content liNavOpt = new HtmlTree(HtmlTag.LI);
bpatel@766 378 writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt);
bpatel@766 379 ulNav.addContent(liNavOpt);
duke@1 380 } else if (writerRequired != null){
bpatel@766 381 Content liNavReq = new HtmlTree(HtmlTag.LI);
bpatel@766 382 writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq);
bpatel@766 383 ulNav.addContent(liNavReq);
duke@1 384 } else {
bpatel@766 385 Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember"));
bpatel@766 386 ulNav.addContent(liNav);
duke@1 387 }
bpatel@766 388 return ulNav;
duke@1 389 }
duke@1 390
duke@1 391 /**
bpatel@766 392 * Add gap between navigation bar elements.
bpatel@766 393 *
bpatel@766 394 * @param liNav the content tree to which the gap will be added
duke@1 395 */
bpatel@766 396 protected void addNavGap(Content liNav) {
bpatel@766 397 liNav.addContent(getSpace());
bpatel@766 398 liNav.addContent("|");
bpatel@766 399 liNav.addContent(getSpace());
duke@1 400 }
duke@1 401
duke@1 402 /**
duke@1 403 * {@inheritDoc}
duke@1 404 */
duke@1 405 public AnnotationTypeDoc getAnnotationTypeDoc() {
duke@1 406 return annotationType;
duke@1 407 }
duke@1 408 }

mercurial