src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java
author ksrini
Tue, 24 Apr 2018 11:54:03 -0700
changeset 49879 601277b1d582
parent 48295 c79d31ba84b9
permissions -rw-r--r--
8025091: VisibleMemberMap.java possible performance improvements 8198890: The standard doclet incorrectly produces wrong method signatures in certain cases. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 48295
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    27
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    28
import java.util.SortedSet;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    29
import java.util.TreeSet;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    30
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    31
import javax.lang.model.SourceVersion;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    32
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    33
import javax.lang.model.element.TypeElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
40315
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
    35
import jdk.javadoc.doclet.Doclet;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    36
import jdk.javadoc.doclet.DocletEnvironment;
44189
dd311cfb920b 8176331: Simplify new doclet packages
jjg
parents: 43261
diff changeset
    37
import jdk.javadoc.doclet.StandardDoclet;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    38
import jdk.javadoc.internal.doclets.formats.html.HtmlDoclet;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    39
import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    40
import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    41
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    42
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
    43
import jdk.javadoc.internal.doclets.toolkit.util.UncheckedDocletException;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    44
import jdk.javadoc.internal.doclets.toolkit.util.InternalException;
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 48254
diff changeset
    45
import jdk.javadoc.internal.doclets.toolkit.util.ElementListWriter;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    46
import jdk.javadoc.internal.doclets.toolkit.util.ResourceIOException;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    47
import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    48
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    49
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    50
import static javax.tools.Diagnostic.Kind.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * An abstract implementation of a Doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    55
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    56
 *  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
    57
 *  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
    58
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 */
40315
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
    62
public abstract class AbstractDoclet implements Doclet {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * The global configuration information for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 44189
diff changeset
    67
    private BaseConfiguration configuration;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
    68
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
    69
    protected Messages messages;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
    70
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    71
    /*
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    72
     *  a handle to our utility methods
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    73
     */
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
    74
    protected Utils utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * The only doclet that may use this toolkit is {@value}
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14368
diff changeset
    79
    private static final String TOOLKIT_DOCLET_NAME =
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    80
        jdk.javadoc.internal.doclets.formats.html.HtmlDoclet.class.getName();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * Verify that the only doclet that is using this toolkit is
49879
601277b1d582 8025091: VisibleMemberMap.java possible performance improvements
ksrini
parents: 48295
diff changeset
    84
     * #TOOLKIT_DOCLET_NAME.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
26269
0d8efbb110b4 8054925: [javadoc] refactor the Doclet start method.
ksrini
parents: 25874
diff changeset
    86
    private boolean isValidDoclet() {
0d8efbb110b4 8054925: [javadoc] refactor the Doclet start method.
ksrini
parents: 25874
diff changeset
    87
        if (!getClass().getName().equals(TOOLKIT_DOCLET_NAME)) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
    88
            messages.error("doclet.Toolkit_Usage_Violation",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                TOOLKIT_DOCLET_NAME);
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * The method that starts the execution of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     *
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
    98
     * @param docEnv   the {@link DocletEnvironment}.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * @return true if the doclet executed without error.  False otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
40315
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
   101
    @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   102
    public boolean run(DocletEnvironment docEnv) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   103
        configuration = getConfiguration();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   104
        configuration.initConfiguration(docEnv);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
   105
        utils = configuration.utils;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   106
        messages = configuration.getMessages();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   107
26269
0d8efbb110b4 8054925: [javadoc] refactor the Doclet start method.
ksrini
parents: 25874
diff changeset
   108
        if (!isValidDoclet()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   111
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        try {
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   113
            try {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   114
                startGeneration(docEnv);
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   115
                return true;
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   116
            } catch (UncheckedDocletException e) {
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   117
                throw (DocletException) e.getCause();
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   118
            }
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   119
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   120
        } catch (DocFileIOException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   121
            switch (e.mode) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   122
                case READ:
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   123
                    messages.error("doclet.exception.read.file",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   124
                            e.fileName.getPath(), e.getCause());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   125
                    break;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   126
                case WRITE:
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   127
                    messages.error("doclet.exception.write.file",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   128
                            e.fileName.getPath(), e.getCause());
20600
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
   129
            }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40605
diff changeset
   130
            dumpStack(configuration.dumpOnError, e);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   131
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   132
        } catch (ResourceIOException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   133
            messages.error("doclet.exception.read.resource",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   134
                    e.resource.getPath(), e.getCause());
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40605
diff changeset
   135
            dumpStack(configuration.dumpOnError, e);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   136
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   137
        } catch (SimpleDocletException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   138
            configuration.reporter.print(ERROR, e.getMessage());
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40605
diff changeset
   139
            dumpStack(configuration.dumpOnError, e);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   140
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   141
        } catch (InternalException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   142
            configuration.reporter.print(ERROR, e.getMessage());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   143
            reportInternalError(e.getCause());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   144
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   145
        } catch (DocletException | RuntimeException | Error e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   146
            messages.error("doclet.internal.exception", e);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   147
            reportInternalError(e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        }
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   149
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   150
        return false;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   151
    }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   152
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   153
    private void reportInternalError(Throwable t) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   154
        if (getClass().equals(StandardDoclet.class) || getClass().equals(HtmlDoclet.class)) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   155
            System.err.println(configuration.getResources().getText("doclet.internal.report.bug"));
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   156
        }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   157
        dumpStack(true, t);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   158
    }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   159
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   160
    private void dumpStack(boolean enabled, Throwable t) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   161
        if (enabled && t != null) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   162
            t.printStackTrace(System.err);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   163
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   167
     * Returns the SourceVersion indicating the features supported by this doclet.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   168
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   169
     * @return SourceVersion
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
40315
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
   171
    @Override
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
   172
    public SourceVersion getSupportedSourceVersion() {
39090
10c2cda4358d 8159396: javadoc getSupportedVersion returns 8 instead of 9
ksrini
parents: 36526
diff changeset
   173
        return SourceVersion.RELEASE_9;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * Create the configuration instance and returns it.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   178
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * @return the configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 44189
diff changeset
   181
    public abstract BaseConfiguration getConfiguration();
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
     * 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
   185
     * writers, which will in turn generate the documentation files. Call the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     * TreeWriter generation first to ensure the Class Hierarchy is built
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * first and then can be used in the later generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   189
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   191
    private void startGeneration(DocletEnvironment docEnv) throws DocletException {
48254
111104f1e033 8193107: javadoc complains about empty module
ksrini
parents: 47849
diff changeset
   192
111104f1e033 8193107: javadoc complains about empty module
ksrini
parents: 47849
diff changeset
   193
        // Modules with no documented classes may be specified on the
111104f1e033 8193107: javadoc complains about empty module
ksrini
parents: 47849
diff changeset
   194
        // command line to specify a service provider, allow these.
111104f1e033 8193107: javadoc complains about empty module
ksrini
parents: 47849
diff changeset
   195
        if (configuration.getSpecifiedModuleElements().isEmpty() &&
111104f1e033 8193107: javadoc complains about empty module
ksrini
parents: 47849
diff changeset
   196
                configuration.getIncludedTypeElements().isEmpty()) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   197
            messages.error("doclet.No_Public_Classes_To_Document");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   200
        if (!configuration.setOptions()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   201
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   202
        }
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   203
        messages.notice("doclet.build_version",
47849
0e38db7cf1cc 8190820: Introduce a new Head builder class
jjg
parents: 47216
diff changeset
   204
            configuration.getDocletVersion());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   207
        generateClassFiles(docEnv, classtree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 48254
diff changeset
   209
        ElementListWriter.generate(configuration);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        generatePackageFiles(classtree);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   211
        generateModuleFiles();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   213
        generateOtherFiles(docEnv, classtree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        configuration.tagletManager.printReport();
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * Generate additional documentation that is added to the API documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   220
     * @param docEnv     the DocletEnvironment
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   221
     * @param classtree the data structure representing the class tree
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   222
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   224
    protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree)
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   225
            throws DocletException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        BuilderFactory builderFactory = configuration.getBuilderFactory();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   227
        AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        constantsSummaryBuilder.build();
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        serializedFormBuilder.build();
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   234
     * Generate the module documentation.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   235
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   236
     * @throws DocletException if there is a problem while generating the documentation
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   237
     *
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   238
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   239
    protected abstract void generateModuleFiles() throws DocletException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   240
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   241
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * Generate the package documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   244
     * @param classtree the data structure representing the class tree
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   245
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   247
    protected abstract void generatePackageFiles(ClassTree classtree) throws DocletException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * Generate the class documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   252
     * @param arr the set of types to be documented
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   253
     * @param classtree the data structure representing the class tree
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   254
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   256
    protected abstract void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree)
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   257
            throws DocletException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * Iterate through all classes and construct documentation for them.
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   262
     * @param docEnv      the DocletEnvironment
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   263
     * @param classtree the data structure representing the class tree
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   264
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   266
    protected void generateClassFiles(DocletEnvironment docEnv, ClassTree classtree)
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   267
            throws DocletException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        generateClassFiles(classtree);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   269
        SortedSet<PackageElement> packages = new TreeSet<>(utils.makePackageComparator());
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41451
diff changeset
   270
        packages.addAll(configuration.getSpecifiedPackageElements());
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42277
diff changeset
   271
        configuration.modulePackages.values().stream().forEach(packages::addAll);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   272
        for (PackageElement pkg : packages) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   273
            generateClassFiles(utils.getAllClasses(pkg), classtree);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   274
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     * Generate the class files for single classes specified on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   280
     * @param classtree the data structure representing the class tree
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   281
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   283
    private void generateClassFiles(ClassTree classtree) throws DocletException {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   284
        SortedSet<PackageElement> packages = configuration.typeElementCatalog.packages();
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   285
        for (PackageElement pkg : packages) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   286
            generateClassFiles(configuration.typeElementCatalog.allClasses(pkg), classtree);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   287
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
}