langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ConstantsSummaryBuilder.java
author ohair
Tue, 25 May 2010 15:54:51 -0700
changeset 5520 86e4b9a9da40
parent 1789 7ac8c0815000
child 5855 00d9c252e60c
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
     2
 * Copyright (c) 2003, 2008, 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
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.doclets.internal.toolkit.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.*;
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * This code is not part of an API.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * It is implementation that is subject to change.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * Do not use it as an API
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
public class ConstantsSummaryBuilder extends AbstractBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     * The root element of the constant summary XML is {@value}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public static final String ROOT = "ConstantSummary";
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * The maximum number of package directories shown in the constant
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * value index.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    public static final int MAX_CONSTANT_VALUE_INDEX_LENGTH = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * The writer used to write the results.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    protected ConstantsSummaryWriter writer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * The set of ClassDocs that have constant fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    66
    protected Set<ClassDoc> classDocsWithConstFields;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * The set of printed package headers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    71
    protected Set<String> printedPackageHeaders;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * The current package being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private PackageDoc currentPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     * The current class being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    private ClassDoc currentClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * Construct a new ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * @param configuration the current configuration of the
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     *                      doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    private ConstantsSummaryBuilder(Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        super(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * Construct a ConstantsSummaryBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * @param configuration the configuration used in this run
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     *                      of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * @param writer        the writer for the summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public static ConstantsSummaryBuilder getInstance(
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        Configuration configuration, ConstantsSummaryWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        ConstantsSummaryBuilder builder = new ConstantsSummaryBuilder(
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        builder.writer = writer;
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   105
        builder.classDocsWithConstFields = new HashSet<ClassDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        return builder;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   112
    public void invokeMethod(String methodName, Class<?>[] paramClasses,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            Object[] params)
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        if (DEBUG) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            configuration.root.printError("DEBUG: " + this.getClass().getName()
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                + "." + methodName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        Method method = this.getClass().getMethod(methodName, paramClasses);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        method.invoke(this, params);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public void build() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        if (writer == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            //Doclet does not support this output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        build(LayoutParser.getInstance(configuration).parseXML(ROOT));
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    public String getName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        return ROOT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * Build the constant summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * @param elements the list of elements describing constant summary
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     *                 documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   147
    public void buildConstantSummary(List<?> elements) throws Exception {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        writer.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * Build the header.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public void buildHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        writer.writeHeader();
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 footer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public void buildFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        writer.writeFooter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * Build the table of contents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public void buildContents() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        writer.writeContentsHeader();
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        PackageDoc[] packages = configuration.packages;
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   172
        printedPackageHeaders = new HashSet<String>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        for (int i = 0; i < packages.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            if (hasConstantField(packages[i]) && ! hasPrintedPackageIndex(packages[i].name())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                writer.writeLinkToPackageContent(packages[i],
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                    parsePackageName(packages[i].name()),
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                    printedPackageHeaders);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        writer.writeContentsFooter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * Build the summary for each documented package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     * @param elements the XML elements that represent the components
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     *                 of documentation for each package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   189
    public void buildConstantSummaries(List<?> elements) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        PackageDoc[] packages = configuration.packages;
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   191
        printedPackageHeaders = new HashSet<String>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        for (int i = 0; i < packages.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            if (hasConstantField(packages[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                currentPackage = packages[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                //Build the documentation for the current package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
                build(elements);
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
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * Build the summary for the current package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * @param elements the list of XML elements that make up package
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     *                 documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   207
    public void buildPackageConstantSummary(List<?> elements) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * Build the summary for the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     * @param elements the list of XML elements that make up the class
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     *                 constant summary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   217
    public void buildClassConstantSummary(List<?> elements) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        ClassDoc[] classes = currentPackage.name().length() > 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            currentPackage.allClasses() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            configuration.classDocCatalog.allClasses(
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                DocletConstants.DEFAULT_PACKAGE_NAME);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        Arrays.sort(classes);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        for (int i = 0; i < classes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            if (! classDocsWithConstFields.contains(classes[i]) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                ! classes[i].isIncluded()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            currentClass = classes[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            //Build the documentation for the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     * Build the header for the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    public void buildPackageHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        String parsedPackageName = parsePackageName(currentPackage.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        if (! printedPackageHeaders.contains(parsedPackageName)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            writer.writePackageName(currentPackage,
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                parsePackageName(currentPackage.name()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            printedPackageHeaders.add(parsedPackageName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     * Build the header for the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public void buildClassHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        writer.writeConstantMembersHeader(currentClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     * Print summary of constant members in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    public void buildConstantMembers() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        new ConstantFieldBuilder(currentClass).buildMembersSummary();
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * Build the footer for the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    public void buildClassFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        writer.writeConstantMembersFooter(currentClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * Return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * @param pkg   the package being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    private boolean hasConstantField(PackageDoc pkg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        ClassDoc[] classes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        if (pkg.name().length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            classes = pkg.allClasses();
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            classes = configuration.classDocCatalog.allClasses(
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                DocletConstants.DEFAULT_PACKAGE_NAME);
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        boolean found = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        for (int j = 0; j < classes.length; j++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            if (classes[j].isIncluded() && hasConstantField(classes[j])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                found = 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 found;
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
     * Return true if the given class has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * @param classDoc the class being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * @return true if the given package has constant fields to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    private boolean hasConstantField (ClassDoc classDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        VisibleMemberMap visibleMemberMapFields = new VisibleMemberMap(classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            VisibleMemberMap.FIELDS, configuration.nodeprecated);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   300
        List<?> fields = visibleMemberMapFields.getLeafClassMembers(configuration);
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   301
        for (Iterator<?> iter = fields.iterator(); iter.hasNext(); ) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            FieldDoc field = (FieldDoc) iter.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
            if (field.constantValueExpression() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                classDocsWithConstFields.add(classDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     * Return true if the given package name has been printed.  Also
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     * return true if the root of this package has been printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     * @param pkgname the name of the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    private boolean hasPrintedPackageIndex(String pkgname) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   318
        String[] list = printedPackageHeaders.toArray(new String[] {});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        for (int i = 0; i < list.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            if (pkgname.startsWith(list[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
     * Print the table of constants.
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
     * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
     * @since 1.4
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    private class ConstantFieldBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
         * The map used to get the visible variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        protected VisibleMemberMap visibleMemberMapFields = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
         * The map used to get the visible variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        protected VisibleMemberMap visibleMemberMapEnumConst = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
         * The classdoc that we are examining constants for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        protected ClassDoc classdoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
         * Construct a ConstantFieldSubWriter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
         * @param classdoc the classdoc that we are examining constants for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        public ConstantFieldBuilder(ClassDoc classdoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            this.classdoc = classdoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            visibleMemberMapFields = new VisibleMemberMap(classdoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
                VisibleMemberMap.FIELDS, configuration.nodeprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            visibleMemberMapEnumConst = new VisibleMemberMap(classdoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                VisibleMemberMap.ENUM_CONSTANTS, configuration.nodeprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
         * Builds the table of constants for a given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        protected void buildMembersSummary() {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   366
            List<FieldDoc> members = new ArrayList<FieldDoc>(members());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            if (members.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                Collections.sort(members);
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                writer.writeConstantMembers(classdoc, members);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
         * Return the list of visible constant fields for the given classdoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
         * @param cd the classdoc to examine.
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
         * @return the list of visible constant fields for the given classdoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
         */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   378
        protected List<FieldDoc> members() {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   379
            List<ProgramElementDoc> l = visibleMemberMapFields.getLeafClassMembers(configuration);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            l.addAll(visibleMemberMapEnumConst.getLeafClassMembers(configuration));
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   381
            Iterator<ProgramElementDoc> iter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            if(l != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
                iter = l.iterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
            }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   388
            List<FieldDoc> inclList = new LinkedList<FieldDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            FieldDoc member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            while(iter.hasNext()){
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
                member = (FieldDoc)iter.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
                if(member.constantValue() != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
                    inclList.add(member);
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            return inclList;
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     * Parse the package name.  We only want to display package name up to
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
     * 2 levels.
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    private String parsePackageName(String pkgname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        int index = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        for (int j = 0; j < MAX_CONSTANT_VALUE_INDEX_LENGTH; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            index = pkgname.indexOf(".", index + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        if (index != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            pkgname = pkgname.substring(0, index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        return pkgname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
}