langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Messages.java
author ksrini
Mon, 05 Jun 2017 13:45:34 -0700
changeset 45417 f7479ee8de69
parent 40303 96a1226aca18
permissions -rw-r--r--
8177848: Rename Configuration(Impl) classes Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     1
/*
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40303
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     4
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    10
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    15
 * accompanied this code).
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    16
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    20
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    23
 * questions.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    24
 */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    25
package jdk.javadoc.internal.doclets.toolkit;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    26
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    27
import javax.lang.model.element.Element;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    28
import javax.tools.Diagnostic;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    29
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    30
import com.sun.source.util.DocTreePath;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    31
import jdk.javadoc.doclet.Reporter;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    32
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    33
import static javax.tools.Diagnostic.Kind.*;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    34
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    35
/**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    36
 * Provides standardized access to the diagnostic reporting facilities
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    37
 * for a doclet.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    38
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    39
 * Messages are specified by resource keys to be found in the doclet's
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    40
 * {@link Resources resources}.  Values can be substituted into the
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    41
 * strings obtained from the resource files.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    42
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    43
 * Messages are reported to the doclet's {@link Reporter reporter}.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    44
 */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    45
public class Messages {
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40303
diff changeset
    46
    private final BaseConfiguration configuration;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    47
    private final Resources resources;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    48
    private Reporter reporter;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    49
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    50
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    51
     * Creates a {@code Messages} object to provide standardized access to
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    52
     * the doclet's diagnostic reporting mechanisms.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    53
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    54
     * @param configuration the doclet's configuration, used to access
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    55
     *  the doclet's resources, reporter, and additional methods and state
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    56
     *  used to filter out messages, if any, which should be suppressed.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    57
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40303
diff changeset
    58
    public Messages(BaseConfiguration configuration) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    59
        this.configuration = configuration;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    60
        resources = configuration.getResources();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    61
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    62
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    63
    // ***** Errors *****
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    64
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    65
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    66
     * Reports an error message to the doclet's reporter.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    67
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    68
     * @param key the name of a resource containing the message to be printed
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    69
     * @param args optional arguments to be replaced in the message.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    70
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    71
    public void error(String key, Object... args) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    72
        report(ERROR, resources.getText(key, args));
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    73
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    74
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    75
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    76
     * Reports an error message to the doclet's reporter.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    77
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    78
     * @param path a path identifying the position to be included with
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    79
     *  the message
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    80
     * @param key the name of a resource containing the message to be printed
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    81
     * @param args optional arguments to be replaced in the message.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    82
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    83
    public void error(DocTreePath path, String key, Object... args) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    84
        report(ERROR, path, resources.getText(key, args));
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    85
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    86
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    87
    // ***** Warnings *****
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    88
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    89
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    90
     * Reports a warning message to the doclet's reporter.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    91
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    92
     * @param key the name of a resource containing the message to be printed
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    93
     * @param args optional arguments to be replaced in the message.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    94
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    95
    public void warning(String key, Object... args) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    96
        report(WARNING, resources.getText(key, args));
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    97
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    98
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    99
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   100
     * Reports a warning message to the doclet's reporter.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   101
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   102
     * @param path a path identifying the position to be included with
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   103
     *  the message
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   104
     * @param key the name of a resource containing the message to be printed
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   105
     * @param args optional arguments to be replaced in the message.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   106
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   107
    public void warning(DocTreePath path, String key, Object... args) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   108
        if (configuration.showMessage(path, key))
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   109
            report(WARNING, path, resources.getText(key, args));
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   110
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   111
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   112
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   113
     * Reports a warning message to the doclet's reporter.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   114
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   115
     * @param e an element identifying the declaration whose position should
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   116
     *  to be included with the message
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   117
     * @param key the name of a resource containing the message to be printed
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   118
     * @param args optional arguments to be replaced in the message.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   119
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   120
    public void warning(Element e, String key, Object... args) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   121
        if (configuration.showMessage(e, key)) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   122
            report(WARNING, e, resources.getText(key, args));
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   123
        }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   124
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   125
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   126
    // ***** Notices *****
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   127
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   128
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   129
     * Reports an informational notice to the doclet's reporter.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   130
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   131
     * @param key the name of a resource containing the message to be printed
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   132
     * @param args optional arguments to be replaced in the message.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   133
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   134
    public void notice(String key, Object... args) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   135
        if (!configuration.quiet) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   136
            report(NOTE, resources.getText(key, args));
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   137
        }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   138
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   139
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   140
    // ***** Internal support *****
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   141
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   142
    private void report(Diagnostic.Kind k, String msg) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   143
        initReporter();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   144
        reporter.print(k, msg);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   145
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   146
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   147
    private void report(Diagnostic.Kind k, DocTreePath p, String msg) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   148
        initReporter();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   149
        reporter.print(k, p, msg);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   150
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   151
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   152
    private void report(Diagnostic.Kind k, Element e, String msg) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   153
        initReporter();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   154
        reporter.print(k, e, msg);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   155
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   156
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   157
    // Lazy init the reporter for now, until we can fix/improve
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40303
diff changeset
   158
    // the init of HtmlConfiguration in HtmlDoclet (and similar.)
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   159
    private void initReporter() {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   160
        if (reporter == null) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   161
            reporter = configuration.reporter;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   162
        }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   163
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   164
}