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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 182
47a62d8d98b4
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1998-2008 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.*;
    29 import com.sun.javadoc.*;
    30 import java.io.*;
    31 import java.util.*;
    33 /**
    34  * Generate package usage information.
    35  *
    36  * @author Robert G. Field
    37  */
    38 public class PackageUseWriter extends SubWriterHolderWriter {
    40     final PackageDoc pkgdoc;
    41     final SortedMap<String,Set<ClassDoc>> usingPackageToUsedClasses = new TreeMap<String,Set<ClassDoc>>();
    43     /**
    44      * Constructor.
    45      *
    46      * @param filename the file to be generated.
    47      * @throws IOException
    48      * @throws DocletAbortException
    49      */
    50     public PackageUseWriter(ConfigurationImpl configuration,
    51                             ClassUseMapper mapper, String filename,
    52                             PackageDoc pkgdoc) throws IOException {
    53         super(configuration, DirectoryManager.getDirectoryPath(pkgdoc),
    54               filename,
    55               DirectoryManager.getRelativePath(pkgdoc.name()));
    56         this.pkgdoc = pkgdoc;
    58         // by examining all classes in this package, find what packages
    59         // use these classes - produce a map between using package and
    60         // used classes.
    61         ClassDoc[] content = pkgdoc.allClasses();
    62         for (int i = 0; i < content.length; ++i) {
    63             ClassDoc usedClass = content[i];
    64             Set<ClassDoc> usingClasses = mapper.classToClass.get(usedClass.qualifiedName());
    65             if (usingClasses != null) {
    66                 for (Iterator it = usingClasses.iterator(); it.hasNext(); ) {
    67                     ClassDoc usingClass = (ClassDoc)it.next();
    68                     PackageDoc usingPackage = usingClass.containingPackage();
    69                     Set<ClassDoc> usedClasses = usingPackageToUsedClasses
    70                         .get(usingPackage.name());
    71                     if (usedClasses == null) {
    72                         usedClasses = new TreeSet<ClassDoc>();
    73                         usingPackageToUsedClasses.put(Util.getPackageName(usingPackage),
    74                                                       usedClasses);
    75                     }
    76                     usedClasses.add(usedClass);
    77                 }
    78             }
    79         }
    80     }
    82     /**
    83      * Generate a class page.
    84      *
    85      * @param configuration the current configuration of the doclet.
    86      * @param mapper        the mapping of the class usage.
    87      * @param pkgdoc        the package doc being documented.
    88      */
    89     public static void generate(ConfigurationImpl configuration,
    90                                 ClassUseMapper mapper, PackageDoc pkgdoc) {
    91         PackageUseWriter pkgusegen;
    92         String filename = "package-use.html";
    93         try {
    94             pkgusegen = new PackageUseWriter(configuration,
    95                                              mapper, filename, pkgdoc);
    96             pkgusegen.generatePackageUseFile();
    97             pkgusegen.close();
    98         } catch (IOException exc) {
    99             configuration.standardmessage.error(
   100                 "doclet.exception_encountered",
   101                 exc.toString(), filename);
   102             throw new DocletAbortException();
   103         }
   104     }
   107     /**
   108      * Print the class use list.
   109      */
   110     protected void generatePackageUseFile() throws IOException {
   111         printPackageUseHeader();
   113         if (usingPackageToUsedClasses.isEmpty()) {
   114             printText("doclet.ClassUse_No.usage.of.0", pkgdoc.name());
   115             p();
   116         } else {
   117             generatePackageUse();
   118         }
   120         printPackageUseFooter();
   121     }
   123     /**
   124      * Print the class use list.
   125      */
   126     protected void generatePackageUse() throws IOException {
   127         if (configuration.packages.length > 1) {
   128             generatePackageList();
   129         }
   130         generateClassList();
   131     }
   133     protected void generatePackageList() throws IOException {
   134         tableIndexSummary();
   135         tableHeaderStart("#CCCCFF");
   136         printText("doclet.ClassUse_Packages.that.use.0",
   137             getPackageLink(pkgdoc, Util.getPackageName(pkgdoc), false));
   138         tableHeaderEnd();
   139         Iterator it = usingPackageToUsedClasses.keySet().iterator();
   140         while (it.hasNext()) {
   141             PackageDoc pkg = configuration.root.packageNamed((String)it.next());
   142             generatePackageUse(pkg);
   143         }
   144         tableEnd();
   145         space();
   146         p();
   147     }
   149     protected void generateClassList() throws IOException {
   150         Iterator itp = usingPackageToUsedClasses.keySet().iterator();
   151         while (itp.hasNext()) {
   152             String packageName = (String)itp.next();
   153             PackageDoc usingPackage = configuration.root.packageNamed(packageName);
   154             if (usingPackage != null) {
   155                 anchor(usingPackage.name());
   156             }
   157             tableIndexSummary();
   158             tableHeaderStart("#CCCCFF");
   159             printText("doclet.ClassUse_Classes.in.0.used.by.1",
   160                 getPackageLink(pkgdoc, Util.getPackageName(pkgdoc), false),
   161                 getPackageLink(usingPackage,Util.getPackageName(usingPackage), false));
   162             tableHeaderEnd();
   163             Iterator itc =
   164                 ((Collection)usingPackageToUsedClasses.get(packageName))
   165                 .iterator();
   166             while (itc.hasNext()) {
   167                 printClassRow((ClassDoc)itc.next(), packageName);
   168             }
   169             tableEnd();
   170             space();
   171             p();
   172         }
   173     }
   175     protected void printClassRow(ClassDoc usedClass, String packageName) {
   176         String path = pathString(usedClass,
   177                                  "class-use/" + usedClass.name() + ".html");
   179         trBgcolorStyle("white", "TableRowColor");
   180         summaryRow(0);
   181         bold();
   182         printHyperLink(path, packageName, usedClass.name(), true);
   183         boldEnd();
   184         println(); br();
   185         printNbsps();
   186         printIndexComment(usedClass);
   187         summaryRowEnd();
   188         trEnd();
   189     }
   191     /**
   192      * Print the package use list.
   193      */
   194     protected void generatePackageUse(PackageDoc pkg) throws IOException {
   195         trBgcolorStyle("white", "TableRowColor");
   196         summaryRow(0);
   197         //Just want an anchor here.
   198         printHyperLink("", pkg.name(), Util.getPackageName(pkg), true);
   199         summaryRowEnd();
   200         summaryRow(0);
   201         if (pkg != null) {
   202             printSummaryComment(pkg);
   203         }
   204         space();
   205         summaryRowEnd();
   206         trEnd();
   207     }
   209     /**
   210      * Print the header for the class use Listing.
   211      */
   212     protected void printPackageUseHeader() {
   213         String packageLabel = configuration.getText("doclet.Package");
   214         String name = pkgdoc.name();
   215         printHtmlHeader(configuration.getText("doclet.Window_ClassUse_Header",
   216             packageLabel, name), null, true);
   217         printTop();
   218         navLinks(true);
   219         hr();
   220         center();
   221         h2();
   222         boldText("doclet.ClassUse_Title", packageLabel, name);
   223         h2End();
   224         centerEnd();
   225     }
   227     /**
   228      * Print the footer for the class use Listing.
   229      */
   230     protected void printPackageUseFooter() {
   231         hr();
   232         navLinks(false);
   233         printBottom();
   234         printBodyHtmlEnd();
   235     }
   238     /**
   239      * Print this package link
   240      */
   241     protected void navLinkPackage() {
   242         navCellStart();
   243         printHyperLink("package-summary.html", "", configuration.getText("doclet.Package"),
   244                        true, "NavBarFont1");
   245         navCellEnd();
   246     }
   248     /**
   249      * Print class use link
   250      */
   251     protected void navLinkClassUse() {
   252         navCellRevStart();
   253         fontStyle("NavBarFont1Rev");
   254         boldText("doclet.navClassUse");
   255         fontEnd();
   256         navCellEnd();
   257     }
   259     protected void navLinkTree() {
   260         navCellStart();
   261         printHyperLink("package-tree.html", "", configuration.getText("doclet.Tree"),
   262                        true, "NavBarFont1");
   263         navCellEnd();
   264     }
   266 }

mercurial