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

Fri, 03 Dec 2010 20:31:57 -0800

author
mfang
date
Fri, 03 Dec 2010 20:31:57 -0800
changeset 762
4f086529d05c
parent 554
9d9f26857129
child 766
90af8d87741f
permissions
-rw-r--r--

6522789: [zh_CN] translation of "enclosing class" in doclet is incorrect
Reviewed-by: yhuang

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

mercurial