src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
author jlahoda
Mon, 21 Oct 2019 15:38:26 +0200
changeset 58713 ad69fd32778e
parent 55495 badfa812b82a
permissions -rw-r--r--
8226585: Improve javac messages for using a preview API Summary: Avoiding deprecation for removal for APIs associated with preview features, the features are marked with an annotation, and errors/warnings are produced for them based on the annotation. Reviewed-by: erikj, mcimadamore, alanb Contributed-by: joe.darcy@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
55495
badfa812b82a 8226785: MandatoryWarningHandler.java contains implementation of Objects.equals functionality
darcy
parents: 48721
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.HashSet;
55495
badfa812b82a 8226785: MandatoryWarningHandler.java contains implementation of Objects.equals functionality
darcy
parents: 48721
diff changeset
    29
import java.util.Objects;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
    33
import com.sun.tools.javac.code.Lint.LintCategory;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
    35
import com.sun.tools.javac.util.JCDiagnostic.Note;
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
    36
import com.sun.tools.javac.util.JCDiagnostic.Warning;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * A handler to process mandatory warnings, setting up a deferred diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * to be printed at the end of the compilation if some warnings get suppressed
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * because too many warnings have already been generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * Note that the SuppressWarnings annotation can be used to suppress warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * about conditions that would otherwise merit a warning. Such processing
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * is done when the condition is detected, and in those cases, no call is
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * made on any API to generate a warning at all. In consequence, this handler only
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 22163
diff changeset
    48
 * Returns to handle those warnings that JLS says must be generated.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    50
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    51
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
public class MandatoryWarningHandler {
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * The kinds of different deferred diagnostics that might be generated
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * if a mandatory warning is suppressed because too many warnings have
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * already been output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * The parameter is a fragment used to build an I18N message key for Log.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    private enum DeferredDiagnosticKind {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
         * This kind is used when a single specific file is found to have warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
         * and no similar warnings have already been given.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
         *      FILE has ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        IN_FILE(".filename"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
         * This kind is used when a single specific file is found to have warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
         * and when similar warnings have already been reported for the file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
         *      FILE has additional ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        ADDITIONAL_IN_FILE(".filename.additional"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
         * This kind is used when multiple files have been found to have warnings,
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
         * and none of them have had any similar warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
         *      Some files have ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        IN_FILES(".plural"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
         * This kind is used when multiple files have been found to have warnings,
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
         * and some of them have had already had specific similar warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
         *      Some files have additional ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        ADDITIONAL_IN_FILES(".plural.additional");
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        DeferredDiagnosticKind(String v) { value = v; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        String getKey(String prefix) { return prefix + value; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 7681
diff changeset
    97
        private final String value;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * Create a handler for mandatory warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * @param log     The log on which to generate any diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * @param verbose Specify whether or not detailed messages about
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     *                individual instances should be given, or whether an aggregate
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     *                message should be generated at the end of the compilation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *                Typically set via  -Xlint:option.
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   108
     * @param enforceMandatory
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   109
     *                True if mandatory warnings and notes are being enforced.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * @param prefix  A common prefix for the set of message keys for
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     *                the messages that may be generated.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   112
     * @param lc      An associated lint category for the warnings, or null if none.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     */
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   114
    public MandatoryWarningHandler(Log log, boolean verbose,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   115
                                   boolean enforceMandatory, String prefix,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   116
                                   LintCategory lc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        this.log = log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        this.verbose = verbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        this.prefix = prefix;
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   120
        this.enforceMandatory = enforceMandatory;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   121
        this.lintCategory = lc;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * Report a mandatory warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   127
    public void report(DiagnosticPosition pos, Warning warnKey) {
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 813
diff changeset
   128
        JavaFileObject currentSource = log.currentSourceFile();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        if (verbose) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            if (sourcesWithReportedWarnings == null)
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14801
diff changeset
   132
                sourcesWithReportedWarnings = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            if (log.nwarnings < log.MaxWarnings) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                // generate message and remember the source file
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   136
                logMandatoryWarning(pos, warnKey);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                sourcesWithReportedWarnings.add(currentSource);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            } else if (deferredDiagnosticKind == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                // set up deferred message
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                if (sourcesWithReportedWarnings.contains(currentSource)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                    // more errors in a file that already has reported warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                    deferredDiagnosticKind = DeferredDiagnosticKind.ADDITIONAL_IN_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                    // warnings in a new source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                    deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                deferredDiagnosticSource = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                deferredDiagnosticArg = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
            } else if ((deferredDiagnosticKind == DeferredDiagnosticKind.IN_FILE
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                        || deferredDiagnosticKind == DeferredDiagnosticKind.ADDITIONAL_IN_FILE)
55495
badfa812b82a 8226785: MandatoryWarningHandler.java contains implementation of Objects.equals functionality
darcy
parents: 48721
diff changeset
   151
                       && !Objects.equals(deferredDiagnosticSource, currentSource)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                // additional errors in more than one source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                deferredDiagnosticKind = DeferredDiagnosticKind.ADDITIONAL_IN_FILES;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                deferredDiagnosticArg = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            if (deferredDiagnosticKind == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                // warnings in a single source
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                deferredDiagnosticSource = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                deferredDiagnosticArg = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            }  else if (deferredDiagnosticKind == DeferredDiagnosticKind.IN_FILE &&
55495
badfa812b82a 8226785: MandatoryWarningHandler.java contains implementation of Objects.equals functionality
darcy
parents: 48721
diff changeset
   163
                        !Objects.equals(deferredDiagnosticSource, currentSource)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                // warnings in multiple source files
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILES;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                deferredDiagnosticArg = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * Report any diagnostic that might have been deferred by previous calls of report().
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    public void reportDeferredDiagnostic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        if (deferredDiagnosticKind != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            if (deferredDiagnosticArg == null)
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   177
                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            else
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   179
                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            if (!verbose)
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   182
                logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * The log to which to report warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     */
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   189
    private final Log log;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * Whether or not to report individual warnings, or simply to report a
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * single aggregate warning at the end of the compilation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     */
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   195
    private final boolean verbose;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * The common prefix for all I18N message keys generated by this handler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     */
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   200
    private final String prefix;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * A set containing the names of the source files for which specific
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * warnings have been generated -- i.e. in verbose mode.  If a source name
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * appears in this list, then deferred diagnostics will be phrased to
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * include "additionally"...
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    private Set<JavaFileObject> sourcesWithReportedWarnings;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * A variable indicating the latest best guess at what the final
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * deferred diagnostic will be. Initially as specific and helpful
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * as possible, as more warnings are reported, the scope of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     * diagnostic will be broadened.
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    private DeferredDiagnosticKind deferredDiagnosticKind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * If deferredDiagnosticKind is IN_FILE or ADDITIONAL_IN_FILE, this variable
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * gives the value of log.currentSource() for the file in question.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    private JavaFileObject deferredDiagnosticSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * An optional argument to be used when constructing the
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     * deferred diagnostic message, based on deferredDiagnosticKind.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     * This variable should normally be set/updated whenever
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * deferredDiagnosticKind is updated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    private Object deferredDiagnosticArg;
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   231
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   232
    /**
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   233
     * True if mandatory warnings and notes are being enforced.
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   234
     */
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   235
    private final boolean enforceMandatory;
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   236
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   237
    /**
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   238
     * A LintCategory to be included in point-of-use diagnostics to indicate
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   239
     * how messages might be suppressed (i.e. with @SuppressWarnings).
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   240
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   241
    private final LintCategory lintCategory;
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   242
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   243
    /**
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   244
     * Reports a mandatory warning to the log.  If mandatory warnings
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   245
     * are not being enforced, treat this as an ordinary warning.
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   246
     */
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   247
    private void logMandatoryWarning(DiagnosticPosition pos, Warning warnKey) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   248
        // Note: the following log methods are safe if lintCategory is null.
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   249
        if (enforceMandatory)
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   250
            log.mandatoryWarning(lintCategory, pos, warnKey);
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   251
        else
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   252
            log.warning(lintCategory, pos, warnKey);
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   253
    }
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   254
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   255
    /**
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   256
     * Reports a mandatory note to the log.  If mandatory notes are
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   257
     * not being enforced, treat this as an ordinary note.
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   258
     */
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   259
    private void logMandatoryNote(JavaFileObject file, String msg, Object... args) {
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   260
        if (enforceMandatory)
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   261
            log.mandatoryNote(file, new Note("compiler", msg, args));
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   262
        else
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   263
            log.note(file, new Note("compiler", msg, args));
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   264
    }
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   265
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   266
    public void clear() {
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   267
        sourcesWithReportedWarnings = null;
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   268
        deferredDiagnosticKind = null;
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   269
        deferredDiagnosticSource = null;
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   270
        deferredDiagnosticArg = null;
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55495
diff changeset
   271
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
}