src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageUseWriter.java
author jjg
Wed, 07 Feb 2018 11:28:23 -0800
changeset 48759 ffa68af7da87
parent 48654 36f58bd6269f
child 49551 0d4786e42471
permissions -rw-r--r--
8195795: Organize output files by module/package, not just package Reviewed-by: ksrini, mchung, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 47850
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2320
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2320
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2320
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2320
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2320
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    26
package jdk.javadoc.internal.doclets.formats.html;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
    28
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
    29
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
    30
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9606
diff changeset
    32
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    33
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    34
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    35
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    36
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    37
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    38
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    39
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    40
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents: 47846
diff changeset
    41
import jdk.javadoc.internal.doclets.formats.html.markup.Links;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    42
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    43
import jdk.javadoc.internal.doclets.toolkit.Content;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    44
import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    45
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    46
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    47
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * Generate package usage information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    52
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    53
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    54
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    55
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    56
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * @author Robert G. Field
2320
5b8c377175f4 6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents: 1789
diff changeset
    58
 * @author Bhavesh Patel (Modified)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
public class PackageUseWriter extends SubWriterHolderWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    62
    final PackageElement packageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    63
    final SortedMap<String, Set<TypeElement>> usingPackageToUsedClasses = new TreeMap<>();
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
    64
    protected HtmlTree mainTree = HtmlTree.MAIN();
47427
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
    65
    final String packageUseTableSummary;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     *
47427
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
    70
     * @param configuration the configuration
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
    71
     * @param mapper a mapper to provide details of where elements are used
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
    72
     * @param filename the file to be generated
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
    73
     * @param pkgElement the package element to be documented
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 41157
diff changeset
    75
    public PackageUseWriter(HtmlConfiguration configuration,
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    76
                            ClassUseMapper mapper, DocPath filename,
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    77
                            PackageElement pkgElement) {
48759
ffa68af7da87 8195795: Organize output files by module/package, not just package
jjg
parents: 48654
diff changeset
    78
        super(configuration, configuration.docPaths.forPackage(pkgElement).resolve(filename));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    79
        this.packageElement = pkgElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        // by examining all classes in this package, find what packages
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        // use these classes - produce a map between using package and
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        // used classes.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    84
        for (TypeElement usedClass : utils.getEnclosedTypeElements(pkgElement)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    85
            Set<TypeElement> usingClasses = mapper.classToClass.get(usedClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            if (usingClasses != null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    87
                for (TypeElement usingClass : usingClasses) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    88
                    PackageElement usingPackage = utils.containingPackage(usingClass);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    89
                    Set<TypeElement> usedClasses = usingPackageToUsedClasses
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    90
                            .get(utils.getPackageName(usingPackage));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                    if (usedClasses == null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    92
                        usedClasses = new TreeSet<>(utils.makeGeneralPurposeComparator());
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    93
                        usingPackageToUsedClasses.put(utils.getPackageName(usingPackage),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                                                      usedClasses);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
                    usedClasses.add(usedClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        }
47427
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
   100
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
   101
        packageUseTableSummary = resources.getText("doclet.Use_Table_Summary",
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
   102
                resources.getText("doclet.packages"));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * Generate a class page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @param mapper        the mapping of the class usage.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   110
     * @param pkgElement    the package being documented.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   111
     * @throws DocFileIOException if there is a problem generating the package use page
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 41157
diff changeset
   113
    public static void generate(HtmlConfiguration configuration,
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   114
                                ClassUseMapper mapper, PackageElement pkgElement)
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   115
            throws DocFileIOException {
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
   116
        DocPath filename = DocPaths.PACKAGE_USE;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   117
        PackageUseWriter pkgusegen = new PackageUseWriter(configuration, mapper, filename, pkgElement);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   118
        pkgusegen.generatePackageUseFile();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   122
     * Generate the package use list.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   123
     * @throws DocFileIOException if there is a problem generating the package use page
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   125
    protected void generatePackageUseFile() throws DocFileIOException {
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   126
        HtmlTree body = getPackageUseHeader();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   127
        HtmlTree div = new HtmlTree(HtmlTag.DIV);
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   128
        div.setStyle(HtmlStyle.contentContainer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        if (usingPackageToUsedClasses.isEmpty()) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 37943
diff changeset
   130
            div.addContent(contents.getContent("doclet.ClassUse_No.usage.of.0", utils.getPackageName(packageElement)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        } else {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   132
            addPackageUse(div);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        }
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   134
        if (configuration.allowTag(HtmlTag.MAIN)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   135
            mainTree.addContent(div);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   136
            body.addContent(mainTree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   137
        } else {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   138
            body.addContent(div);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   139
        }
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   140
        HtmlTree tree = (configuration.allowTag(HtmlTag.FOOTER))
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   141
                ? HtmlTree.FOOTER()
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   142
                : body;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   143
        addNavLinks(false, tree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   144
        addBottom(tree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   145
        if (configuration.allowTag(HtmlTag.FOOTER)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   146
            body.addContent(tree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   147
        }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   148
        printHtmlDocument(null, true, body);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   149
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   151
    /**
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   152
     * Add the package use information.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   153
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   154
     * @param contentTree the content tree to which the package use information will be added
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   155
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   156
    protected void addPackageUse(Content contentTree) {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   157
        HtmlTree ul = new HtmlTree(HtmlTag.UL);
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   158
        ul.setStyle(HtmlStyle.blockList);
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22163
diff changeset
   159
        if (configuration.packages.size() > 1) {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   160
            addPackageList(ul);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   161
        }
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   162
        addClassList(ul);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   163
        contentTree.addContent(ul);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   167
     * Add the list of packages that use the given package.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   168
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   169
     * @param contentTree the content tree to which the package list will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   171
    protected void addPackageList(Content contentTree) {
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   172
        Content caption = contents.getContent(
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   173
                "doclet.ClassUse_Packages.that.use.0",
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   174
                getPackageLink(packageElement, utils.getPackageName(packageElement)));
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   175
        Table table = new Table(configuration.htmlVersion, HtmlStyle.useSummary)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   176
                .setSummary(packageUseTableSummary)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   177
                .setCaption(caption)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   178
                .setHeader(getPackageTableHeader())
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   179
                .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   180
        for (String pkgname: usingPackageToUsedClasses.keySet()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   181
            PackageElement pkg = utils.elementUtils.getPackageElement(pkgname);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents: 47846
diff changeset
   182
            Content packageLink = links.createLink(utils.getPackageName(pkg),
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   183
                    new StringContent(utils.getPackageName(pkg)));
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   184
            Content summary = new ContentBuilder();
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   185
            if (pkg != null && !pkg.isUnnamed()) {
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   186
                addSummaryComment(pkg, summary);
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   187
            } else {
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   188
                summary.addContent(Contents.SPACE);
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   189
            }
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   190
            table.addRow(packageLink, summary);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        }
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   192
        Content li = HtmlTree.LI(HtmlStyle.blockList, table.toContent());
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   193
        contentTree.addContent(li);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   196
    /**
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   197
     * Add the list of classes that use the given package.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   198
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   199
     * @param contentTree the content tree to which the class list will be added
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   200
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   201
    protected void addClassList(Content contentTree) {
47427
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
   202
        TableHeader classTableHeader = new TableHeader(
251676148c62 8189405: More cleanup in HtmlWriter
jjg
parents: 47216
diff changeset
   203
                contents.classLabel, contents.descriptionLabel);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20613
diff changeset
   204
        for (String packageName : usingPackageToUsedClasses.keySet()) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   205
            PackageElement usingPackage = utils.elementUtils.getPackageElement(packageName);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   206
            HtmlTree li = new HtmlTree(HtmlTag.LI);
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   207
            li.setStyle(HtmlStyle.blockList);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            if (usingPackage != null) {
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents: 47846
diff changeset
   209
                li.addContent(links.createAnchor(utils.getPackageName(usingPackage)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            }
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   211
            String tableSummary = resources.getText("doclet.Use_Table_Summary",
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   212
                                                        resources.getText("doclet.classes"));
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   213
            Content caption = contents.getContent(
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   214
                    "doclet.ClassUse_Classes.in.0.used.by.1",
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   215
                    getPackageLink(packageElement, utils.getPackageName(packageElement)),
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   216
                    getPackageLink(usingPackage, utils.getPackageName(usingPackage)));
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   217
            Table table = new Table(configuration.htmlVersion, HtmlStyle.useSummary)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   218
                    .setSummary(tableSummary)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   219
                    .setCaption(caption)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   220
                    .setHeader(classTableHeader)
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   221
                    .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   222
            for (TypeElement te : usingPackageToUsedClasses.get(packageName)) {
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   223
                DocPath dp = pathString(te,
48759
ffa68af7da87 8195795: Organize output files by module/package, not just package
jjg
parents: 48654
diff changeset
   224
                        DocPaths.CLASS_USE.resolve(docPaths.forName(te)));
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   225
                Content stringContent = new StringContent(utils.getSimpleName(te));
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 47850
diff changeset
   226
                Content typeContent = links.createLink(dp.fragment(getPackageAnchorName(usingPackage)),
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   227
                        stringContent);
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   228
                Content summary = new ContentBuilder();
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   229
                addIndexComment(te, summary);
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   230
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   231
                table.addRow(typeContent, summary);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            }
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   233
            li.addContent(table.toContent());
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   234
            contentTree.addContent(li);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   238
    /**
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   239
     * Get the header for the package use listing.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   240
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   241
     * @return a content tree representing the package use header
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     */
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   243
    private HtmlTree getPackageUseHeader() {
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   244
        String packageText = resources.getText("doclet.Package");
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   245
        String name = packageElement.isUnnamed() ? "" : utils.getPackageName(packageElement);
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47427
diff changeset
   246
        String title = resources.getText("doclet.Window_ClassUse_Header", packageText, name);
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   247
        HtmlTree bodyTree = getBody(true, getWindowTitle(title));
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   248
        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   249
                ? HtmlTree.HEADER()
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   250
                : bodyTree;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   251
        addTop(htmlTree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   252
        addNavLinks(true, htmlTree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   253
        if (configuration.allowTag(HtmlTag.HEADER)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   254
            bodyTree.addContent(htmlTree);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   255
        }
17562
c84f1d7fa11d 8011662: Remove single instance of resource with HTML from doclet resource bundle
jjg
parents: 17559
diff changeset
   256
        ContentBuilder headContent = new ContentBuilder();
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 37943
diff changeset
   257
        headContent.addContent(contents.getContent("doclet.ClassUse_Title", packageText));
17562
c84f1d7fa11d 8011662: Remove single instance of resource with HTML from doclet resource bundle
jjg
parents: 17559
diff changeset
   258
        headContent.addContent(new HtmlTree(HtmlTag.BR));
c84f1d7fa11d 8011662: Remove single instance of resource with HTML from doclet resource bundle
jjg
parents: 17559
diff changeset
   259
        headContent.addContent(name);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   260
        Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   261
                HtmlStyle.title, headContent);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   262
        Content div = HtmlTree.DIV(HtmlStyle.header, heading);
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   263
        if (configuration.allowTag(HtmlTag.MAIN)) {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   264
            mainTree.addContent(div);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   265
        } else {
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   266
            bodyTree.addContent(div);
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 26900
diff changeset
   267
        }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   268
        return bodyTree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    /**
37943
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   272
     * Get the module link.
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   273
     *
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   274
     * @return a content tree for the module link
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   275
     */
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   276
    @Override
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   277
    protected Content getNavLinkModule() {
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   278
        Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(packageElement),
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 37943
diff changeset
   279
                contents.moduleLabel);
37943
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   280
        Content li = HtmlTree.LI(linkContent);
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   281
        return li;
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   282
    }
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   283
2efb75c09230 8154262: Navigation bar in javadoc generated pages needs to be updated to display module information
bpatel
parents: 35426
diff changeset
   284
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   285
     * Get this package link.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   286
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   287
     * @return a content tree for the package link
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   289
    @Override
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   290
    protected Content getNavLinkPackage() {
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 47850
diff changeset
   291
        Content linkContent = links.createLink(DocPaths.PACKAGE_SUMMARY,
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 37943
diff changeset
   292
                contents.packageLabel);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   293
        Content li = HtmlTree.LI(linkContent);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   294
        return li;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   297
    /**
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   298
     * Get the use link.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   299
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   300
     * @return a content tree for the use link
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   301
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   302
    @Override
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   303
    protected Content getNavLinkClassUse() {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 37943
diff changeset
   304
        Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, contents.useLabel);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   305
        return li;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   308
    /**
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   309
     * Get the tree link.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   310
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   311
     * @return a content tree for the tree link
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   312
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   313
    @Override
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   314
    protected Content getNavLinkTree() {
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 47850
diff changeset
   315
        Content linkContent = links.createLink(DocPaths.PACKAGE_TREE,
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 37943
diff changeset
   316
                contents.treeLabel);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   317
        Content li = HtmlTree.LI(linkContent);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   318
        return li;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   319
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
}