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

Fri, 04 Mar 2011 19:53:03 -0800

author
jjg
date
Fri, 04 Mar 2011 19:53:03 -0800
changeset 910
ebf7c13df6c0
parent 798
4868a36f6fd8
child 943
72bdd232e0ea
permissions
-rw-r--r--

6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
Reviewed-by: bpatel

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

mercurial