langtools/src/share/classes/com/sun/tools/javac/util/AbstractLog.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 14259 fb94a1df0d53
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
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
/*
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 10455
diff changeset
     2
 * Copyright (c) 1999, 2012, 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;
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    36
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    37
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    38
/**
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    39
 *  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
    40
 *  keeps track of error numbers and positions.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    41
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    42
 *  <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
    43
 *  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
    44
 *  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
    45
 *  deletion without notice.</b>
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    46
 */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    47
public abstract class AbstractLog {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    48
    /** Factory for diagnostics
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    49
     */
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    50
    protected JCDiagnostic.Factory diags;
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    51
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    52
    /** The file that's currently being translated.
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    53
     */
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    54
    protected DiagnosticSource source;
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    55
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    56
    /** A cache of lightweight DiagnosticSource objects.
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    57
     */
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    58
    protected Map<JavaFileObject, DiagnosticSource> sourceMap;
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    59
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    60
    AbstractLog(JCDiagnostic.Factory diags) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    61
        this.diags = diags;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14259
diff changeset
    62
        sourceMap = new HashMap<>();
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    63
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    64
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    65
    /** Re-assign source, returning previous setting.
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
    public JavaFileObject useSource(JavaFileObject file) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    68
        JavaFileObject prev = (source == null ? null : source.getFile());
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    69
        source = getSource(file);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    70
        return prev;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    71
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    72
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    73
    protected DiagnosticSource getSource(JavaFileObject file) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    74
        if (file == null)
3144
202fa249dc34 6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents: 1591
diff changeset
    75
            return DiagnosticSource.NO_SOURCE;
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    76
        DiagnosticSource s = sourceMap.get(file);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    77
        if (s == null) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    78
            s = new DiagnosticSource(file, this);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    79
            sourceMap.put(file, s);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    80
        }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    81
        return s;
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    82
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    83
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    84
    /** Return the underlying diagnostic source
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    85
     */
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    86
    public DiagnosticSource currentSource() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 867
diff changeset
    87
        return 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
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    90
    /** 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
    91
     *  source position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    92
     *  @param key    The key for the localized error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    93
     *  @param args   Fields of the error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    94
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    95
    public void error(String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    96
        report(diags.error(source, null, key, args));
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
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
    99
    /** 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
   100
     *  source position.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   101
     *  @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
   102
     *  @param key    The key for the localized error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   103
     *  @param args   Fields of the error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   104
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   105
    public void error(DiagnosticPosition pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   106
        report(diags.error(source, pos, key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   107
    }
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
    /** 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
   110
     *  source position.
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   111
     *  @param flag   A flag to set on the diagnostic
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   112
     *  @param pos    The source position at which to report the error.
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   113
     *  @param key    The key for the localized error message.
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   114
     *  @param args   Fields of the error message.
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   115
     */
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   116
    public void error(DiagnosticFlag flag, DiagnosticPosition pos, String key, Object ... args) {
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   117
        JCDiagnostic d = diags.error(source, pos, key, args);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   118
        d.setFlag(flag);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   119
        report(d);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   120
    }
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   121
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 7681
diff changeset
   122
    /** 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
   123
     *  source position.
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   124
     *  @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
   125
     *  @param key    The key for the localized error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   126
     *  @param args   Fields of the error message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   127
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   128
    public void error(int pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   129
        report(diags.error(source, wrap(pos), key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   130
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   131
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   132
    /** 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
   133
     *  source position.
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   134
     *  @param flag   A flag to set on the diagnostic
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   135
     *  @param pos    The source position at which to report the error.
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   136
     *  @param key    The key for the localized error message.
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   137
     *  @param args   Fields of the error message.
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   138
     */
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   139
    public void error(DiagnosticFlag flag, int pos, String key, Object ... args) {
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   140
        JCDiagnostic d = diags.error(source, wrap(pos), key, args);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   141
        d.setFlag(flag);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   142
        report(d);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   143
    }
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6151
diff changeset
   144
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   145
    /** 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
   146
     *  maximum number of warnings has been reached.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   147
     *  @param key    The key for the localized warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   148
     *  @param args   Fields of the warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   149
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   150
    public void warning(String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   151
        report(diags.warning(source, null, key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   152
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   153
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   154
    /** 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
   155
     *  maximum number of warnings has been reached.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   156
     *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   157
     *  @param key    The key for the localized warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   158
     *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   159
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   160
    public void warning(LintCategory lc, String key, Object ... args) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   161
        report(diags.warning(lc, key, args));
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   162
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   163
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   164
    /** 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
   165
     *  maximum number of warnings has been reached.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   166
     *  @param pos    The source position at which to report the warning.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   167
     *  @param key    The key for the localized warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   168
     *  @param args   Fields of the warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   169
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   170
    public void warning(DiagnosticPosition pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   171
        report(diags.warning(source, pos, key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   172
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   173
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   174
    /** 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
   175
     *  maximum number of warnings has been reached.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   176
     *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   177
     *  @param pos    The source position at which to report the warning.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   178
     *  @param key    The key for the localized warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   179
     *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   180
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   181
    public void warning(LintCategory lc, DiagnosticPosition pos, String key, Object ... args) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   182
        report(diags.warning(lc, source, pos, key, args));
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   183
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   184
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   185
    /** 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
   186
     *  maximum number of warnings has been reached.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   187
     *  @param pos    The source position at which to report the warning.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   188
     *  @param key    The key for the localized warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   189
     *  @param args   Fields of the warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   190
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   191
    public void warning(int pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   192
        report(diags.warning(source, wrap(pos), key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   193
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   194
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   195
    /** Report a warning.
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.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   197
     *  @param key    The key for the localized warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   198
     *  @param args   Fields of the warning message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   199
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   200
    public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   201
        report(diags.mandatoryWarning(source, pos, key, args));
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
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   204
    /** Report a warning.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   205
     *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   206
     *  @param pos    The source position at which to report the warning.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   207
     *  @param key    The key for the localized warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   208
     *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   209
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   210
    public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, String key, Object ... args) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   211
        report(diags.mandatoryWarning(lc, source, pos, key, args));
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   212
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   213
867
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   214
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   215
     *  @param key    The key for the localized notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   216
     *  @param args   Fields of the notint an error or warning message:
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   217
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   218
    public void note(String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   219
        report(diags.note(source, null, key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   220
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   221
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   222
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   223
     *  @param key    The key for the localized notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   224
     *  @param args   Fields of the notification message.
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
    public void note(DiagnosticPosition pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   227
        report(diags.note(source, pos, key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   228
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   229
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   230
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   231
     *  @param key    The key for the localized notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   232
     *  @param args   Fields of the notification message.
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
    public void note(int pos, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   235
        report(diags.note(source, wrap(pos), key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   236
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   237
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   238
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   239
     *  @param key    The key for the localized notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   240
     *  @param args   Fields of the notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   241
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   242
    public void note(JavaFileObject file, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   243
        report(diags.note(getSource(file), null, key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   244
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   245
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   246
    /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   247
     *  @param key    The key for the localized notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   248
     *  @param args   Fields of the notification message.
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   249
     */
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   250
    public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   251
        report(diags.mandatoryNote(getSource(file), key, args));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   252
    }
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
    protected abstract void report(JCDiagnostic diagnostic);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   255
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   256
    protected abstract void directError(String key, Object... args);
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   257
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   258
    private DiagnosticPosition wrap(int pos) {
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   259
        return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos));
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   260
    }
1dff24b5f407 6724071: refactor Log into a front end and back end
jjg
parents:
diff changeset
   261
}