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

Fri, 30 Aug 2013 11:48:36 -0700

author
jjg
date
Fri, 30 Aug 2013 11:48:36 -0700
changeset 1993
240f424cc0d5
parent 1985
0e6577980181
child 2035
a2a5ad0853ed
permissions
-rw-r--r--

8023700: Use non breaking space in various labels
Reviewed-by: bpatel

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@958 230 Content span = HtmlTree.SPAN(HtmlStyle.strong, 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@1935 265 Content strong = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
bpatel@766 266 Content div = HtmlTree.DIV(HtmlStyle.block, strong);
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 public void addAnnotationDetailsMarker(Content memberDetails) {
bpatel@766 282 memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
duke@1 283 }
duke@1 284
bpatel@766 285 /**
bpatel@766 286 * {@inheritDoc}
bpatel@766 287 */
bpatel@766 288 protected Content getNavLinkTree() {
jjg@1372 289 Content treeLinkContent = getHyperLink(DocPaths.PACKAGE_TREE,
jjg@1373 290 treeLabel, "", "");
bpatel@766 291 Content li = HtmlTree.LI(treeLinkContent);
bpatel@766 292 return li;
bpatel@766 293 }
bpatel@766 294
bpatel@766 295 /**
bpatel@766 296 * Add summary details to the navigation bar.
bpatel@766 297 *
bpatel@766 298 * @param subDiv the content tree to which the summary detail links will be added
bpatel@766 299 */
bpatel@766 300 protected void addSummaryDetailLinks(Content subDiv) {
duke@1 301 try {
bpatel@766 302 Content div = HtmlTree.DIV(getNavSummaryLinks());
bpatel@766 303 div.addContent(getNavDetailLinks());
bpatel@766 304 subDiv.addContent(div);
duke@1 305 } catch (Exception e) {
duke@1 306 e.printStackTrace();
jjg@1985 307 throw new DocletAbortException(e);
duke@1 308 }
duke@1 309 }
duke@1 310
bpatel@766 311 /**
bpatel@766 312 * Get summary links for navigation bar.
bpatel@766 313 *
bpatel@766 314 * @return the content tree for the navigation summary links
bpatel@766 315 */
bpatel@766 316 protected Content getNavSummaryLinks() throws Exception {
bpatel@766 317 Content li = HtmlTree.LI(summaryLabel);
bpatel@766 318 li.addContent(getSpace());
bpatel@766 319 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
duke@1 320 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
bpatel@766 321 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
bpatel@766 322 Content liNavReq = new HtmlTree(HtmlTag.LI);
bpatel@766 323 addNavSummaryLink(memberSummaryBuilder,
bpatel@766 324 "doclet.navAnnotationTypeRequiredMember",
bpatel@766 325 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq);
bpatel@766 326 addNavGap(liNavReq);
bpatel@766 327 ulNav.addContent(liNavReq);
bpatel@766 328 Content liNavOpt = new HtmlTree(HtmlTag.LI);
bpatel@766 329 addNavSummaryLink(memberSummaryBuilder,
bpatel@766 330 "doclet.navAnnotationTypeOptionalMember",
bpatel@766 331 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt);
bpatel@766 332 ulNav.addContent(liNavOpt);
bpatel@766 333 return ulNav;
duke@1 334 }
duke@1 335
bpatel@766 336 /**
bpatel@766 337 * Add the navigation summary link.
bpatel@766 338 *
bpatel@766 339 * @param builder builder for the member to be documented
bpatel@766 340 * @param label the label for the navigation
bpatel@766 341 * @param type type to be documented
bpatel@766 342 * @param liNav the content tree to which the navigation summary link will be added
bpatel@766 343 */
bpatel@766 344 protected void addNavSummaryLink(MemberSummaryBuilder builder,
bpatel@766 345 String label, int type, Content liNav) {
duke@1 346 AbstractMemberWriter writer = ((AbstractMemberWriter) builder.
bpatel@766 347 getMemberSummaryWriter(type));
duke@1 348 if (writer == null) {
bpatel@766 349 liNav.addContent(getResource(label));
duke@1 350 } else {
bpatel@766 351 liNav.addContent(writer.getNavSummaryLink(null,
bpatel@766 352 ! builder.getVisibleMemberMap(type).noVisibleMembers()));
duke@1 353 }
duke@1 354 }
duke@1 355
duke@1 356 /**
bpatel@766 357 * Get detail links for the navigation bar.
duke@1 358 *
bpatel@766 359 * @return the content tree for the detail links
duke@1 360 */
bpatel@766 361 protected Content getNavDetailLinks() throws Exception {
bpatel@766 362 Content li = HtmlTree.LI(detailLabel);
bpatel@766 363 li.addContent(getSpace());
bpatel@766 364 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
duke@1 365 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
bpatel@766 366 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
duke@1 367 AbstractMemberWriter writerOptional =
bpatel@766 368 ((AbstractMemberWriter) memberSummaryBuilder.
duke@1 369 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
duke@1 370 AbstractMemberWriter writerRequired =
bpatel@766 371 ((AbstractMemberWriter) memberSummaryBuilder.
duke@1 372 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
duke@1 373 if (writerOptional != null){
bpatel@766 374 Content liNavOpt = new HtmlTree(HtmlTag.LI);
bpatel@766 375 writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt);
bpatel@766 376 ulNav.addContent(liNavOpt);
duke@1 377 } else if (writerRequired != null){
bpatel@766 378 Content liNavReq = new HtmlTree(HtmlTag.LI);
bpatel@766 379 writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq);
bpatel@766 380 ulNav.addContent(liNavReq);
duke@1 381 } else {
bpatel@766 382 Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember"));
bpatel@766 383 ulNav.addContent(liNav);
duke@1 384 }
bpatel@766 385 return ulNav;
duke@1 386 }
duke@1 387
duke@1 388 /**
bpatel@766 389 * Add gap between navigation bar elements.
bpatel@766 390 *
bpatel@766 391 * @param liNav the content tree to which the gap will be added
duke@1 392 */
bpatel@766 393 protected void addNavGap(Content liNav) {
bpatel@766 394 liNav.addContent(getSpace());
bpatel@766 395 liNav.addContent("|");
bpatel@766 396 liNav.addContent(getSpace());
duke@1 397 }
duke@1 398
duke@1 399 /**
duke@1 400 * {@inheritDoc}
duke@1 401 */
duke@1 402 public AnnotationTypeDoc getAnnotationTypeDoc() {
duke@1 403 return annotationType;
duke@1 404 }
duke@1 405 }

mercurial