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

Mon, 13 Dec 2010 13:44:47 -0800

author
bpatel
date
Mon, 13 Dec 2010 13:44:47 -0800
changeset 793
ffbf2b2a8611
parent 766
90af8d87741f
child 798
4868a36f6fd8
permissions
-rw-r--r--

7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg

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

mercurial