src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstantsSummaryBuilder.java
author hannesw
Wed, 27 Nov 2019 13:08:16 +0100
changeset 59294 48b88b9c11eb
parent 49879 601277b1d582
permissions -rw-r--r--
8223378: CSS solution for navbar problem with <a> elements is not ideal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 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: 1789
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: 1789
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: 1789
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
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.toolkit.builders;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    28
import java.util.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 7681
diff changeset
    29
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    30
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    31
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    32
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    33
import javax.lang.model.element.VariableElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    34
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    35
import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    36
import jdk.javadoc.internal.doclets.toolkit.Content;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    37
import jdk.javadoc.internal.doclets.toolkit.DocletException;
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
    38
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    39
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
    40
import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * Builds the Constants Summary Page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    45
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    46
 *  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: 14259
diff changeset
    47
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    48
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * @author Jamie Ho
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    51
 * @author Bhavesh Patel (Modified)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
public class ConstantsSummaryBuilder extends AbstractBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * The maximum number of package directories shown in the constant
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * value index.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    public static final int MAX_CONSTANT_VALUE_INDEX_LENGTH = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * The writer used to write the results.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    64
    protected final ConstantsSummaryWriter writer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    67
     * The set of TypeElements that have constant fields.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    69
    protected final Set<TypeElement> typeElementsWithConstFields;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * The set of printed package headers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    74
    protected final Set<PackageElement> printedPackageHeaders;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * The current package being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    79
    private PackageElement currentPackage;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * The current class being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
    84
    private TypeElement currentClass;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /**
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    87
     * True if first package is listed.
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    88
     */
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    89
    private boolean first = true;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    90
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    91
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Construct a new ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     *
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    94
     * @param context       the build context.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    95
     * @param writer        the writer for the summary.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    97
    private ConstantsSummaryBuilder(Context context,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    98
            ConstantsSummaryWriter writer) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    99
        super(context);
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   100
        this.writer = writer;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   101
        this.typeElementsWithConstFields = new HashSet<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   102
        this.printedPackageHeaders = new TreeSet<>(utils.makePackageComparator());
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
     * Construct a ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   108
     * @param context       the build context.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @param writer        the writer for the summary.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   110
     * @return the new ConstantsSummaryBuilder
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   112
    public static ConstantsSummaryBuilder getInstance(Context context,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   113
            ConstantsSummaryWriter writer) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   114
        return new ConstantsSummaryBuilder(context, writer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * {@inheritDoc}
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   119
     * @throws DocletException if there is a problem while building the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   121
    @Override
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   122
    public void build() throws DocletException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        if (writer == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            //Doclet does not support this output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        }
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   127
        buildConstantSummary();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * Build the constant summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   133
     * @throws DocletException if there is a problem while building the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     */
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   135
    protected void buildConstantSummary() throws DocletException {
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   136
        Content contentTree = writer.getHeader();
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   137
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   138
        buildContents();
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   139
        buildConstantSummaries();
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   140
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   141
        writer.addFooter();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   142
        writer.printDocument(contentTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   146
     * Build the list of packages.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   148
    protected void buildContents() {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   149
        Content contentListTree = writer.getContentsHeader();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   150
        printedPackageHeaders.clear();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   151
        for (PackageElement pkg : configuration.packages) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   152
            if (hasConstantField(pkg) && !hasPrintedPackageIndex(pkg)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   153
                writer.addLinkToPackageContent(pkg, printedPackageHeaders, contentListTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        }
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   156
        writer.addContentsList(contentListTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * Build the summary for each documented package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   162
     * @throws DocletException if there is a problem while building the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     */
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   164
    protected void buildConstantSummaries() throws DocletException {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   165
        printedPackageHeaders.clear();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   166
        Content summariesTree = writer.getConstantSummaries();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   167
        for (PackageElement aPackage : configuration.packages) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   168
            if (hasConstantField(aPackage)) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   169
                currentPackage = aPackage;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                //Build the documentation for the current package.
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   171
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   172
                buildPackageHeader(summariesTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   173
                buildClassConstantSummary(summariesTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   174
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
   175
                first = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        }
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 49879
diff changeset
   178
        writer.addConstantSummaries(summariesTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   182
     * Build the header for the given package.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   184
     * @param summariesTree the tree to which the package header will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   186
    protected void buildPackageHeader(Content summariesTree) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   187
        PackageElement abbrevPkg = configuration.workArounds.getAbbreviatedPackageElement(currentPackage);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   188
        if (!printedPackageHeaders.contains(abbrevPkg)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   189
            writer.addPackageName(currentPackage, summariesTree, first);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   190
            printedPackageHeaders.add(abbrevPkg);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   191
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * Build the summary for the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   197
     * @param summariesTree the tree to which the class constant summary will be added
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   198
     * @throws DocletException if there is a problem while building the documentation
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   199
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   201
    protected void buildClassConstantSummary(Content summariesTree)
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   202
            throws DocletException {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   203
        SortedSet<TypeElement> classes = !currentPackage.isUnnamed()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   204
                ? utils.getAllClasses(currentPackage)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   205
                : configuration.typeElementCatalog.allUnnamedClasses();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   206
        Content classConstantTree = writer.getClassConstantHeader();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   207
        for (TypeElement te : classes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   208
            if (!typeElementsWithConstFields.contains(te) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   209
                !utils.isIncluded(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   212
            currentClass = te;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            //Build the documentation for the current class.
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   214
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   215
            buildConstantMembers(classConstantTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   216
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        }
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
   218
        writer.addClassConstant(summariesTree, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   222
     * Build the summary of constant members in the class.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   223
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   224
     * @param classConstantTree the tree to which the constant members table
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   225
     *                          will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   227
    protected void buildConstantMembers(Content classConstantTree) {
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   228
        new ConstantFieldBuilder(currentClass).buildMembersSummary(classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * Return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
     * @param pkg   the package being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   237
    private boolean hasConstantField(PackageElement pkg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   238
        SortedSet<TypeElement> classes = !pkg.isUnnamed()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   239
                  ? utils.getAllClasses(pkg)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   240
                  : configuration.typeElementCatalog.allUnnamedClasses();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        boolean found = false;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   242
        for (TypeElement te : classes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   243
            if (utils.isIncluded(te) && hasConstantField(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                found = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        return found;
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * Return true if the given class has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   253
     * @param typeElement the class being checked.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   256
    private boolean hasConstantField (TypeElement typeElement) {
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   257
        VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement);
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   258
        List<? extends Element> fields = vmt.getVisibleMembers(FIELDS);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   259
        for (Element f : fields) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   260
            VariableElement field = (VariableElement)f;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   261
            if (field.getConstantValue() != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   262
                typeElementsWithConstFields.add(typeElement);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * Return true if the given package name has been printed.  Also
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * return true if the root of this package has been printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     *
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   273
     * @param pkg the name of the package to check.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   275
    private boolean hasPrintedPackageIndex(PackageElement pkg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   276
        for (PackageElement printedPkg : printedPackageHeaders) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   277
            if (utils.getPackageName(pkg).startsWith(utils.parsePackageName(printedPkg))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     * Print the table of constants.
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    private class ConstantFieldBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   292
         * The typeElement that we are examining constants for.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   294
        protected TypeElement typeElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
         * Construct a ConstantFieldSubWriter.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   298
         * @param typeElement the typeElement that we are examining constants for.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   300
        public ConstantFieldBuilder(TypeElement typeElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   301
            this.typeElement = typeElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
         * Builds the table of constants for a given class.
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   306
         *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   307
         * @param classConstantTree the tree to which the class constants table
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   308
         *                          will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
         */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   310
        protected void buildMembersSummary(Content classConstantTree) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   311
            SortedSet<VariableElement> members = members();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   312
            if (!members.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   313
                writer.addConstantMembers(typeElement, members, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        /**
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   318
         * Returns a set of visible constant fields for the given type.
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   319
         * @return the set of visible constant fields for the given type.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   321
        protected SortedSet<VariableElement> members() {
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   322
            VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement);
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   323
            List<Element> members = new ArrayList<>();
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   324
            members.addAll(vmt.getVisibleMembers(FIELDS));
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   325
            members.addAll(vmt.getVisibleMembers(ENUM_CONSTANTS));
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   326
            SortedSet<VariableElement> includes =
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   327
                    new TreeSet<>(utils.makeGeneralPurposeComparator());
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   328
            for (Element element : members) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   329
                VariableElement member = (VariableElement)element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   330
                if (member.getConstantValue() != null) {
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   331
                    includes.add(member);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            }
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   334
            return includes;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
}