langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/AbstractDoclet.java
author ksrini
Sun, 15 Jun 2014 08:41:57 -0700
changeset 25454 376a52c9540c
parent 22159 682da512ec17
permissions -rw-r--r--
8039028: [javadoc] refactor the usage of Util.java Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
     2
 * Copyright (c) 2003, 2014, 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: 1652
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: 1652
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: 1652
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
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;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    28
import com.sun.javadoc.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.doclets.internal.toolkit.builders.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * An abstract implementation of a Doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    35
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    36
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    37
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    38
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
public abstract class AbstractDoclet {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     * The global configuration information for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
     */
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    47
    public Configuration configuration;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    48
    /*
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    49
     *  a handle to our utility methods
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    50
     */
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    51
    protected Utils utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * The only doclet that may use this toolkit is {@value}
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    56
    private static final String TOOLKIT_DOCLET_NAME =
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    57
        com.sun.tools.doclets.formats.html.HtmlDoclet.class.getName();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * Verify that the only doclet that is using this toolkit is
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * {@value #TOOLKIT_DOCLET_NAME}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    private boolean isValidDoclet(AbstractDoclet doclet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
            configuration.message.error("doclet.Toolkit_Usage_Violation",
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
                TOOLKIT_DOCLET_NAME);
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * The method that starts the execution of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * @param doclet the doclet to start the execution for.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @param root   the {@link RootDoc} that points to the source to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * @return true if the doclet executed without error.  False otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public boolean start(AbstractDoclet doclet, RootDoc root) {
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    80
        configuration = configuration();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        configuration.root = root;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    82
        utils = configuration.utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        if (! isValidDoclet(doclet)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            doclet.startGeneration(root);
16324
332d7f5fdf62 8008949: javadoc stopped copying doc-files
jjg
parents: 15723
diff changeset
    88
        } catch (Configuration.Fault f) {
332d7f5fdf62 8008949: javadoc stopped copying doc-files
jjg
parents: 15723
diff changeset
    89
            root.printError(f.getMessage());
332d7f5fdf62 8008949: javadoc stopped copying doc-files
jjg
parents: 15723
diff changeset
    90
            return false;
20600
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    91
        } catch (DocletAbortException e) {
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    92
            Throwable cause = e.getCause();
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    93
            if (cause != null) {
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    94
                if (cause.getLocalizedMessage() != null) {
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    95
                    root.printError(cause.getLocalizedMessage());
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    96
                } else {
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    97
                    root.printError(cause.toString());
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    98
                }
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
    99
            }
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
   100
            return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        } catch (Exception exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * Indicate that this doclet supports the 1.5 language features.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @return JAVA_1_5, indicating that the new features are supported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    public static LanguageVersion languageVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        return LanguageVersion.JAVA_1_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * Create the configuration instance and returns it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * @return the configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    public abstract Configuration configuration();
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * Start the generation of files. Call generate methods in the individual
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14357
diff changeset
   124
     * writers, which will in turn generate the documentation files. Call the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * TreeWriter generation first to ensure the Class Hierarchy is built
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * first and then can be used in the later generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * @see com.sun.javadoc.RootDoc
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     */
16324
332d7f5fdf62 8008949: javadoc stopped copying doc-files
jjg
parents: 15723
diff changeset
   130
    private void startGeneration(RootDoc root) throws Configuration.Fault, Exception {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        if (root.classes().length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            configuration.message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                error("doclet.No_Public_Classes_To_Document");
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        configuration.setOptions();
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        configuration.getDocletSpecificMsg().notice("doclet.build_version",
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            configuration.getDocletSpecificBuildDate());
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        generateClassFiles(root, classtree);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
   142
        configuration.utils.copyDocFiles(configuration, DocPaths.DOC_FILES);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        PackageListWriter.generate(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        generatePackageFiles(classtree);
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   146
        generateProfileFiles();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        generateOtherFiles(root, classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        configuration.tagletManager.printReport();
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
     * Generate additional documentation that is added to the API documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * @param root      the RootDoc of source to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * @param classtree the data structure representing the class tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        BuilderFactory builderFactory = configuration.getBuilderFactory();
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        constantsSummaryBuilder.build();
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        serializedFormBuilder.build();
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   167
     * Generate the profile documentation.
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   168
     *
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   169
     */
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   170
    protected abstract void generateProfileFiles() throws Exception;
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   171
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14542
diff changeset
   172
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * Generate the package documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * @param classtree the data structure representing the class tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    protected abstract void generatePackageFiles(ClassTree classtree) throws Exception;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * Generate the class documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * @param classtree the data structure representing the class tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * Iterate through all classes and construct documentation for them.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * @param root      the RootDoc of source to document.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @param classtree the data structure representing the class tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    protected void generateClassFiles(RootDoc root, ClassTree classtree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        generateClassFiles(classtree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        PackageDoc[] packages = root.specifiedPackages();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20600
diff changeset
   195
        for (PackageDoc pkg : packages) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20600
diff changeset
   196
            generateClassFiles(pkg.allClasses(), classtree);
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * Generate the class files for single classes specified on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * @param classtree the data structure representing the class tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    private void generateClassFiles(ClassTree classtree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        String[] packageNames = configuration.classDocCatalog.packageNames();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20600
diff changeset
   207
        for (String packageName : packageNames) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            generateClassFiles(configuration.classDocCatalog.allClasses(
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 20600
diff changeset
   209
                    packageName), classtree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
}