langtools/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
author vromero
Mon, 10 Dec 2012 16:21:26 +0000
changeset 14801 d66cab4ef397
parent 7681 1f0819a3341f
child 22163 3651128c74eb
permissions -rw-r--r--
8003967: detect and remove all mutable implicit static enum fields in langtools Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 7681
diff changeset
     2
 * Copyright (c) 2005, 2012, 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;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
    32
import com.sun.tools.javac.code.Lint.LintCategory;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * A handler to process mandatory warnings, setting up a deferred diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * to be printed at the end of the compilation if some warnings get suppressed
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * because too many warnings have already been generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * Note that the SuppressWarnings annotation can be used to suppress warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * about conditions that would otherwise merit a warning. Such processing
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * is done when the condition is detected, and in those cases, no call is
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * made on any API to generate a warning at all. In consequence, this handler only
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * gets to handle those warnings that JLS says must be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    47
 *  <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
    48
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
public class MandatoryWarningHandler {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * The kinds of different deferred diagnostics that might be generated
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * if a mandatory warning is suppressed because too many warnings have
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * already been output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * The parameter is a fragment used to build an I18N message key for Log.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    private enum DeferredDiagnosticKind {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
         * This kind is used when a single specific file is found to have warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
         * and no similar warnings have already been given.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
         *      FILE has ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        IN_FILE(".filename"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
         * This kind is used when a single specific file is found to have warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
         * and when similar warnings have already been reported for the file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
         *      FILE has additional ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        ADDITIONAL_IN_FILE(".filename.additional"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
         * This kind is used when multiple files have been found to have warnings,
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
         * and none of them have had any similar warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
         *      Some files have ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        IN_FILES(".plural"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
         * This kind is used when multiple files have been found to have warnings,
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
         * and some of them have had already had specific similar warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
         * It generates a message like:
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
         *      Some files have additional ISSUES
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        ADDITIONAL_IN_FILES(".plural.additional");
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        DeferredDiagnosticKind(String v) { value = v; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        String getKey(String prefix) { return prefix + value; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
14801
d66cab4ef397 8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents: 7681
diff changeset
    94
        private final String value;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * Create a handler for mandatory warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * @param log     The log on which to generate any diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * @param verbose Specify whether or not detailed messages about
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     *                individual instances should be given, or whether an aggregate
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     *                message should be generated at the end of the compilation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     *                Typically set via  -Xlint:option.
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   105
     * @param enforceMandatory
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   106
     *                True if mandatory warnings and notes are being enforced.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * @param prefix  A common prefix for the set of message keys for
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     *                the messages that may be generated.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   109
     * @param lc      An associated lint category for the warnings, or null if none.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     */
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   111
    public MandatoryWarningHandler(Log log, boolean verbose,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   112
                                   boolean enforceMandatory, String prefix,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   113
                                   LintCategory lc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        this.log = log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        this.verbose = verbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        this.prefix = prefix;
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   117
        this.enforceMandatory = enforceMandatory;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   118
        this.lintCategory = lc;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     * Report a mandatory warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    public void report(DiagnosticPosition pos, String msg, Object... args) {
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 813
diff changeset
   125
        JavaFileObject currentSource = log.currentSourceFile();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        if (verbose) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            if (sourcesWithReportedWarnings == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                sourcesWithReportedWarnings = new HashSet<JavaFileObject>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            if (log.nwarnings < log.MaxWarnings) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                // generate message and remember the source file
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   133
                logMandatoryWarning(pos, msg, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                sourcesWithReportedWarnings.add(currentSource);
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            } else if (deferredDiagnosticKind == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                // set up deferred message
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                if (sourcesWithReportedWarnings.contains(currentSource)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                    // more errors in a file that already has reported warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                    deferredDiagnosticKind = DeferredDiagnosticKind.ADDITIONAL_IN_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                    // warnings in a new source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                    deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                deferredDiagnosticSource = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                deferredDiagnosticArg = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            } else if ((deferredDiagnosticKind == DeferredDiagnosticKind.IN_FILE
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                        || deferredDiagnosticKind == DeferredDiagnosticKind.ADDITIONAL_IN_FILE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                       && !equal(deferredDiagnosticSource, currentSource)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                // additional errors in more than one source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                deferredDiagnosticKind = DeferredDiagnosticKind.ADDITIONAL_IN_FILES;
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                deferredDiagnosticArg = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            if (deferredDiagnosticKind == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                // warnings in a single source
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                deferredDiagnosticSource = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                deferredDiagnosticArg = currentSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            }  else if (deferredDiagnosticKind == DeferredDiagnosticKind.IN_FILE &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                        !equal(deferredDiagnosticSource, currentSource)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                // warnings in multiple source files
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILES;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                deferredDiagnosticArg = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * Report any diagnostic that might have been deferred by previous calls of report().
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    public void reportDeferredDiagnostic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        if (deferredDiagnosticKind != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            if (deferredDiagnosticArg == null)
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   174
                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            else
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   176
                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            if (!verbose)
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   179
                logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * Check two objects, each possibly null, are either both null or are equal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    private static boolean equal(Object o1, Object o2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        return ((o1 == null || o2 == null) ? (o1 == o2) : o1.equals(o2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * The log to which to report warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    private Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * Whether or not to report individual warnings, or simply to report a
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * single aggregate warning at the end of the compilation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    private boolean verbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * The common prefix for all I18N message keys generated by this handler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    private String prefix;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * A set containing the names of the source files for which specific
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * warnings have been generated -- i.e. in verbose mode.  If a source name
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * appears in this list, then deferred diagnostics will be phrased to
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * include "additionally"...
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    private Set<JavaFileObject> sourcesWithReportedWarnings;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * A variable indicating the latest best guess at what the final
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     * deferred diagnostic will be. Initially as specific and helpful
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * as possible, as more warnings are reported, the scope of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * diagnostic will be broadened.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    private DeferredDiagnosticKind deferredDiagnosticKind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     * If deferredDiagnosticKind is IN_FILE or ADDITIONAL_IN_FILE, this variable
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * gives the value of log.currentSource() for the file in question.
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    private JavaFileObject deferredDiagnosticSource;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * An optional argument to be used when constructing the
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * deferred diagnostic message, based on deferredDiagnosticKind.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * This variable should normally be set/updated whenever
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * deferredDiagnosticKind is updated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    private Object deferredDiagnosticArg;
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   235
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
     * 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
   238
     */
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   239
    private final boolean enforceMandatory;
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   240
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   241
    /**
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   242
     * 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
   243
     * 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
   244
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   245
    private final LintCategory lintCategory;
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   246
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   247
    /**
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   248
     * 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
   249
     * 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
   250
     */
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   251
    private void logMandatoryWarning(DiagnosticPosition pos, String msg,
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   252
                                     Object... args) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   253
        // 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
   254
        if (enforceMandatory)
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   255
            log.mandatoryWarning(lintCategory, pos, msg, args);
813
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   256
        else
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   257
            log.warning(lintCategory, pos, msg, args);
813
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
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   260
    /**
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   261
     * 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
   262
     * 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
   263
     */
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   264
    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
   265
        if (enforceMandatory)
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   266
            log.mandatoryNote(file, msg, args);
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   267
        else
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   268
            log.note(file, msg, args);
ab91293d33f4 6507179: javadoc -source 1.3 does not work with jdk6
jjg
parents: 10
diff changeset
   269
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
}