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

Mon, 09 Mar 2009 23:53:41 -0700

author
tbell
date
Mon, 09 Mar 2009 23:53:41 -0700
changeset 240
8c55d5b0ed71
parent 184
905e151a185a
child 243
edd944553131
permissions
-rw-r--r--

Merge

     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<ClassDoc> it = usingClasses.iterator(); it.hasNext(); ) {
    67                     ClassDoc usingClass = 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<String> it = usingPackageToUsedClasses.keySet().iterator();
   140         while (it.hasNext()) {
   141             PackageDoc pkg = configuration.root.packageNamed(it.next());
   142             generatePackageUse(pkg);
   143         }
   144         tableEnd();
   145         space();
   146         p();
   147     }
   149     protected void generateClassList() throws IOException {
   150         Iterator<String> itp = usingPackageToUsedClasses.keySet().iterator();
   151         while (itp.hasNext()) {
   152             String packageName = 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<ClassDoc> itc =
   164                     usingPackageToUsedClasses.get(packageName).iterator();
   165             while (itc.hasNext()) {
   166                 printClassRow(itc.next(), packageName);
   167             }
   168             tableEnd();
   169             space();
   170             p();
   171         }
   172     }
   174     protected void printClassRow(ClassDoc usedClass, String packageName) {
   175         String path = pathString(usedClass,
   176                                  "class-use/" + usedClass.name() + ".html");
   178         trBgcolorStyle("white", "TableRowColor");
   179         summaryRow(0);
   180         strong();
   181         printHyperLink(path, packageName, usedClass.name(), true);
   182         strongEnd();
   183         println(); br();
   184         printNbsps();
   185         printIndexComment(usedClass);
   186         summaryRowEnd();
   187         trEnd();
   188     }
   190     /**
   191      * Print the package use list.
   192      */
   193     protected void generatePackageUse(PackageDoc pkg) throws IOException {
   194         trBgcolorStyle("white", "TableRowColor");
   195         summaryRow(0);
   196         //Just want an anchor here.
   197         printHyperLink("", pkg.name(), Util.getPackageName(pkg), true);
   198         summaryRowEnd();
   199         summaryRow(0);
   200         if (pkg != null) {
   201             printSummaryComment(pkg);
   202         }
   203         space();
   204         summaryRowEnd();
   205         trEnd();
   206     }
   208     /**
   209      * Print the header for the class use Listing.
   210      */
   211     protected void printPackageUseHeader() {
   212         String packageLabel = configuration.getText("doclet.Package");
   213         String name = pkgdoc.name();
   214         printHtmlHeader(configuration.getText("doclet.Window_ClassUse_Header",
   215             packageLabel, name), null, true);
   216         printTop();
   217         navLinks(true);
   218         hr();
   219         center();
   220         h2();
   221         strongText("doclet.ClassUse_Title", packageLabel, name);
   222         h2End();
   223         centerEnd();
   224     }
   226     /**
   227      * Print the footer for the class use Listing.
   228      */
   229     protected void printPackageUseFooter() {
   230         hr();
   231         navLinks(false);
   232         printBottom();
   233         printBodyHtmlEnd();
   234     }
   237     /**
   238      * Print this package link
   239      */
   240     protected void navLinkPackage() {
   241         navCellStart();
   242         printHyperLink("package-summary.html", "", configuration.getText("doclet.Package"),
   243                        true, "NavBarFont1");
   244         navCellEnd();
   245     }
   247     /**
   248      * Print class use link
   249      */
   250     protected void navLinkClassUse() {
   251         navCellRevStart();
   252         fontStyle("NavBarFont1Rev");
   253         strongText("doclet.navClassUse");
   254         fontEnd();
   255         navCellEnd();
   256     }
   258     protected void navLinkTree() {
   259         navCellStart();
   260         printHyperLink("package-tree.html", "", configuration.getText("doclet.Tree"),
   261                        true, "NavBarFont1");
   262         navCellEnd();
   263     }
   265 }

mercurial