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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 182
47a62d8d98b4
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 1998-2004 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import com.sun.tools.doclets.internal.toolkit.util.*;
    30 import com.sun.javadoc.*;
    31 import java.io.*;
    32 import java.util.*;
    34 /**
    35  * Generate Index for all the Member Names with Indexing in
    36  * Unicode Order. This class is a base class for {@link SingleIndexWriter} and
    37  * {@link SplitIndexWriter}. It uses the functionality from
    38  * {@link HtmlDocletWriter} to generate the Index Contents.
    39  *
    40  * @see    IndexBuilder
    41  * @author Atul M Dambalkar
    42  */
    43 public class AbstractIndexWriter extends HtmlDocletWriter {
    45     /**
    46      * The index of all the members with unicode character.
    47      */
    48     protected IndexBuilder indexbuilder;
    50     /**
    51      * This constructor will be used by {@link SplitIndexWriter}. Initialises
    52      * path to this file and relative path from this file.
    53      *
    54      * @param path       Path to the file which is getting generated.
    55      * @param filename   Name of the file which is getting genrated.
    56      * @param relpath    Relative path from this file to the current directory.
    57      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
    58      */
    59     protected AbstractIndexWriter(ConfigurationImpl configuration,
    60                                   String path, String filename,
    61                                   String relpath, IndexBuilder indexbuilder)
    62                                   throws IOException {
    63         super(configuration, path, filename, relpath);
    64         this.indexbuilder = indexbuilder;
    65     }
    67     /**
    68      * This Constructor will be used by {@link SingleIndexWriter}.
    69      *
    70      * @param filename   Name of the file which is getting genrated.
    71      * @param indexbuilder Unicode based Index form {@link IndexBuilder}
    72      */
    73     protected AbstractIndexWriter(ConfigurationImpl configuration,
    74                                   String filename, IndexBuilder indexbuilder)
    75                                   throws IOException {
    76         super(configuration, filename);
    77         this.indexbuilder = indexbuilder;
    78     }
    80     /**
    81      * Print the text "Index" in bold format in the navigation bar.
    82      */
    83     protected void navLinkIndex() {
    84         navCellRevStart();
    85         fontStyle("NavBarFont1Rev");
    86         boldText("doclet.Index");
    87         fontEnd();
    88         navCellEnd();
    89     }
    91     /**
    92      * Generate the member information for the unicode character along with the
    93      * list of the members.
    94      *
    95      * @param unicode Unicode for which member list information to be generated.
    96      * @param memberlist List of members for the unicode character.
    97      */
    98     protected void generateContents(Character unicode, List memberlist) {
    99         anchor("_" + unicode + "_");
   100         h2();
   101         bold(unicode.toString());
   102         h2End();
   103         dl();
   104         for (int i = 0; i < memberlist.size(); i++) {
   105             Doc element = (Doc)memberlist.get(i);
   106             if (element instanceof MemberDoc) {
   107                 printDescription((MemberDoc)element);
   108             } else if (element instanceof ClassDoc) {
   109                 printDescription((ClassDoc)element);
   110             } else if (element instanceof PackageDoc) {
   111                 printDescription((PackageDoc)element);
   112             }
   113         }
   114         dlEnd();
   115         hr();
   116     }
   119     /**
   120      * Print one line summary comment for the package.
   121      *
   122      * @param pkg PackageDoc passed.
   123      */
   124     protected void printDescription(PackageDoc pkg) {
   125         dt();
   126         printPackageLink(pkg, Util.getPackageName(pkg), true);
   127         print(" - ");
   128         print(configuration.getText("doclet.package") + " " + pkg.name());
   129         dd();
   130         printSummaryComment(pkg);
   131     }
   133     /**
   134      * Print one line summary comment for the class.
   135      *
   136      * @param cd ClassDoc passed.
   137      */
   138     protected void printDescription(ClassDoc cd) {
   139         dt();
   140         printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true));
   141         print(" - ");
   142         printClassInfo(cd);
   143         dd();
   144         printComment(cd);
   145     }
   147     /**
   148      * Print the classkind(class, interface, exception, error of the class
   149      * passed.
   150      *
   151      * @param cd ClassDoc.
   152      */
   153     protected void printClassInfo(ClassDoc cd) {
   154         print(configuration.getText("doclet.in",
   155             Util.getTypeName(configuration, cd, false),
   156             getPackageLink(cd.containingPackage(),
   157                 Util.getPackageName(cd.containingPackage()), false)));
   158     }
   161     /**
   162      * Generate Description for Class, Field, Method or Constructor.
   163      * for Java.* Packages Class Members.
   164      *
   165      * @param member MemberDoc for the member of the Class Kind.
   166      * @see com.sun.javadoc.MemberDoc
   167      */
   168     protected void printDescription(MemberDoc member) {
   169         String name = (member instanceof ExecutableMemberDoc)?
   170             member.name() + ((ExecutableMemberDoc)member).flatSignature() :
   171             member.name();
   172         if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
   173                 name = Util.escapeHtmlChars(name);
   174         }
   175         ClassDoc containing = member.containingClass();
   176         dt();
   177         printDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name, true);
   178         println(" - ");
   179         printMemberDesc(member);
   180         println();
   181         dd();
   182         printComment(member);
   183         println();
   184     }
   187     /**
   188      * Print comment for each element in the index. If the element is deprecated
   189      * and it has a @deprecated tag, use that comment. Else if the containing
   190      * class for this element is deprecated, then add the word "Deprecated." at
   191      * the start and then print the normal comment.
   192      *
   193      * @param element Index element.
   194      */
   195     protected void printComment(ProgramElementDoc element) {
   196         Tag[] tags;
   197         if (Util.isDeprecated(element)) {
   198             boldText("doclet.Deprecated"); space();
   199             if ((tags = element.tags("deprecated")).length > 0)
   200                 printInlineDeprecatedComment(element, tags[0]);
   201         } else {
   202             ClassDoc cont = element.containingClass();
   203             while (cont != null) {
   204                 if (Util.isDeprecated(cont)) {
   205                     boldText("doclet.Deprecated"); space();
   206                     break;
   207                 }
   208                 cont = cont.containingClass();
   209             }
   210             printSummaryComment(element);
   211         }
   212     }
   214     /**
   215      * Print description about the Static Varible/Method/Constructor for a
   216      * member.
   217      *
   218      * @param member MemberDoc for the member within the Class Kind.
   219      * @see com.sun.javadoc.MemberDoc
   220      */
   221     protected void printMemberDesc(MemberDoc member) {
   222         ClassDoc containing = member.containingClass();
   223         String classdesc = Util.getTypeName(configuration, containing, true) + " " +
   224             getPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing,
   225                 false);
   226         if (member.isField()) {
   227             if (member.isStatic()) {
   228                 printText("doclet.Static_variable_in", classdesc);
   229             } else {
   230                 printText("doclet.Variable_in", classdesc);
   231             }
   232         } else if (member.isConstructor()) {
   233             printText("doclet.Constructor_for", classdesc);
   234         } else if (member.isMethod()) {
   235             if (member.isStatic()) {
   236                 printText("doclet.Static_method_in", classdesc);
   237             } else {
   238                 printText("doclet.Method_in", classdesc);
   239             }
   240         }
   241     }
   242 }

mercurial