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

Tue, 23 Oct 2012 13:20:37 -0700

author
jjg
date
Tue, 23 Oct 2012 13:20:37 -0700
changeset 1372
78962d89f283
parent 1359
25e14ad23cef
child 1410
bfec2a1cc869
permissions
-rw-r--r--

8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 1998, 2012, 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 java.io.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.formats.html.markup.*;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 /**
    37  * Generate Index for all the Member Names with Indexing in
    38  * Unicode Order. This class is a base class for {@link SingleIndexWriter} and
    39  * {@link SplitIndexWriter}. It uses the functionality from
    40  * {@link HtmlDocletWriter} to generate the Index Contents.
    41  *
    42  *  <p><b>This is NOT part of any supported API.
    43  *  If you write code that depends on this, you do so at your own risk.
    44  *  This code and its internal interfaces are subject to change or
    45  *  deletion without notice.</b>
    46  *
    47  * @see    IndexBuilder
    48  * @author Atul M Dambalkar
    49  * @author Bhavesh Patel (Modified)
    50  */
    51 public class AbstractIndexWriter extends HtmlDocletWriter {
    53     /**
    54      * The index of all the members with unicode character.
    55      */
    56     protected IndexBuilder indexbuilder;
    58     /**
    59      * This constructor will be used by {@link SplitIndexWriter}. Initializes
    60      * path to this file and relative path from this file.
    61      *
    62      * @param configuration  The current configuration
    63      * @param path       Path to the file which is getting generated.
    64      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
    65      */
    66     protected AbstractIndexWriter(ConfigurationImpl configuration,
    67                                   DocPath path,
    68                                   IndexBuilder indexbuilder)
    69                                   throws IOException {
    70         super(configuration, path);
    71         this.indexbuilder = indexbuilder;
    72     }
    74     /**
    75      * Get the index label for navigation bar.
    76      *
    77      * @return a content tree for the tree label
    78      */
    79     protected Content getNavLinkIndex() {
    80         Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, indexLabel);
    81         return li;
    82     }
    84     /**
    85      * Add the member information for the unicode character along with the
    86      * list of the members.
    87      *
    88      * @param unicode Unicode for which member list information to be generated
    89      * @param memberlist List of members for the unicode character
    90      * @param contentTree the content tree to which the information will be added
    91      */
    92     protected void addContents(Character unicode, List<? extends Doc> memberlist,
    93             Content contentTree) {
    94         contentTree.addContent(getMarkerAnchor("_" + unicode + "_"));
    95         Content headContent = new StringContent(unicode.toString());
    96         Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, false,
    97                 HtmlStyle.title, headContent);
    98         contentTree.addContent(heading);
    99         int memberListSize = memberlist.size();
   100         // Display the list only if there are elements to be displayed.
   101         if (memberListSize > 0) {
   102             Content dl = new HtmlTree(HtmlTag.DL);
   103             for (int i = 0; i < memberListSize; i++) {
   104                 Doc element = memberlist.get(i);
   105                 if (element instanceof MemberDoc) {
   106                     addDescription((MemberDoc)element, dl);
   107                 } else if (element instanceof ClassDoc) {
   108                     addDescription((ClassDoc)element, dl);
   109                 } else if (element instanceof PackageDoc) {
   110                     addDescription((PackageDoc)element, dl);
   111                 }
   112             }
   113             contentTree.addContent(dl);
   114         }
   115     }
   117     /**
   118      * Add one line summary comment for the package.
   119      *
   120      * @param pkg the package to be documented
   121      * @param dlTree the content tree to which the description will be added
   122      */
   123     protected void addDescription(PackageDoc pkg, Content dlTree) {
   124         Content link = getPackageLink(pkg, new StringContent(Util.getPackageName(pkg)));
   125         Content dt = HtmlTree.DT(link);
   126         dt.addContent(" - ");
   127         dt.addContent(getResource("doclet.package"));
   128         dt.addContent(" " + pkg.name());
   129         dlTree.addContent(dt);
   130         Content dd = new HtmlTree(HtmlTag.DD);
   131         addSummaryComment(pkg, dd);
   132         dlTree.addContent(dd);
   133     }
   135     /**
   136      * Add one line summary comment for the class.
   137      *
   138      * @param cd the class being documented
   139      * @param dlTree the content tree to which the description will be added
   140      */
   141     protected void addDescription(ClassDoc cd, Content dlTree) {
   142         Content link = new RawHtml(
   143                 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true)));
   144         Content dt = HtmlTree.DT(link);
   145         dt.addContent(" - ");
   146         addClassInfo(cd, dt);
   147         dlTree.addContent(dt);
   148         Content dd = new HtmlTree(HtmlTag.DD);
   149         addComment(cd, dd);
   150         dlTree.addContent(dd);
   151     }
   153     /**
   154      * Add the classkind(class, interface, exception, error of the class
   155      * passed.
   156      *
   157      * @param cd the class being documented
   158      * @param contentTree the content tree to which the class info will be added
   159      */
   160     protected void addClassInfo(ClassDoc cd, Content contentTree) {
   161         contentTree.addContent(getResource("doclet.in",
   162                 Util.getTypeName(configuration, cd, false),
   163                 getPackageLinkString(cd.containingPackage(),
   164                 Util.getPackageName(cd.containingPackage()), false)));
   165     }
   167     /**
   168      * Add description for Class, Field, Method or Constructor.
   169      *
   170      * @param member MemberDoc for the member of the Class Kind
   171      * @param dlTree the content tree to which the description will be added
   172      */
   173     protected void addDescription(MemberDoc member, Content dlTree) {
   174         String name = (member instanceof ExecutableMemberDoc)?
   175             member.name() + ((ExecutableMemberDoc)member).flatSignature() :
   176             member.name();
   177         if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
   178                 name = Util.escapeHtmlChars(name);
   179         }
   180         Content span = HtmlTree.SPAN(HtmlStyle.strong,
   181                 getDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name));
   182         Content dt = HtmlTree.DT(span);
   183         dt.addContent(" - ");
   184         addMemberDesc(member, dt);
   185         dlTree.addContent(dt);
   186         Content dd = new HtmlTree(HtmlTag.DD);
   187         addComment(member, dd);
   188         dlTree.addContent(dd);
   189     }
   191     /**
   192      * Add comment for each element in the index. If the element is deprecated
   193      * and it has a @deprecated tag, use that comment. Else if the containing
   194      * class for this element is deprecated, then add the word "Deprecated." at
   195      * the start and then print the normal comment.
   196      *
   197      * @param element Index element
   198      * @param contentTree the content tree to which the comment will be added
   199      */
   200     protected void addComment(ProgramElementDoc element, Content contentTree) {
   201         Tag[] tags;
   202         Content span = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
   203         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   204         div.addStyle(HtmlStyle.block);
   205         if (Util.isDeprecated(element)) {
   206             div.addContent(span);
   207             if ((tags = element.tags("deprecated")).length > 0)
   208                 addInlineDeprecatedComment(element, tags[0], div);
   209             contentTree.addContent(div);
   210         } else {
   211             ClassDoc cont = element.containingClass();
   212             while (cont != null) {
   213                 if (Util.isDeprecated(cont)) {
   214                     div.addContent(span);
   215                     contentTree.addContent(div);
   216                     break;
   217                 }
   218                 cont = cont.containingClass();
   219             }
   220             addSummaryComment(element, contentTree);
   221         }
   222     }
   224     /**
   225      * Add description about the Static Varible/Method/Constructor for a
   226      * member.
   227      *
   228      * @param member MemberDoc for the member within the Class Kind
   229      * @param contentTree the content tree to which the member description will be added
   230      */
   231     protected void addMemberDesc(MemberDoc member, Content contentTree) {
   232         ClassDoc containing = member.containingClass();
   233         String classdesc = Util.getTypeName(
   234                 configuration, containing, true) + " ";
   235         if (member.isField()) {
   236             if (member.isStatic()) {
   237                 contentTree.addContent(
   238                         getResource("doclet.Static_variable_in", classdesc));
   239             } else {
   240                 contentTree.addContent(
   241                         getResource("doclet.Variable_in", classdesc));
   242             }
   243         } else if (member.isConstructor()) {
   244             contentTree.addContent(
   245                     getResource("doclet.Constructor_for", classdesc));
   246         } else if (member.isMethod()) {
   247             if (member.isStatic()) {
   248                 contentTree.addContent(
   249                         getResource("doclet.Static_method_in", classdesc));
   250             } else {
   251                 contentTree.addContent(
   252                         getResource("doclet.Method_in", classdesc));
   253             }
   254         }
   255         addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing,
   256                 false, contentTree);
   257     }
   258 }

mercurial