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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 958
734144b6b22f
child 1359
25e14ad23cef
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

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

mercurial