langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/AbstractDoclet.java
author jjg
Mon, 22 Aug 2016 16:32:40 -0700
changeset 40587 1c355ea550ed
parent 40508 74ef30d16fb9
child 40605 926c13175b67
permissions -rw-r--r--
8164130: Simplify doclet IOException handling Reviewed-by: bpatel, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
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
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;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    37
import jdk.javadoc.doclets.StandardDoclet;
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;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    43
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
    44
import jdk.javadoc.internal.doclets.toolkit.util.InternalException;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
    45
import jdk.javadoc.internal.doclets.toolkit.util.PackageListWriter;
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
     */
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
    67
    private Configuration configuration;
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
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * {@value #TOOLKIT_DOCLET_NAME}.
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) {
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
   103
        configuration = configuration();
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   104
        configuration.docEnv = docEnv;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   105
        configuration.cmtUtils = new CommentUtils(configuration);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   106
        configuration.utils = new Utils(configuration);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22159
diff changeset
   107
        utils = configuration.utils;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   108
        configuration.workArounds = new WorkArounds(configuration);
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   109
        messages = configuration.getMessages();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   110
26269
0d8efbb110b4 8054925: [javadoc] refactor the Doclet start method.
ksrini
parents: 25874
diff changeset
   111
        if (!isValidDoclet()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   114
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   115
        boolean dumpOnError = false;  // set true to always show stack traces
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   116
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        try {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   118
            startGeneration(docEnv);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   119
            return true;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   120
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   121
        } catch (DocFileIOException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   122
            switch (e.mode) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   123
                case READ:
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   124
                    messages.error("doclet.exception.read.file",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   125
                            e.fileName.getPath(), e.getCause());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   126
                    break;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   127
                case WRITE:
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   128
                    messages.error("doclet.exception.write.file",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   129
                            e.fileName.getPath(), e.getCause());
20600
052970964bc1 6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents: 16324
diff changeset
   130
            }
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   131
            dumpStack(dumpOnError, e);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   132
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   133
        } catch (ResourceIOException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   134
            messages.error("doclet.exception.read.resource",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   135
                    e.resource.getPath(), e.getCause());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   136
            dumpStack(dumpOnError, e);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   137
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   138
        } catch (SimpleDocletException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   139
            configuration.reporter.print(ERROR, e.getMessage());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   140
            dumpStack(dumpOnError, e);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   141
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   142
        } catch (InternalException e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   143
            configuration.reporter.print(ERROR, e.getMessage());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   144
            reportInternalError(e.getCause());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   145
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   146
        } catch (DocletException | RuntimeException | Error e) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   147
            messages.error("doclet.internal.exception", e);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   148
            reportInternalError(e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        }
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   150
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   151
        return false;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   152
    }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   153
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   154
    private void reportInternalError(Throwable t) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   155
        if (getClass().equals(StandardDoclet.class) || getClass().equals(HtmlDoclet.class)) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   156
            System.err.println(configuration.getResources().getText("doclet.internal.report.bug"));
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   157
        }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   158
        dumpStack(true, t);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   159
    }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   160
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   161
    private void dumpStack(boolean enabled, Throwable t) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   162
        if (enabled && t != null) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   163
            t.printStackTrace(System.err);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   164
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   168
     * Returns the SourceVersion indicating the features supported by this doclet.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   169
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   170
     * @return SourceVersion
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     */
40315
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
   172
    @Override
9e994c77db6a 8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents: 40303
diff changeset
   173
    public SourceVersion getSupportedSourceVersion() {
39090
10c2cda4358d 8159396: javadoc getSupportedVersion returns 8 instead of 9
ksrini
parents: 36526
diff changeset
   174
        return SourceVersion.RELEASE_9;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * Create the configuration instance and returns it.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   180
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * @return the configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public abstract Configuration configuration();
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     * 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
   187
     * writers, which will in turn generate the documentation files. Call the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * TreeWriter generation first to ensure the Class Hierarchy is built
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * first and then can be used in the later generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   191
     * @see jdk.doclet.DocletEnvironment
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   192
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   194
    private void startGeneration(DocletEnvironment docEnv) throws DocletException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   195
        if (docEnv.getIncludedTypeElements().isEmpty()) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   196
            messages.error("doclet.No_Public_Classes_To_Document");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   199
        if (!configuration.setOptions()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   200
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   201
        }
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   202
        messages.notice("doclet.build_version",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            configuration.getDocletSpecificBuildDate());
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   206
        generateClassFiles(docEnv, classtree);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   207
        configuration.utils.copyDocFiles(DocPaths.DOC_FILES);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        PackageListWriter.generate(configuration);
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());
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   270
        packages.addAll(configuration.getSpecifiedPackages());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   271
        configuration.modulePackages.values().stream().forEach(pset -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   272
            packages.addAll(pset);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40315
diff changeset
   273
        });
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   274
        for (PackageElement pkg : packages) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   275
            generateClassFiles(utils.getAllClasses(pkg), classtree);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   276
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * Generate the class files for single classes specified on the command line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   282
     * @param classtree the data structure representing the class tree
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   283
     * @throws DocletException if there is a problem while generating the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   285
    private void generateClassFiles(ClassTree classtree) throws DocletException {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   286
        SortedSet<PackageElement> packages = configuration.typeElementCatalog.packages();
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   287
        for (PackageElement pkg : packages) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26269
diff changeset
   288
            generateClassFiles(configuration.typeElementCatalog.allClasses(pkg), classtree);
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40508
diff changeset
   289
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
}