langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java
changeset 40587 1c355ea550ed
parent 40303 96a1226aca18
child 41157 b235a429089a
equal deleted inserted replaced
40519:e17429a7e843 40587:1c355ea550ed
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.javadoc.internal.doclets.formats.html;
    26 package jdk.javadoc.internal.doclets.formats.html;
    27 
    27 
    28 import java.io.*;
       
    29 import java.util.*;
    28 import java.util.*;
    30 
    29 
    31 import javax.lang.model.element.PackageElement;
    30 import javax.lang.model.element.PackageElement;
    32 import javax.lang.model.element.TypeElement;
    31 import javax.lang.model.element.TypeElement;
    33 
    32 
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
    35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
    38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
    39 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
    38 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
    40 import jdk.javadoc.internal.doclets.toolkit.Content;
    39 import jdk.javadoc.internal.doclets.toolkit.Content;
    41 import jdk.javadoc.internal.doclets.toolkit.Messages;
       
    42 import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper;
    40 import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper;
       
    41 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
    43 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
    42 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
    44 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
    43 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
    45 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
       
    46 
    44 
    47 /**
    45 /**
    48  * Generate package usage information.
    46  * Generate package usage information.
    49  *
    47  *
    50  *  <p><b>This is NOT part of any supported API.
    48  *  <p><b>This is NOT part of any supported API.
    63 
    61 
    64     /**
    62     /**
    65      * Constructor.
    63      * Constructor.
    66      *
    64      *
    67      * @param filename the file to be generated.
    65      * @param filename the file to be generated.
    68      * @throws IOException
       
    69      * @throws DocletAbortException
       
    70      */
    66      */
    71     public PackageUseWriter(ConfigurationImpl configuration,
    67     public PackageUseWriter(ConfigurationImpl configuration,
    72                             ClassUseMapper mapper, DocPath filename,
    68                             ClassUseMapper mapper, DocPath filename,
    73                             PackageElement pkgElement) throws IOException {
    69                             PackageElement pkgElement) {
    74         super(configuration, DocPath.forPackage(pkgElement).resolve(filename));
    70         super(configuration, DocPath.forPackage(pkgElement).resolve(filename));
    75         this.packageElement = pkgElement;
    71         this.packageElement = pkgElement;
    76 
    72 
    77         // by examining all classes in this package, find what packages
    73         // by examining all classes in this package, find what packages
    78         // use these classes - produce a map between using package and
    74         // use these classes - produce a map between using package and
    99      * Generate a class page.
    95      * Generate a class page.
   100      *
    96      *
   101      * @param configuration the current configuration of the doclet.
    97      * @param configuration the current configuration of the doclet.
   102      * @param mapper        the mapping of the class usage.
    98      * @param mapper        the mapping of the class usage.
   103      * @param pkgElement    the package being documented.
    99      * @param pkgElement    the package being documented.
       
   100      * @throws DocFileIOException if there is a problem generating the package use page
   104      */
   101      */
   105     public static void generate(ConfigurationImpl configuration,
   102     public static void generate(ConfigurationImpl configuration,
   106                                 ClassUseMapper mapper, PackageElement pkgElement) {
   103                                 ClassUseMapper mapper, PackageElement pkgElement)
   107         PackageUseWriter pkgusegen;
   104             throws DocFileIOException {
   108         DocPath filename = DocPaths.PACKAGE_USE;
   105         DocPath filename = DocPaths.PACKAGE_USE;
   109         try {
   106         PackageUseWriter pkgusegen = new PackageUseWriter(configuration, mapper, filename, pkgElement);
   110             pkgusegen = new PackageUseWriter(configuration, mapper, filename, pkgElement);
   107         pkgusegen.generatePackageUseFile();
   111             pkgusegen.generatePackageUseFile();
       
   112         } catch (IOException exc) {
       
   113             Messages messages = configuration.getMessages();
       
   114             messages.error(exc.toString(), filename);
       
   115             throw new DocletAbortException(exc);
       
   116         }
       
   117     }
   108     }
   118 
   109 
   119     /**
   110     /**
   120      * Generate the package use list.
   111      * Generate the package use list.
   121      */
   112      * @throws DocFileIOException if there is a problem generating the package use page
   122     protected void generatePackageUseFile() throws IOException {
   113      */
       
   114     protected void generatePackageUseFile() throws DocFileIOException {
   123         HtmlTree body = getPackageUseHeader();
   115         HtmlTree body = getPackageUseHeader();
   124         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   116         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   125         div.addStyle(HtmlStyle.contentContainer);
   117         div.addStyle(HtmlStyle.contentContainer);
   126         if (usingPackageToUsedClasses.isEmpty()) {
   118         if (usingPackageToUsedClasses.isEmpty()) {
   127             div.addContent(contents.getContent("doclet.ClassUse_No.usage.of.0", utils.getPackageName(packageElement)));
   119             div.addContent(contents.getContent("doclet.ClassUse_No.usage.of.0", utils.getPackageName(packageElement)));
   148     /**
   140     /**
   149      * Add the package use information.
   141      * Add the package use information.
   150      *
   142      *
   151      * @param contentTree the content tree to which the package use information will be added
   143      * @param contentTree the content tree to which the package use information will be added
   152      */
   144      */
   153     protected void addPackageUse(Content contentTree) throws IOException {
   145     protected void addPackageUse(Content contentTree) {
   154         HtmlTree ul = new HtmlTree(HtmlTag.UL);
   146         HtmlTree ul = new HtmlTree(HtmlTag.UL);
   155         ul.addStyle(HtmlStyle.blockList);
   147         ul.addStyle(HtmlStyle.blockList);
   156         if (configuration.packages.size() > 1) {
   148         if (configuration.packages.size() > 1) {
   157             addPackageList(ul);
   149             addPackageList(ul);
   158         }
   150         }
   163     /**
   155     /**
   164      * Add the list of packages that use the given package.
   156      * Add the list of packages that use the given package.
   165      *
   157      *
   166      * @param contentTree the content tree to which the package list will be added
   158      * @param contentTree the content tree to which the package list will be added
   167      */
   159      */
   168     protected void addPackageList(Content contentTree) throws IOException {
   160     protected void addPackageList(Content contentTree) {
   169         Content caption = getTableCaption(configuration.getContent(
   161         Content caption = getTableCaption(configuration.getContent(
   170                 "doclet.ClassUse_Packages.that.use.0",
   162                 "doclet.ClassUse_Packages.that.use.0",
   171                 getPackageLink(packageElement, utils.getPackageName(packageElement))));
   163                 getPackageLink(packageElement, utils.getPackageName(packageElement))));
   172         Content table = (configuration.isOutputHtml5())
   164         Content table = (configuration.isOutputHtml5())
   173                 ? HtmlTree.TABLE(HtmlStyle.useSummary, caption)
   165                 ? HtmlTree.TABLE(HtmlStyle.useSummary, caption)
   191     /**
   183     /**
   192      * Add the list of classes that use the given package.
   184      * Add the list of classes that use the given package.
   193      *
   185      *
   194      * @param contentTree the content tree to which the class list will be added
   186      * @param contentTree the content tree to which the class list will be added
   195      */
   187      */
   196     protected void addClassList(Content contentTree) throws IOException {
   188     protected void addClassList(Content contentTree) {
   197         List<String> classTableHeader = Arrays.asList(
   189         List<String> classTableHeader = Arrays.asList(
   198             configuration.getText("doclet.0_and_1",
   190             configuration.getText("doclet.0_and_1",
   199                     configuration.getText("doclet.Class"),
   191                     configuration.getText("doclet.Class"),
   200                     configuration.getText("doclet.Description")));
   192                     configuration.getText("doclet.Description")));
   201         for (String packageName : usingPackageToUsedClasses.keySet()) {
   193         for (String packageName : usingPackageToUsedClasses.keySet()) {
   252      * Add the package use information.
   244      * Add the package use information.
   253      *
   245      *
   254      * @param pkg the package that used the given package
   246      * @param pkg the package that used the given package
   255      * @param contentTree the content tree to which the information will be added
   247      * @param contentTree the content tree to which the information will be added
   256      */
   248      */
   257     protected void addPackageUse(PackageElement pkg, Content contentTree) throws IOException {
   249     protected void addPackageUse(PackageElement pkg, Content contentTree) {
   258         Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
   250         Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
   259                 getHyperLink(utils.getPackageName(pkg),
   251                 getHyperLink(utils.getPackageName(pkg),
   260                 new StringContent(utils.getPackageName(pkg))));
   252                 new StringContent(utils.getPackageName(pkg))));
   261         contentTree.addContent(tdFirst);
   253         contentTree.addContent(tdFirst);
   262         HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
   254         HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
   318     /**
   310     /**
   319      * Get this package link.
   311      * Get this package link.
   320      *
   312      *
   321      * @return a content tree for the package link
   313      * @return a content tree for the package link
   322      */
   314      */
       
   315     @Override
   323     protected Content getNavLinkPackage() {
   316     protected Content getNavLinkPackage() {
   324         Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
   317         Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
   325                 contents.packageLabel);
   318                 contents.packageLabel);
   326         Content li = HtmlTree.LI(linkContent);
   319         Content li = HtmlTree.LI(linkContent);
   327         return li;
   320         return li;
   330     /**
   323     /**
   331      * Get the use link.
   324      * Get the use link.
   332      *
   325      *
   333      * @return a content tree for the use link
   326      * @return a content tree for the use link
   334      */
   327      */
       
   328     @Override
   335     protected Content getNavLinkClassUse() {
   329     protected Content getNavLinkClassUse() {
   336         Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, contents.useLabel);
   330         Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, contents.useLabel);
   337         return li;
   331         return li;
   338     }
   332     }
   339 
   333 
   340     /**
   334     /**
   341      * Get the tree link.
   335      * Get the tree link.
   342      *
   336      *
   343      * @return a content tree for the tree link
   337      * @return a content tree for the tree link
   344      */
   338      */
       
   339     @Override
   345     protected Content getNavLinkTree() {
   340     protected Content getNavLinkTree() {
   346         Content linkContent = getHyperLink(DocPaths.PACKAGE_TREE,
   341         Content linkContent = getHyperLink(DocPaths.PACKAGE_TREE,
   347                 contents.treeLabel);
   342                 contents.treeLabel);
   348         Content li = HtmlTree.LI(linkContent);
   343         Content li = HtmlTree.LI(linkContent);
   349         return li;
   344         return li;