src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ConstantsSummaryBuilder.java
author ksrini
Tue, 24 Apr 2018 11:54:03 -0700
changeset 49879 601277b1d582
parent 47216 71c04702a3d5
child 59294 48b88b9c11eb
permissions -rw-r--r--
8025091: VisibleMemberMap.java possible performance improvements 8198890: The standard doclet incorrectly produces wrong method signatures in certain cases. 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
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    87
     * The content tree for the constant summary documentation.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    88
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    89
    private Content contentTree;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    90
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    91
    /**
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    92
     * True if first package is listed.
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    93
     */
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    94
    private boolean first = true;
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    95
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
    96
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * Construct a new ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     *
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    99
     * @param context       the build context.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   100
     * @param writer        the writer for the summary.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   102
    private ConstantsSummaryBuilder(Context context,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   103
            ConstantsSummaryWriter writer) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   104
        super(context);
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   105
        this.writer = writer;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   106
        this.typeElementsWithConstFields = new HashSet<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   107
        this.printedPackageHeaders = new TreeSet<>(utils.makePackageComparator());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * Construct a ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     *
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   113
     * @param context       the build context.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * @param writer        the writer for the summary.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   115
     * @return the new ConstantsSummaryBuilder
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   117
    public static ConstantsSummaryBuilder getInstance(Context context,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   118
            ConstantsSummaryWriter writer) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   119
        return new ConstantsSummaryBuilder(context, writer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * {@inheritDoc}
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   124
     * @throws DocletException if there is a problem while building the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   126
    @Override
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   127
    public void build() throws DocletException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        if (writer == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            //Doclet does not support this output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        }
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   132
        buildConstantSummary(contentTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * Build the constant summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   138
     * @param contentTree the content tree to which the documentation will be added
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   139
     * @throws DocletException if there is a problem while building the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   141
    protected void buildConstantSummary(Content contentTree) throws DocletException {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   142
        contentTree = writer.getHeader();
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   143
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   144
        buildContents(contentTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   145
        buildConstantSummaries(contentTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   146
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   147
        writer.addFooter(contentTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   148
        writer.printDocument(contentTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   152
     * Build the list of packages.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   153
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   154
     * @param contentTree the content tree to which the content list will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   156
    protected void buildContents(Content contentTree) {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   157
        Content contentListTree = writer.getContentsHeader();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   158
        printedPackageHeaders.clear();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   159
        for (PackageElement pkg : configuration.packages) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   160
            if (hasConstantField(pkg) && !hasPrintedPackageIndex(pkg)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   161
                writer.addLinkToPackageContent(pkg, printedPackageHeaders, contentListTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        }
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
   164
        writer.addContentsList(contentTree, contentListTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * Build the summary for each documented package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   170
     * @param contentTree the tree to which the summaries will be added
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   171
     * @throws DocletException if there is a problem while building the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   173
    protected void buildConstantSummaries(Content contentTree) throws DocletException {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   174
        printedPackageHeaders.clear();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   175
        Content summariesTree = writer.getConstantSummaries();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   176
        for (PackageElement aPackage : configuration.packages) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   177
            if (hasConstantField(aPackage)) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   178
                currentPackage = aPackage;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                //Build the documentation for the current package.
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   180
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   181
                buildPackageHeader(summariesTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   182
                buildClassConstantSummary(summariesTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   183
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
   184
                first = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        }
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
   187
        writer.addConstantSummaries(contentTree, summariesTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   191
     * Build the header for the given package.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   193
     * @param summariesTree the tree to which the package header will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   195
    protected void buildPackageHeader(Content summariesTree) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   196
        PackageElement abbrevPkg = configuration.workArounds.getAbbreviatedPackageElement(currentPackage);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   197
        if (!printedPackageHeaders.contains(abbrevPkg)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   198
            writer.addPackageName(currentPackage, summariesTree, first);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   199
            printedPackageHeaders.add(abbrevPkg);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   200
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * Build the summary for the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   206
     * @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
   207
     * @throws DocletException if there is a problem while building the documentation
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   208
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   210
    protected void buildClassConstantSummary(Content summariesTree)
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
   211
            throws DocletException {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   212
        SortedSet<TypeElement> classes = !currentPackage.isUnnamed()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   213
                ? utils.getAllClasses(currentPackage)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   214
                : configuration.typeElementCatalog.allUnnamedClasses();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   215
        Content classConstantTree = writer.getClassConstantHeader();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   216
        for (TypeElement te : classes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   217
            if (!typeElementsWithConstFields.contains(te) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   218
                !utils.isIncluded(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   221
            currentClass = te;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            //Build the documentation for the current class.
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   223
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   224
            buildConstantMembers(classConstantTree);
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   225
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        }
29957
7740f9657f56 8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents: 25874
diff changeset
   227
        writer.addClassConstant(summariesTree, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   231
     * 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
   232
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   233
     * @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
   234
     *                          will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   236
    protected void buildConstantMembers(Content classConstantTree) {
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   237
        new ConstantFieldBuilder(currentClass).buildMembersSummary(classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * Return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * @param pkg   the package being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   246
    private boolean hasConstantField(PackageElement pkg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   247
        SortedSet<TypeElement> classes = !pkg.isUnnamed()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   248
                  ? utils.getAllClasses(pkg)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   249
                  : configuration.typeElementCatalog.allUnnamedClasses();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        boolean found = false;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   251
        for (TypeElement te : classes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   252
            if (utils.isIncluded(te) && hasConstantField(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                found = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        return found;
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * Return true if the given class has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   262
     * @param typeElement the class being checked.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   265
    private boolean hasConstantField (TypeElement typeElement) {
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   266
        VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement);
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   267
        List<? extends Element> fields = vmt.getVisibleMembers(FIELDS);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   268
        for (Element f : fields) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   269
            VariableElement field = (VariableElement)f;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   270
            if (field.getConstantValue() != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   271
                typeElementsWithConstFields.add(typeElement);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * Return true if the given package name has been printed.  Also
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * return true if the root of this package has been printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     *
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   282
     * @param pkg the name of the package to check.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   284
    private boolean hasPrintedPackageIndex(PackageElement pkg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   285
        for (PackageElement printedPkg : printedPackageHeaders) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   286
            if (utils.getPackageName(pkg).startsWith(utils.parsePackageName(printedPkg))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * Print the table of constants.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    private class ConstantFieldBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   301
         * The typeElement that we are examining constants for.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   303
        protected TypeElement typeElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
         * Construct a ConstantFieldSubWriter.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   307
         * @param typeElement the typeElement that we are examining constants for.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   309
        public ConstantFieldBuilder(TypeElement typeElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   310
            this.typeElement = typeElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
         * 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
   315
         *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   316
         * @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
   317
         *                          will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
         */
45599
8bc3a019f948 8149146: [javadoc] eliminate doclet.xml
jjg
parents: 44460
diff changeset
   319
        protected void buildMembersSummary(Content classConstantTree) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   320
            SortedSet<VariableElement> members = members();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   321
            if (!members.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   322
                writer.addConstantMembers(typeElement, members, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        /**
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   327
         * 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
   328
         * @return the set of visible constant fields for the given type.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   330
        protected SortedSet<VariableElement> members() {
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   331
            VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement);
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   332
            List<Element> members = new ArrayList<>();
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   333
            members.addAll(vmt.getVisibleMembers(FIELDS));
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 47216
diff changeset
   334
            members.addAll(vmt.getVisibleMembers(ENUM_CONSTANTS));
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   335
            SortedSet<VariableElement> includes =
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   336
                    new TreeSet<>(utils.makeGeneralPurposeComparator());
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   337
            for (Element element : members) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   338
                VariableElement member = (VariableElement)element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 29957
diff changeset
   339
                if (member.getConstantValue() != null) {
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   340
                    includes.add(member);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            }
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 40587
diff changeset
   343
            return includes;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
}