langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ConstantsSummaryBuilder.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 22159 682da512ec17
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14542
diff changeset
     2
 * Copyright (c) 2003, 2013, 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
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.builders;
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.io.*;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    29
import java.util.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 7681
diff changeset
    30
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    31
import com.sun.javadoc.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 7681
diff changeset
    32
import com.sun.tools.doclets.internal.toolkit.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Builds the Constants Summary Page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    38
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    39
 *  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
    40
 *  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
    41
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @author Jamie Ho
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    44
 * @author Bhavesh Patel (Modified)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public class ConstantsSummaryBuilder extends AbstractBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * The root element of the constant summary XML is {@value}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    public static final String ROOT = "ConstantSummary";
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * The maximum number of package directories shown in the constant
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * value index.
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    public static final int MAX_CONSTANT_VALUE_INDEX_LENGTH = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * The writer used to write the results.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    63
    protected final ConstantsSummaryWriter writer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * The set of ClassDocs that have constant fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    68
    protected final Set<ClassDoc> classDocsWithConstFields;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * The set of printed package headers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    73
    protected Set<String> printedPackageHeaders;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * The current package being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    private PackageDoc currentPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * The current class being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private ClassDoc currentClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    86
     * 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
    87
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    88
    private Content contentTree;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    89
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
    90
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * Construct a new ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     *
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    93
     * @param context       the build context.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    94
     * @param writer        the writer for the summary.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    96
    private ConstantsSummaryBuilder(Context context,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    97
            ConstantsSummaryWriter writer) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    98
        super(context);
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
    99
        this.writer = writer;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   100
        this.classDocsWithConstFields = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * Construct a ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     *
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   106
     * @param context       the build context.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * @param writer        the writer for the summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   109
    public static ConstantsSummaryBuilder getInstance(Context context,
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   110
            ConstantsSummaryWriter writer) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   111
        return new ConstantsSummaryBuilder(context, writer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public void build() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        if (writer == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            //Doclet does not support this output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        }
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14260
diff changeset
   122
        build(layoutParser.parseXML(ROOT), contentTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    public String getName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        return ROOT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * Build the constant summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   135
     * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   136
     * @param contentTree the content tree to which the documentation will be added
10
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
    public void buildConstantSummary(XMLNode node, Content contentTree) throws Exception {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   139
        contentTree = writer.getHeader();
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   140
        buildChildren(node, contentTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   141
        writer.addFooter(contentTree);
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
        writer.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   147
     * Build the list of packages.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   148
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   149
     * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   150
     * @param contentTree the content tree to which the content list will be added
10
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
    public void buildContents(XMLNode node, Content contentTree) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   153
        Content contentListTree = writer.getContentsHeader();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   154
        printedPackageHeaders = new HashSet<>();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   155
        for (PackageDoc pkg : configuration.packages) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   156
            if (hasConstantField(pkg) && !hasPrintedPackageIndex(pkg.name())) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   157
                writer.addLinkToPackageContent(pkg,
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   158
                                               parsePackageName(pkg.name()),
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   159
                                               printedPackageHeaders, contentListTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   162
        contentTree.addContent(writer.getContentsList(contentListTree));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * Build the summary for each documented package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   168
     * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   169
     * @param contentTree the tree to which the summaries will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   171
    public void buildConstantSummaries(XMLNode node, Content contentTree) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   172
        printedPackageHeaders = new HashSet<>();
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   173
        Content summariesTree = writer.getConstantSummaries();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   174
        for (PackageDoc aPackage : configuration.packages) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   175
            if (hasConstantField(aPackage)) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   176
                currentPackage = aPackage;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                //Build the documentation for the current package.
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   178
                buildChildren(node, summariesTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   181
        contentTree.addContent(summariesTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   185
     * Build the header for the given package.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   187
     * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   188
     * @param summariesTree the tree to which the package header will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   190
    public void buildPackageHeader(XMLNode node, Content summariesTree) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   191
        String parsedPackageName = parsePackageName(currentPackage.name());
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   192
        if (! printedPackageHeaders.contains(parsedPackageName)) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   193
            writer.addPackageName(currentPackage,
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   194
                parsePackageName(currentPackage.name()), summariesTree);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   195
            printedPackageHeaders.add(parsedPackageName);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   196
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * Build the summary for the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   202
     * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   203
     * @param summariesTree the tree to which the class constant summary will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   205
    public void buildClassConstantSummary(XMLNode node, Content summariesTree) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        ClassDoc[] classes = currentPackage.name().length() > 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            currentPackage.allClasses() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            configuration.classDocCatalog.allClasses(
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                DocletConstants.DEFAULT_PACKAGE_NAME);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        Arrays.sort(classes);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   211
        Content classConstantTree = writer.getClassConstantHeader();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   212
        for (ClassDoc doc : classes) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   213
            if (!classDocsWithConstFields.contains(doc) ||
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   214
                !doc.isIncluded()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            }
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   217
            currentClass = doc;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            //Build the documentation for the current class.
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   219
            buildChildren(node, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   221
        summariesTree.addContent(classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   225
     * 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
   226
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   227
     * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   228
     * @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
   229
     *                          will be added
10
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
    public void buildConstantMembers(XMLNode node, Content classConstantTree) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   232
        new ConstantFieldBuilder(currentClass).buildMembersSummary(node, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
     * Return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * @param pkg   the package being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    private boolean hasConstantField(PackageDoc pkg) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   242
        ClassDoc[] classes
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   243
                = (pkg.name().length() > 0)
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   244
                  ? pkg.allClasses()
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   245
                  : configuration.classDocCatalog.allClasses(DocletConstants.DEFAULT_PACKAGE_NAME);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        boolean found = false;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   247
        for (ClassDoc doc : classes) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   248
            if (doc.isIncluded() && hasConstantField(doc)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                found = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        return found;
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
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 true if the given class has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     * @param classDoc the class being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    private boolean hasConstantField (ClassDoc classDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        VisibleMemberMap visibleMemberMapFields = new VisibleMemberMap(classDoc,
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14542
diff changeset
   263
            VisibleMemberMap.FIELDS, configuration);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   264
        List<?> fields = visibleMemberMapFields.getLeafClassMembers(configuration);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   265
        for (Object f : fields) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   266
            FieldDoc field = (FieldDoc) f;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            if (field.constantValueExpression() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                classDocsWithConstFields.add(classDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     * Return true if the given package name has been printed.  Also
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * return true if the root of this package has been printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * @param pkgname the name of the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    private boolean hasPrintedPackageIndex(String pkgname) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   282
        String[] list = printedPackageHeaders.toArray(new String[] {});
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   283
        for (String packageHeader : list) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   284
            if (pkgname.startsWith(packageHeader)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     * Print the table of constants.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * @since 1.4
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    private class ConstantFieldBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
         * The map used to get the visible variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        protected VisibleMemberMap visibleMemberMapFields = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
         * The map used to get the visible variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        protected VisibleMemberMap visibleMemberMapEnumConst = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
         * The classdoc that we are examining constants for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        protected ClassDoc classdoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
         * Construct a ConstantFieldSubWriter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
         * @param classdoc the classdoc that we are examining constants for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        public ConstantFieldBuilder(ClassDoc classdoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
            this.classdoc = classdoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            visibleMemberMapFields = new VisibleMemberMap(classdoc,
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14542
diff changeset
   321
                VisibleMemberMap.FIELDS, configuration);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            visibleMemberMapEnumConst = new VisibleMemberMap(classdoc,
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14542
diff changeset
   323
                VisibleMemberMap.ENUM_CONSTANTS, configuration);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
         * 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
   328
         *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   329
         * @param node the XML element that specifies which components to document
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   330
         * @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
   331
         *                          will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
         */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   333
        protected void buildMembersSummary(XMLNode node, Content classConstantTree) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   334
            List<FieldDoc> members = new ArrayList<>(members());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
            if (members.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                Collections.sort(members);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5855
diff changeset
   337
                writer.addConstantMembers(classdoc, members, classConstantTree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
         * Return the list of visible constant fields for the given classdoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
         * @return the list of visible constant fields for the given classdoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
         */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   345
        protected List<FieldDoc> members() {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   346
            List<ProgramElementDoc> l = visibleMemberMapFields.getLeafClassMembers(configuration);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            l.addAll(visibleMemberMapEnumConst.getLeafClassMembers(configuration));
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   348
            Iterator<ProgramElementDoc> iter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            if(l != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                iter = l.iterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   355
            List<FieldDoc> inclList = new LinkedList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            FieldDoc member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            while(iter.hasNext()){
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                member = (FieldDoc)iter.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                if(member.constantValue() != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                    inclList.add(member);
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            return inclList;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     * Parse the package name.  We only want to display package name up to
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     * 2 levels.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    private String parsePackageName(String pkgname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        int index = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        for (int j = 0; j < MAX_CONSTANT_VALUE_INDEX_LENGTH; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            index = pkgname.indexOf(".", index + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        if (index != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            pkgname = pkgname.substring(0, index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        return pkgname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
}