langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 6151 dd513881e71d
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
     2
 * Copyright (c) 2003, 2008, 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: 3995
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: 3995
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: 3995
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3995
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.Locale;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.tools.Diagnostic;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
    34
import com.sun.tools.javac.api.DiagnosticFormatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/** An abstraction of a diagnostic message generated by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    41
 *  <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
    42
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class JCDiagnostic implements Diagnostic<JavaFileObject> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    /** A factory for creating diagnostic objects. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    public static class Factory {
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        /** The context key for the diagnostic factory. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
        protected static final Context.Key<JCDiagnostic.Factory> diagnosticFactoryKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
            new Context.Key<JCDiagnostic.Factory>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        /** Get the Factory instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        public static Factory instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
            Factory instance = context.get(diagnosticFactoryKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
            if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
                instance = new Factory(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
            return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
    61
        DiagnosticFormatter<JCDiagnostic> formatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        final String prefix;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        /** Create a new diagnostic factory. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        protected Factory(Context context) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
    66
            this(JavacMessages.instance(context), "compiler");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
            context.put(diagnosticFactoryKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        /** Create a new diagnostic factory. */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
    71
        public Factory(JavacMessages messages, String prefix) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            this.prefix = prefix;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
    73
            this.formatter = new BasicDiagnosticFormatter(messages);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
         * Create an error diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
         *  @param source The source of the compilation unit, if any, in which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
         *  @param pos    The source position at which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        public JCDiagnostic error(
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
    85
            return create(ERROR, true, source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
         * Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
         *  @param source The source of the compilation unit, if any, in which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
         *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
         *  @see MandatoryWarningHandler
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        public JCDiagnostic mandatoryWarning(
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                 DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
    98
            return create(WARNING, true, source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
         * Create a warning diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
         *  @param source The source of the compilation unit, if any, in which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
         *  @param pos    The source position at which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        public JCDiagnostic warning(
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   110
            return create(WARNING, false, source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
         * Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
         *  @see MandatoryWarningHandler
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   120
            return create(NOTE, true, source, null, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
         * Create a note diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        public JCDiagnostic note(String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   129
            return create(NOTE, false, null, null, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
         * Create a note diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
         *  @param source The source of the compilation unit, if any, in which to report the note.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
         *  @param pos    The source position at which to report the note.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        public JCDiagnostic note(
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   141
            return create(NOTE, false, source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
         * Create a fragment diagnostic, for use as an argument in other diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        public JCDiagnostic fragment(String key, Object... args) {
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   150
            return create(FRAGMENT, false, null, null, key, args);
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   151
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   152
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   153
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   154
         * Create a new diagnostic of the given kind.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   155
         *  @param kind        The diagnostic kind
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   156
         *  @param isMandatory is diagnostic mandatory?
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   157
         *  @param source      The source of the compilation unit, if any, in which to report the note.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   158
         *  @param pos         The source position at which to report the note.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   159
         *  @param key         The key for the localized error message.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   160
         *  @param args        Fields of the error message.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   161
         */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   162
        public JCDiagnostic create(
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   163
                DiagnosticType kind, boolean isMandatory, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   164
            return new JCDiagnostic(formatter, kind, isMandatory, source, pos, qualify(kind, key), args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        protected String qualify(DiagnosticType t, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
            return prefix + "." + t.key + "." + key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * Create a fragment diagnostic, for use as an argument in other diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     *  @param args   Fields of the error message.
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   178
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     */
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   180
    @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public static JCDiagnostic fragment(String key, Object... args) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   182
        return new JCDiagnostic(getFragmentFormatter(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                              FRAGMENT,
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                              false,
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                              null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                              null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                              "compiler." + FRAGMENT.key + "." + key,
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                              args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   190
    //where
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   191
    @Deprecated
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   192
    public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() {
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   193
        if (fragmentFormatter == null) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
   194
            fragmentFormatter = new BasicDiagnosticFormatter(JavacMessages.getDefaultMessages());
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   195
        }
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   196
        return fragmentFormatter;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   197
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * A DiagnosticType defines the type of the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    public enum DiagnosticType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        /** A fragment of an enclosing diagnostic. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        FRAGMENT("misc"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        /** A note: similar to, but less serious than, a warning. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        NOTE("note"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        /** A warning. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        WARNING("warn"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        /** An error. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        ERROR("err");
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        final String key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        /** Create a DiagnosticType.
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
         * @param key A string used to create the resource key for the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        DiagnosticType(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            this.key = key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     * A DiagnosticPosition provides information about the positions in a file
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * that gave rise to a diagnostic. It always defines a "preferred" position
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * that most accurately defines the location of the diagnostic, it may also
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     * provide a related tree node that spans that location.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    public static interface DiagnosticPosition {
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        /** Gets the tree node, if any, to which the diagnostic applies. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        JCTree getTree();
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        /** If there is a tree node, get the start position of the tree node.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
         *  Otherwise, just returns the same as getPreferredPosition(). */
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        int getStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        /** Get the position within the file that most accurately defines the
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
         *  location for the diagnostic. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        int getPreferredPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        /** If there is a tree node, and if endPositions are available, get
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
         *  the end position of the tree node. Otherwise, just returns the
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
         *  same as getPreferredPosition(). */
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        int getEndPosition(Map<JCTree, Integer> endPosTable);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * A DiagnosticPosition that simply identifies a position, but no related
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * tree node, as the location for a diagnostic. Used for scanner and parser
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     * diagnostics. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    public static class SimpleDiagnosticPosition implements DiagnosticPosition {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        public SimpleDiagnosticPosition(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            this.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        public JCTree getTree() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        public int getStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        public int getPreferredPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        public int getEndPosition(Map<JCTree, Integer> endPosTable) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        private final int pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    private final DiagnosticType type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    private final DiagnosticSource source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    private final DiagnosticPosition position;
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    private final int line;
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    private final int column;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    private final String key;
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   277
    protected Object[] args;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    private boolean mandatory;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * Create a diagnostic object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     * @param messages the resource for localized messages
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     * @param dt the type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     * @param name the name of the source file, or null if none.
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     * @param pos the character offset within the source file, if given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     * @param key a resource key to identify the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     * @param args arguments to be included in the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     */
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   289
    protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                       DiagnosticType dt,
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
                       boolean mandatory,
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                       DiagnosticSource source,
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
                       DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                       String key,
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                       Object ... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   299
        this.defaultFormatter = formatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        this.type = dt;
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        this.mandatory = mandatory;
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        this.source = source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        this.position = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        this.key = key;
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   305
            this.args = args;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        if (n == Position.NOPOS || source == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
            line = column = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            line = source.getLineNumber(n);
1109
853d8c191eac 6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents: 1040
diff changeset
   312
            column = source.getColumnNumber(n, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     * Get the type of this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     * @return the type of this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    public DiagnosticType getType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    /**
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   325
     * Get the subdiagnostic list
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   326
     * @return subdiagnostic list
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   327
     */
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   328
    public List<JCDiagnostic> getSubdiagnostics() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   329
        return List.nil();
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   330
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   331
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   332
    public boolean isMultiline() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   333
        return false;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   334
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   335
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   336
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
     * Check whether or not this diagnostic is required to be shown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     * @return true if this diagnostic is required to be shown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
    public boolean isMandatory() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        return mandatory;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     * Get the name of the source file referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     * @return the name of the source referred to with this diagnostic, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    public JavaFileObject getSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        if (source == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            return source.getFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     * Get the source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
     * @return the source referred to with this diagnostic, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
    public DiagnosticSource getDiagnosticSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        return source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
    protected int getIntStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        return (position == null ? Position.NOPOS : position.getStartPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    protected int getIntPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        return (position == null ? Position.NOPOS : position.getPreferredPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    protected int getIntEndPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    public long getStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        return getIntStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    public long getPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        return getIntPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    public long getEndPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        return getIntEndPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
     * Get the line number within the source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
     * @return  the line number within the source referred to by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    public long getLineNumber() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        return line;
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     * Get the column number within the line of source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     * @return  the column number within the line of source referred to by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    public long getColumnNumber() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        return column;
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     * Get the arguments to be included in the text of the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * @return  the arguments to be included in the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public Object[] getArgs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        return args;
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
     * Get the prefix string associated with this type of diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
     * @return the prefix string associated with this type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    public String getPrefix() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        return getPrefix(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
     * Get the prefix string associated with a particular type of diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
     * @return the prefix string associated with a particular type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
    public String getPrefix(DiagnosticType dt) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   424
        return defaultFormatter.formatKind(this, Locale.getDefault());
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   425
    }
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   426
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     * Return the standard presentation of this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
     */
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3143
diff changeset
   430
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    public String toString() {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   432
        return defaultFormatter.format(this,Locale.getDefault());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   435
    private DiagnosticFormatter<JCDiagnostic> defaultFormatter;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   436
    @Deprecated
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   437
    private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    // Methods for javax.tools.Diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    public Diagnostic.Kind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        switch (type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        case NOTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            return Diagnostic.Kind.NOTE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        case WARNING:
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            return mandatory ? Diagnostic.Kind.MANDATORY_WARNING
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                             : Diagnostic.Kind.WARNING;
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
            return Diagnostic.Kind.ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            return Diagnostic.Kind.OTHER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
    public String getCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        return key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
    public String getMessage(Locale locale) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   460
        return defaultFormatter.formatMessage(this, locale);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
    }
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   462
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   463
    public static class MultilineDiagnostic extends JCDiagnostic {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   464
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   465
        private final List<JCDiagnostic> subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   466
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   467
        public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   468
            super(other.defaultFormatter,
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   469
                  other.getType(),
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   470
                  other.isMandatory(),
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   471
                  other.getDiagnosticSource(),
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   472
                  other.position,
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   473
                  other.getCode(),
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   474
                  other.getArgs());
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   475
            this.subdiagnostics = subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   476
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   477
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   478
        @Override
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   479
        public List<JCDiagnostic> getSubdiagnostics() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   480
            return subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   481
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   482
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   483
        @Override
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   484
        public boolean isMultiline() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   485
            return true;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   486
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   487
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
}