home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / tooldocs / javadoc / source / standard / AbstractIndexWriter.java next >
Encoding:
Java Source  |  1999-09-19  |  7.5 KB  |  236 lines

  1. /*
  2.  * @(#)AbstractIndexWriter.java    1.7 98/04/17
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package com.sun.tools.doclets.standard;
  16.  
  17. import com.sun.tools.doclets.*;
  18. import com.sun.javadoc.*;
  19. import java.io.*;
  20. import java.lang.*;
  21. import java.util.*;
  22.  
  23. /**
  24.  * Generate Index for all the Member Names with Indexing in 
  25.  * Unicode Order. This class is a base class for {@link SingleIndexWriter} and
  26.  * {@link SplitIndexWriter}. It uses the functionality from
  27.  * {@link HtmlStandardWriter} and {@link HtmlWriter} to generate the Index 
  28.  * Contents.
  29.  *
  30.  * @see    IndexBuilder
  31.  * @author Atul M Dambalkar
  32.  */
  33. public class AbstractIndexWriter extends HtmlStandardWriter {
  34.  
  35.     /**
  36.      * The index of all the members with unicode character.
  37.      */
  38.     protected IndexBuilder indexbuilder;
  39.  
  40.     /**
  41.      * This constructor will be used by {@link SplitIndexWriter}. Initialises
  42.      * path to this file and relative path from this file.
  43.      * 
  44.      * @param path       Path to the file which is getting generated.
  45.      * @param filename   Name of the file which is getting genrated.
  46.      * @param relpath    Relative path from this file to the current directory.
  47.      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
  48.      */
  49.     protected AbstractIndexWriter(String path, String filename, 
  50.                                   String relpath, IndexBuilder indexbuilder) 
  51.                                   throws IOException {
  52.         super(path, filename, relpath);
  53.         this.indexbuilder = indexbuilder;
  54.     }
  55.  
  56.     /**
  57.      * This Constructor will be used by {@link SingleIndexWriter}.
  58.      * 
  59.      * @param filename   Name of the file which is getting genrated.
  60.      * @param indexbuilder Unicode based Index form {@link IndexBuilder}
  61.      */
  62.     protected AbstractIndexWriter(String filename, IndexBuilder indexbuilder) 
  63.                                   throws IOException {
  64.         super(filename);
  65.         this.indexbuilder = indexbuilder;
  66.     }
  67.  
  68.     /**
  69.      * Print the text "Index" in bold format in the navigation bar.
  70.      */
  71.     protected void navLinkIndex() {
  72.         navCellRevStart();
  73.         fontStyle("NavBarFont1Rev");
  74.         boldText("doclet.Index");
  75.         fontEnd();
  76.         navCellEnd();
  77.     }
  78.  
  79.     /**
  80.      * Generate the member information for the unicode character along with the
  81.      * list of the members.  
  82.      *
  83.      * @param unicode Unicode for which member list information to be generated.
  84.      * @param memberlist List of members for the unicode character.
  85.      */
  86.     protected void generateContents(Character unicode, List memberlist) {
  87.         anchor("_" + unicode + "_");
  88.         h2();
  89.         bold(unicode.toString());
  90.         h2End();
  91.         dl();
  92.         for (int i = 0; i < memberlist.size(); i++) {
  93.             Doc element = (Doc)memberlist.get(i);
  94.             if (element instanceof MemberDoc) {
  95.                 printDescription((MemberDoc)element);
  96.             } else if (element instanceof ClassDoc) {
  97.                 printDescription((ClassDoc)element);
  98.             } else if (element instanceof PackageDoc) {
  99.                 printDescription((PackageDoc)element);
  100.             } 
  101.         }
  102.         dlEnd();
  103.         hr();
  104.     }
  105.  
  106.  
  107.     /**
  108.      * Print one line summary comment for the package.
  109.      *
  110.      * @param pd PackageDoc passed.
  111.      */
  112.     protected void printDescription(PackageDoc pd) {
  113.         dt();
  114.         printPackageLink(pd); 
  115.         print(" - ");
  116.         print("package " + pd.name());
  117.         dd();
  118.         printSummaryComment(pd); 
  119.     }
  120.  
  121.     /**
  122.      * Print one line summary comment for the class.
  123.      *
  124.      * @param cd ClassDoc passed.
  125.      */
  126.     protected void printDescription(ClassDoc cd) {
  127.         dt();
  128.         printClassLink(cd, true); 
  129.         print(" - ");
  130.         printClassInfo(cd);
  131.         dd();
  132.         printComment(cd); 
  133.     }
  134.  
  135.     /**
  136.      * What is the classkind? Print the classkind(class, interface, exception, 
  137.      * error of the class passed. 
  138.      *
  139.      * @param cd ClassDoc.
  140.      */
  141.     protected void printClassInfo(ClassDoc cd) {
  142.         if (cd.isOrdinaryClass()) {
  143.             print("class ");
  144.         } else if (cd.isInterface()) {
  145.             print("interface ");
  146.         } else if (cd.isException()) {
  147.             print("exception ");
  148.         } else {   // error
  149.             print("error ");
  150.         }
  151.         printPreQualifiedClassLink(cd);
  152.         print('.');
  153.     }
  154.  
  155.  
  156.     /**
  157.      * Generate Description for Class, Field, Method or Constructor.
  158.      * for Java.* Packages Class Members.
  159.      *
  160.      * @param member MemberDoc for the member of the Class Kind.
  161.      * @see com.sun.javadoc.MemberDoc
  162.      */
  163.     protected void printDescription(MemberDoc element) {
  164.         String name = (element instanceof ExecutableMemberDoc)?
  165.                            element.name() + 
  166.                            ((ExecutableMemberDoc)element).flatSignature():
  167.                            element.name();
  168.         ClassDoc containing = element.containingClass();
  169.         String qualname = containing.qualifiedName();
  170.         String baseClassName = containing.name();
  171.         dt();
  172.         printDocLink(element, name, true);
  173.         println(" - ");
  174.         printMemberDesc(element);
  175.         println();
  176.         dd();
  177.         printComment(element); 
  178.         println();
  179.     }
  180.  
  181.  
  182.     /**
  183.      * Print comment for each element in the index. If the element is deprecated
  184.      * and it has a @deprecated tag, use that comment. Else if the containing
  185.      * class for this element is deprecated, then add the word "Deprecated." at
  186.      * the start and then print the normal comment.
  187.      *
  188.      * @param element Index element.
  189.      */
  190.     protected void printComment(ProgramElementDoc element) {
  191.         Tag[] tags;
  192.         if ((tags = element.tags("deprecated")).length > 0) {
  193.             boldText("doclet.Deprecated"); space();
  194.             printInlineDeprecatedComment(tags[0]);
  195.         } else {
  196.             ClassDoc cont = element.containingClass();
  197.             while (cont != null) {
  198.                 if (cont.tags("deprecated").length > 0) {
  199.                     boldText("doclet.Deprecated"); space();
  200.                     break;
  201.                 }
  202.                 cont = cont.containingClass();
  203.             }
  204.             printSummaryComment(element);
  205.         }
  206.     }
  207.  
  208.     /**
  209.      * Print description about the Static Varible/Method/Constructor for a
  210.      * member.
  211.      * 
  212.      * @param member MemberDoc for the member within the Class Kind.
  213.      * @see com.sun.javadoc.MemberDoc
  214.      */
  215.     protected void printMemberDesc(MemberDoc member) {
  216.         ClassDoc containing = member.containingClass();
  217.         String classdesc = (containing.isInterface()? "interface ": "class ") + 
  218.                            getPreQualifiedClassLink(containing);
  219.         if (member.isField()) {
  220.             if (member.isStatic()) {
  221.                 printText("doclet.Static_variable_in", classdesc);
  222.             } else {
  223.                 printText("doclet.Variable_in", classdesc);
  224.             }
  225.         } else if (member.isConstructor()) {
  226.             printText("doclet.Constructor_for", classdesc);
  227.         } else if (member.isMethod()) {
  228.             if (member.isStatic()) {
  229.                 printText("doclet.Static_method_in", classdesc);
  230.             } else {
  231.                 printText("doclet.Method_in", classdesc);
  232.             }
  233.         }               
  234.     }
  235. }
  236.