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