src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java
author vromero
Fri, 02 Feb 2018 07:43:54 -0500
changeset 48721 ef3557eb4306
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196403: remove the remaining use of string keys for errors and warnings in the compiler Reviewed-by: mcimadamore, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     1
/*
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     4
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
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: 3144
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3144
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    10
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    15
 * accompanied this code).
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    16
 *
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3144
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3144
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3144
diff changeset
    23
 * questions.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    24
 */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    25
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.util;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    27
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    28
import java.util.HashMap;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    29
import java.util.Map;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    30
import javax.tools.JavaFileObject;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
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;
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
    33
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
    34
import com.sun.tools.javac.util.JCDiagnostic.Error;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
    35
import com.sun.tools.javac.util.JCDiagnostic.Note;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
    36
import com.sun.tools.javac.util.JCDiagnostic.Warning;
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    37
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    38
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    39
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    40
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    41
/**
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    42
 *  A base class for error logs. Reports errors and warnings, and
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    43
 *  keeps track of error numbers and positions.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    44
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    45
 *  <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
    46
 *  If you write code that depends on this, you do so at your own risk.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    47
 *  This code and its internal interfaces are subject to change or
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    48
 *  deletion without notice.</b>
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    49
 */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    50
public abstract class AbstractLog {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    51
    /** Factory for diagnostics
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    52
     */
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    53
    protected JCDiagnostic.Factory diags;
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    54
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    55
    /** The file that's currently being translated.
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    56
     */
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    57
    protected DiagnosticSource source;
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    58
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    59
    /** A cache of lightweight DiagnosticSource objects.
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    60
     */
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    61
    protected Map<JavaFileObject, DiagnosticSource> sourceMap;
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    62
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    63
    AbstractLog(JCDiagnostic.Factory diags) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    64
        this.diags = diags;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    65
        sourceMap = new HashMap<>();
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    66
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    67
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    68
    /** Re-assign source, returning previous setting.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    69
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    70
    public JavaFileObject useSource(JavaFileObject file) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    71
        JavaFileObject prev = (source == null ? null : source.getFile());
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    72
        source = getSource(file);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    73
        return prev;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    74
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    75
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    76
    protected DiagnosticSource getSource(JavaFileObject file) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    77
        if (file == null)
3144
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1591
diff changeset
    78
            return DiagnosticSource.NO_SOURCE;
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    79
        DiagnosticSource s = sourceMap.get(file);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    80
        if (s == null) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    81
            s = new DiagnosticSource(file, this);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    82
            sourceMap.put(file, s);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    83
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    84
        return s;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    85
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    86
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    87
    /** Return the underlying diagnostic source
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    88
     */
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    89
    public DiagnosticSource currentSource() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    90
        return source;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    91
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    92
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    93
    /** Report an error, unless another error was already reported at same
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    94
     *  source position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    95
     *  @param key    The key for the localized error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    96
     *  @param args   Fields of the error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    97
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    98
    public void error(String key, Object ... args) {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
    99
        error(diags.errorKey(key, args));
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   100
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   101
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   102
    /** Report an error, unless another error was already reported at same
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   103
     *  source position.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   104
     *  @param errorKey    The key for the localized error message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   105
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   106
    public void error(Error errorKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   107
        report(diags.error(null, source, null, errorKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   108
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   109
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   110
    /** Report an error, unless another error was already reported at same
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   111
     *  source position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   112
     *  @param pos    The source position at which to report the error.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   113
     *  @param errorKey    The key for the localized error message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   114
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   115
    public void error(DiagnosticPosition pos, Error errorKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   116
        report(diags.error(null, source, pos, errorKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   117
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   118
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   119
    /** Report an error, unless another error was already reported at same
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   120
     *  source position.
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   121
     *  @param flag   A flag to set on the diagnostic
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   122
     *  @param pos    The source position at which to report the error.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   123
     *  @param errorKey    The key for the localized error message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   124
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   125
    public void error(DiagnosticFlag flag, DiagnosticPosition pos, Error errorKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   126
        report(diags.error(flag, source, pos, errorKey));
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   127
    }
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   128
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   129
    /** Report an error, unless another error was already reported at same
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   130
     *  source position.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   131
     *  @param pos    The source position at which to report the error.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   132
     *  @param key    The key for the localized error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   133
     *  @param args   Fields of the error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   134
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   135
    public void error(int pos, String key, Object ... args) {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   136
        error(pos, diags.errorKey(key, args));
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   137
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   138
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   139
    /** Report an error, unless another error was already reported at same
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   140
     *  source position.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   141
     *  @param pos    The source position at which to report the error.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   142
     *  @param errorKey    The key for the localized error message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   143
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   144
    public void error(int pos, Error errorKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   145
        report(diags.error(null, source, wrap(pos), errorKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   146
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   147
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   148
    /** Report an error, unless another error was already reported at same
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   149
     *  source position.
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   150
     *  @param flag   A flag to set on the diagnostic
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   151
     *  @param pos    The source position at which to report the error.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   152
     *  @param errorKey    The key for the localized error message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   153
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   154
    public void error(DiagnosticFlag flag, int pos, Error errorKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   155
        report(diags.error(flag, source, wrap(pos), errorKey));
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   156
    }
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   157
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   158
    /** Report a warning, unless suppressed by the  -nowarn option or the
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   159
     *  maximum number of warnings has been reached.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   160
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   161
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   162
    public void warning(Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   163
        report(diags.warning(null, source, null, warningKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   164
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   165
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   166
    /** Report a lint warning, unless suppressed by the  -nowarn option or the
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   167
     *  maximum number of warnings has been reached.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   168
     *  @param lc     The lint category for the diagnostic
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   169
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   170
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   171
    public void warning(LintCategory lc, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   172
        report(diags.warning(lc, null, null, warningKey));
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   173
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   174
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   175
    /** Report a warning, unless suppressed by the  -nowarn option or the
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   176
     *  maximum number of warnings has been reached.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   177
     *  @param pos    The source position at which to report the warning.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   178
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   179
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   180
    public void warning(DiagnosticPosition pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   181
        report(diags.warning(null, source, pos, warningKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   182
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   183
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   184
    /** Report a lint warning, unless suppressed by the  -nowarn option or the
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   185
     *  maximum number of warnings has been reached.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   186
     *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   187
     *  @param pos    The source position at which to report the warning.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   188
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   189
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   190
    public void warning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   191
        report(diags.warning(lc, source, pos, warningKey));
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   192
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   193
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   194
    /** Report a warning, unless suppressed by the  -nowarn option or the
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   195
     *  maximum number of warnings has been reached.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   196
     *  @param pos    The source position at which to report the warning.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   197
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   198
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   199
    public void warning(int pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   200
        report(diags.warning(null, source, wrap(pos), warningKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   201
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   202
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   203
    /** Report a warning.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   204
     *  @param pos    The source position at which to report the warning.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   205
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   206
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   207
    public void mandatoryWarning(DiagnosticPosition pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   208
        report(diags.mandatoryWarning(null, source, pos, warningKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   209
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   210
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   211
    /** Report a warning.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   212
     *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   213
     *  @param pos    The source position at which to report the warning.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   214
     *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   215
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   216
    public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   217
        report(diags.mandatoryWarning(lc, source, pos, warningKey));
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   218
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   219
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   220
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   221
     *  @param noteKey    The key for the localized notification message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   222
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   223
    public void note(Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   224
        report(diags.note(source, null, noteKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   225
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   226
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   227
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   228
     *  @param noteKey    The key for the localized notification message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   229
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   230
    public void note(DiagnosticPosition pos, Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   231
        report(diags.note(source, pos, noteKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   232
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   233
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   234
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   235
     *  @param noteKey    The key for the localized notification message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   236
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   237
    public void note(int pos, Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   238
        report(diags.note(source, wrap(pos), noteKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   239
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   240
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   241
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   242
     *  @param noteKey    The key for the localized notification message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   243
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   244
    public void note(JavaFileObject file, Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   245
        report(diags.note(getSource(file), null, noteKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   246
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   247
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   248
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   249
     *  @param noteKey    The key for the localized notification message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   250
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   251
    public void mandatoryNote(final JavaFileObject file, Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 25874
diff changeset
   252
        report(diags.mandatoryNote(getSource(file), noteKey));
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   253
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   254
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   255
    protected abstract void report(JCDiagnostic diagnostic);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   256
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   257
    protected abstract void directError(String key, Object... args);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   258
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   259
    private DiagnosticPosition wrap(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   260
        return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   261
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   262
}