langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
author jlahoda
Tue, 13 Jan 2015 19:13:42 +0100
changeset 28455 41245007c074
parent 28334 1633de6070ae
child 40504 0a01f6710c84
permissions -rw-r--r--
8066843: Messager.printMessage cannot print multiple errors for same source position Summary: Using a DiagnosticFlag to mark diagnostics that should be always printed even if multiple of them have the same source position. Reviewed-by: darcy, jjg, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
28455
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 28334
diff changeset
     2
 * Copyright (c) 2003, 2015, 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
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
    28
import java.util.EnumSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Locale;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
    30
import java.util.Set;
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
    31
import java.util.stream.Stream;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.tools.Diagnostic;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
    36
import com.sun.tools.javac.api.DiagnosticFormatter;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
    37
import com.sun.tools.javac.code.Lint.LintCategory;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11055
diff changeset
    38
import com.sun.tools.javac.tree.EndPosTable;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.tree.JCTree;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    40
import com.sun.tools.javac.util.DefinedBy.Api;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
/** An abstraction of a diagnostic message generated by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    46
 *  <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
    47
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
public class JCDiagnostic implements Diagnostic<JavaFileObject> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /** A factory for creating diagnostic objects. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    public static class Factory {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        /** The context key for the diagnostic factory. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17582
diff changeset
    55
        protected static final Context.Key<JCDiagnostic.Factory> diagnosticFactoryKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        /** Get the Factory instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        public static Factory instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            Factory instance = context.get(diagnosticFactoryKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
            if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
                instance = new Factory(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
    65
        DiagnosticFormatter<JCDiagnostic> formatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        final String prefix;
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    67
        final Set<DiagnosticFlag> defaultErrorFlags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        /** Create a new diagnostic factory. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        protected Factory(Context context) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
    71
            this(JavacMessages.instance(context), "compiler");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            context.put(diagnosticFactoryKey, this);
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    73
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    74
            final Options options = Options.instance(context);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    75
            initOptions(options);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    76
            options.addListener(new Runnable() {
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    77
               public void run() {
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    78
                   initOptions(options);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    79
               }
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    80
            });
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    81
        }
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    82
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    83
        private void initOptions(Options options) {
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    84
            if (options.isSet("onlySyntaxErrorsUnrecoverable"))
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    85
                defaultErrorFlags.add(DiagnosticFlag.RECOVERABLE);
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
        /** Create a new diagnostic factory. */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
    89
        public Factory(JavacMessages messages, String prefix) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            this.prefix = prefix;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
    91
            this.formatter = new BasicDiagnosticFormatter(messages);
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    92
            defaultErrorFlags = EnumSet.of(DiagnosticFlag.MANDATORY);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        /**
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
    96
         * Create an error diagnostic
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
         *  @param source The source of the compilation unit, if any, in which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
         *  @param pos    The source position at which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        public JCDiagnostic error(
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   103
                DiagnosticFlag flag, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   104
            return error(flag, source, pos, errorKey(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        /**
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   108
         * Create an error diagnostic
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   109
         *  @param source The source of the compilation unit, if any, in which to report the error.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   110
         *  @param pos    The source position at which to report the error.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   111
         *  @param errorKey    The key for the localized error message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
         */
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   113
        public JCDiagnostic error(
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   114
                DiagnosticFlag flag, DiagnosticSource source, DiagnosticPosition pos, Error errorKey) {
28455
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 28334
diff changeset
   115
            JCDiagnostic diag = create(null, EnumSet.copyOf(defaultErrorFlags), source, pos, errorKey);
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   116
            if (flag != null) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   117
                diag.setFlag(flag);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   118
            }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   119
            return diag;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   120
        }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   121
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   122
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   123
         * Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   124
         *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   125
         *  @param source The source of the compilation unit, if any, in which to report the warning.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   126
         *  @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
   127
         *  @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
   128
         *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   129
         *  @see MandatoryWarningHandler
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   130
         */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   131
        public JCDiagnostic mandatoryWarning(
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   132
                LintCategory lc,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   133
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   134
            return mandatoryWarning(lc, source, pos, warningKey(key, args));
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   135
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   136
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   137
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   138
         * Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   139
         *  @param lc     The lint category for the diagnostic
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   140
         *  @param source The source of the compilation unit, if any, in which to report the warning.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   141
         *  @param pos    The source position at which to report the warning.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   142
         *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   143
         *  @see MandatoryWarningHandler
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   144
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   145
        public JCDiagnostic mandatoryWarning(
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   146
                LintCategory lc,
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   147
                DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   148
            return create(lc, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, warningKey);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   149
        }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   150
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   151
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   152
         * Create a warning diagnostic.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   153
         *  @param lc     The lint category for the diagnostic
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   154
         *  @param source The source of the compilation unit, if any, in which to report the warning.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   155
         *  @param pos    The source position at which to report the warning.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   156
         *  @param key    The key for the localized error message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   157
         *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   158
         *  @see MandatoryWarningHandler
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 JCDiagnostic warning(
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   161
                LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   162
            return warning(lc, source, pos, warningKey(key, args));
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   163
        }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   164
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   165
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   166
         * Create a warning diagnostic.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   167
         *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   168
         *  @param source The source of the compilation unit, if any, in which to report the warning.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   169
         *  @param pos    The source position at which to report the warning.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   170
         *  @param warningKey    The key for the localized warning message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   171
         *  @see MandatoryWarningHandler
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   172
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   173
        public JCDiagnostic warning(
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   174
                LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   175
            return create(lc, EnumSet.noneOf(DiagnosticFlag.class), source, pos, warningKey);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   176
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   177
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   178
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   179
         * Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   180
         *  @param source The source of the compilation unit, if any, in which to report the warning.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   181
         *  @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
   182
         *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   183
         *  @see MandatoryWarningHandler
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   184
         */
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   185
        public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   186
            return mandatoryNote(source, noteKey(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
         * Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   191
         *  @param noteKey    The key for the localized note message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
         *  @see MandatoryWarningHandler
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
         */
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   194
        public JCDiagnostic mandatoryNote(DiagnosticSource source, Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   195
            return create(null, EnumSet.of(DiagnosticFlag.MANDATORY), source, null, noteKey);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
         * Create a note diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
         *  @param key    The key for the localized error message.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   201
         *  @param args   Fields of the message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
         */
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   203
        public JCDiagnostic note(
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   204
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   205
            return note(source, pos, noteKey(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
         * Create a note diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
         *  @param source The source of the compilation unit, if any, in which to report the note.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
         *  @param pos    The source position at which to report the note.
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   212
         *  @param noteKey    The key for the localized note message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        public JCDiagnostic note(
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   215
                DiagnosticSource source, DiagnosticPosition pos, Note noteKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   216
            return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, noteKey);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
         * Create a fragment diagnostic, for use as an argument in other diagnostics
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   221
         *  @param key    The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   222
         *  @param args   Fields of the message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        public JCDiagnostic fragment(String key, Object... args) {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   225
            return fragment(fragmentKey(key, args));
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   226
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   227
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   228
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   229
         * Create a fragment diagnostic, for use as an argument in other diagnostics
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   230
         *  @param fragmentKey    The key for the localized subdiagnostic message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   231
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   232
        public JCDiagnostic fragment(Fragment fragmentKey) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   233
            return create(null, EnumSet.noneOf(DiagnosticFlag.class), null, null, fragmentKey);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   234
        }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   235
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   236
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   237
         * Create a new diagnostic of the given kind, which is not mandatory and which has
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   238
         * no lint category.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   239
         *  @param kind        The diagnostic kind
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   240
         *  @param source      The source of the compilation unit, if any, in which to report the message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   241
         *  @param pos         The source position at which to report the message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   242
         *  @param key         The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   243
         *  @param args        Fields of the message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   244
         */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   245
        public JCDiagnostic create(
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   246
                DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   247
            return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, DiagnosticInfo.of(kind, prefix, key, args));
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   248
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   249
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   250
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   251
         * Create a new diagnostic of the given kind, which is not mandatory and which has
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   252
         * no lint category.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   253
         *  @param source      The source of the compilation unit, if any, in which to report the message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   254
         *  @param pos         The source position at which to report the message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   255
         *  @param diagnosticInfo         The key for the localized message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   256
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   257
        public JCDiagnostic create(
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   258
                DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   259
            return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, diagnosticInfo);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   260
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   261
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   262
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   263
         * Create a new diagnostic of the given kind.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   264
         *  @param kind        The diagnostic kind
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   265
         *  @param lc          The lint category, if applicable, or null
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   266
         *  @param flags       The set of flags for the diagnostic
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   267
         *  @param source      The source of the compilation unit, if any, in which to report the message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   268
         *  @param pos         The source position at which to report the message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   269
         *  @param key         The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   270
         *  @param args        Fields of the message.
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   271
         */
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   272
        public JCDiagnostic create(DiagnosticType kind,
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   273
                LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   274
            return create(lc, flags, source, pos, DiagnosticInfo.of(kind, prefix, key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   277
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   278
         * Create a new diagnostic with given key.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   279
         *  @param lc          The lint category, if applicable, or null
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   280
         *  @param flags       The set of flags for the diagnostic
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   281
         *  @param source      The source of the compilation unit, if any, in which to report the message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   282
         *  @param pos         The source position at which to report the message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   283
         *  @param diagnosticInfo    The key for the localized message.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   284
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   285
        public JCDiagnostic create(
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   286
                LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   287
            return new JCDiagnostic(formatter, normalize(diagnosticInfo), lc, flags, source, pos);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   288
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   289
        //where
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   290
            DiagnosticInfo normalize(DiagnosticInfo diagnosticInfo) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   291
                //replace all nested FragmentKey with full-blown JCDiagnostic objects
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   292
                return DiagnosticInfo.of(diagnosticInfo.type, diagnosticInfo.prefix, diagnosticInfo.code,
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   293
                        Stream.of(diagnosticInfo.args).map(o -> {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   294
                            return (o instanceof Fragment) ?
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   295
                                    fragment((Fragment)o) : o;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   296
                        }).toArray());
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   297
            }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   298
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   299
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   300
         * Create a new error key.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   301
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   302
        Error errorKey(String code, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   303
            return (Error)DiagnosticInfo.of(ERROR, prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   304
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   305
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   306
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   307
         * Create a new warning key.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   308
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   309
        Warning warningKey(String code, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   310
            return (Warning)DiagnosticInfo.of(WARNING, prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   311
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   312
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   313
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   314
         * Create a new note key.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   315
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   316
        Note noteKey(String code, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   317
            return (Note)DiagnosticInfo.of(NOTE, prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   318
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   319
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   320
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   321
         * Create a new fragment key.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   322
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   323
        Fragment fragmentKey(String code, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   324
            return (Fragment)DiagnosticInfo.of(FRAGMENT, prefix, code, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
     * Create a fragment diagnostic, for use as an argument in other diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     *  @param args   Fields of the error message.
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   334
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     */
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   336
    @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    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
   338
        return new JCDiagnostic(getFragmentFormatter(),
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   339
                              DiagnosticInfo.of(FRAGMENT,
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   340
                                      "compiler",
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   341
                                      key,
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   342
                                      args),
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   343
                              null,
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   344
                              EnumSet.noneOf(DiagnosticFlag.class),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                              null,
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   346
                              null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    }
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   348
    //where
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   349
    @Deprecated
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   350
    public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() {
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   351
        if (fragmentFormatter == null) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
   352
            fragmentFormatter = new BasicDiagnosticFormatter(JavacMessages.getDefaultMessages());
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   353
        }
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   354
        return fragmentFormatter;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   355
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
     * A DiagnosticType defines the type of the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    public enum DiagnosticType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        /** A fragment of an enclosing diagnostic. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        FRAGMENT("misc"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        /** A note: similar to, but less serious than, a warning. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        NOTE("note"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        /** A warning. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        WARNING("warn"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        /** An error. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        ERROR("err");
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        final String key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        /** Create a DiagnosticType.
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
         * @param key A string used to create the resource key for the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        DiagnosticType(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            this.key = key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17582
diff changeset
   378
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     * A DiagnosticPosition provides information about the positions in a file
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
     * that gave rise to a diagnostic. It always defines a "preferred" position
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     * that most accurately defines the location of the diagnostic, it may also
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     * provide a related tree node that spans that location.
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    public static interface DiagnosticPosition {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        /** Gets the tree node, if any, to which the diagnostic applies. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        JCTree getTree();
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        /** If there is a tree node, get the start position of the tree node.
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
         *  Otherwise, just returns the same as getPreferredPosition(). */
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        int getStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        /** Get the position within the file that most accurately defines the
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
         *  location for the diagnostic. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        int getPreferredPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        /** If there is a tree node, and if endPositions are available, get
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
         *  the end position of the tree node. Otherwise, just returns the
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
         *  same as getPreferredPosition(). */
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 11052
diff changeset
   398
        int getEndPosition(EndPosTable endPosTable);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
     * A DiagnosticPosition that simply identifies a position, but no related
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     * tree node, as the location for a diagnostic. Used for scanner and parser
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     * diagnostics. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    public static class SimpleDiagnosticPosition implements DiagnosticPosition {
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        public SimpleDiagnosticPosition(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            this.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        public JCTree getTree() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        public int getStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        public int getPreferredPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 11052
diff changeset
   422
        public int getEndPosition(EndPosTable endPosTable) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        private final int pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   429
    public enum DiagnosticFlag {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   430
        MANDATORY,
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   431
        RESOLVE_ERROR,
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   432
        SYNTAX,
16326
9b94bafef533 8009227: Certain diagnostics should not be deferred
mcimadamore
parents: 16309
diff changeset
   433
        RECOVERABLE,
9b94bafef533 8009227: Certain diagnostics should not be deferred
mcimadamore
parents: 16309
diff changeset
   434
        NON_DEFERRABLE,
28455
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 28334
diff changeset
   435
        COMPRESSED,
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 28334
diff changeset
   436
        /** Print multiple errors for same source locations.
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 28334
diff changeset
   437
         */
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 28334
diff changeset
   438
        MULTIPLE;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   439
    }
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   440
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    private final DiagnosticSource source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    private final DiagnosticPosition position;
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   443
    private final DiagnosticInfo diagnosticInfo;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   444
    private final Set<DiagnosticFlag> flags;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   445
    private final LintCategory lintCategory;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
25010
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   447
    /** source line position (set lazily) */
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   448
    private SourcePosition sourcePosition;
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   449
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   450
    /**
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   451
     * This class is used to defer the line/column position fetch logic after diagnostic construction.
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   452
     */
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   453
    class SourcePosition {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   454
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   455
        private final int line;
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   456
        private final int column;
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   457
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   458
        SourcePosition() {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   459
            int n = (position == null ? Position.NOPOS : position.getPreferredPosition());
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   460
            if (n == Position.NOPOS || source == null)
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   461
                line = column = -1;
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   462
            else {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   463
                line = source.getLineNumber(n);
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   464
                column = source.getColumnNumber(n, true);
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   465
            }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   466
        }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   467
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   468
        public int getLineNumber() {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   469
            return line;
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   470
        }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   471
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   472
        public int getColumnNumber() {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   473
            return column;
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   474
        }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   475
    }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   476
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
    /**
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   478
     * A diagnostic key object encapsulates basic properties of a diagnostic, such as the resource key,
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   479
     * the arguments and the kind associated with the diagnostic object. Diagnostic keys can be either
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   480
     * created programmatically (by using the supplied factory method) or obtained through build-time
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   481
     * generated factory methods.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   482
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   483
    public static abstract class DiagnosticInfo {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   484
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   485
        /** The diagnostic kind (i.e. error). */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   486
        DiagnosticType type;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   487
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   488
        /** The diagnostic prefix (i.e. 'javac'); used to compute full resource key. */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   489
        String prefix;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   490
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   491
        /** The diagnostic code (i.e. 'cannot.resolve.sym'); together with {@code prefix} it forms
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   492
         * the full resource key. */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   493
        String code;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   494
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   495
        /** The diagnostic arguments. */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   496
        Object[] args;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   497
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   498
        private DiagnosticInfo(DiagnosticType type, String prefix, String code, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   499
            this.type = type;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   500
            this.prefix = prefix;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   501
            this.code = code;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   502
            this.args = args;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   503
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   504
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   505
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   506
         * Compute the resource key.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   507
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   508
        public String key() {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   509
            return prefix + "." + type.key + "." + code;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   510
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   511
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   512
        /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   513
         * Static factory method; build a custom diagnostic key using given kind, prefix, code and args.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   514
         */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   515
        public static DiagnosticInfo of(DiagnosticType type, String prefix, String code, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   516
            switch (type) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   517
                case ERROR:
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   518
                    return new Error(prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   519
                case WARNING:
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   520
                    return new Warning(prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   521
                case NOTE:
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   522
                    return new Note(prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   523
                case FRAGMENT:
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   524
                    return new Fragment(prefix, code, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   525
                default:
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   526
                    Assert.error("Wrong diagnostic type: " + type);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   527
                    return null;
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   528
            }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   529
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   530
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   531
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   532
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   533
    /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   534
     * Class representing error diagnostic keys.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   535
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   536
    public static final class Error extends DiagnosticInfo {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   537
        public Error(String prefix, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   538
            super(DiagnosticType.ERROR, prefix, key, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   539
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   540
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   541
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   542
    /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   543
     * Class representing warning diagnostic keys.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   544
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   545
    public static final class Warning extends DiagnosticInfo {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   546
        public Warning(String prefix, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   547
            super(DiagnosticType.WARNING, prefix, key, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   548
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   549
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   550
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   551
    /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   552
     * Class representing note diagnostic keys.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   553
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   554
    public static final class Note extends DiagnosticInfo {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   555
        public Note(String prefix, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   556
            super(DiagnosticType.NOTE, prefix, key, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   557
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   558
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   559
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   560
    /**
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   561
     * Class representing fragment diagnostic keys.
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   562
     */
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   563
    public static final class Fragment extends DiagnosticInfo {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   564
        public Fragment(String prefix, String key, Object... args) {
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   565
            super(DiagnosticType.FRAGMENT, prefix, key, args);
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   566
        }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   567
    }
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   568
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   569
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
     * Create a diagnostic object.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   571
     * @param formatter the formatter to use for the diagnostic
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   572
     * @param diagnosticInfo the diagnostic key
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   573
     * @param lc     the lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   574
     * @param source the name of the source file, or null if none.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     * @param pos the character offset within the source file, if given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     */
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   577
    protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter,
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   578
                       DiagnosticInfo diagnosticInfo,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   579
                       LintCategory lc,
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   580
                       Set<DiagnosticFlag> flags,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
                       DiagnosticSource source,
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   582
                       DiagnosticPosition pos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   586
        this.defaultFormatter = formatter;
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   587
        this.diagnosticInfo = diagnosticInfo;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   588
        this.lintCategory = lc;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   589
        this.flags = flags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        this.source = source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        this.position = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
     * Get the type of this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
     * @return the type of this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
    public DiagnosticType getType() {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   599
        return diagnosticInfo.type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
    /**
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   603
     * Get the subdiagnostic list
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   604
     * @return subdiagnostic list
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   605
     */
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   606
    public List<JCDiagnostic> getSubdiagnostics() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   607
        return List.nil();
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   608
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   609
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   610
    public boolean isMultiline() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   611
        return false;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   612
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   613
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   614
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
     * Check whether or not this diagnostic is required to be shown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
     * @return true if this diagnostic is required to be shown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
    public boolean isMandatory() {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   619
        return flags.contains(DiagnosticFlag.MANDATORY);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
    /**
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   623
     * Check whether this diagnostic has an associated lint category.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   624
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   625
    public boolean hasLintCategory() {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   626
        return (lintCategory != null);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   627
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   628
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   629
    /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   630
     * Get the associated lint category, or null if none.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   631
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   632
    public LintCategory getLintCategory() {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   633
        return lintCategory;
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   634
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   635
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   636
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
     * Get the name of the source file referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
     * @return the name of the source referred to with this diagnostic, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   640
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
    public JavaFileObject getSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        if (source == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            return source.getFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
     * Get the source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
     * @return the source referred to with this diagnostic, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
    public DiagnosticSource getDiagnosticSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
        return source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
    protected int getIntStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
        return (position == null ? Position.NOPOS : position.getStartPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
    protected int getIntPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        return (position == null ? Position.NOPOS : position.getPreferredPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    protected int getIntEndPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
        return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   668
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
    public long getStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        return getIntStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   673
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
    public long getPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        return getIntPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   678
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
    public long getEndPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        return getIntEndPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
16309
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   683
    public DiagnosticPosition getDiagnosticPosition() {
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   684
        return position;
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   685
    }
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   686
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
     * Get the line number within the source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
     * @return  the line number within the source referred to by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   691
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
    public long getLineNumber() {
25010
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   693
        if (sourcePosition == null) {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   694
            sourcePosition = new SourcePosition();
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   695
        }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   696
        return sourcePosition.getLineNumber();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
     * Get the column number within the line of source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
     * @return  the column number within the line of source referred to by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   703
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
    public long getColumnNumber() {
25010
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   705
        if (sourcePosition == null) {
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   706
            sourcePosition = new SourcePosition();
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   707
        }
64c8d860c984 8043253: Slow javac compile times in JDK 8
mcimadamore
parents: 22163
diff changeset
   708
        return sourcePosition.getColumnNumber();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
     * Get the arguments to be included in the text of the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
     * @return  the arguments to be included in the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
    public Object[] getArgs() {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   716
        return diagnosticInfo.args;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
     * Get the prefix string associated with this type of diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
     * @return the prefix string associated with this type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
    public String getPrefix() {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   724
        return getPrefix(diagnosticInfo.type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
     * Get the prefix string associated with a particular type of diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     * @return the prefix string associated with a particular type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
    public String getPrefix(DiagnosticType dt) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   732
        return defaultFormatter.formatKind(this, Locale.getDefault());
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   733
    }
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   734
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
     * Return the standard presentation of this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
     */
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3143
diff changeset
   738
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
    public String toString() {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   740
        return defaultFormatter.format(this, Locale.getDefault());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   743
    private DiagnosticFormatter<JCDiagnostic> defaultFormatter;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   744
    @Deprecated
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   745
    private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
    // Methods for javax.tools.Diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   749
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
    public Diagnostic.Kind getKind() {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   751
        switch (diagnosticInfo.type) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        case NOTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
            return Diagnostic.Kind.NOTE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
        case WARNING:
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   755
            return flags.contains(DiagnosticFlag.MANDATORY)
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   756
                    ? Diagnostic.Kind.MANDATORY_WARNING
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   757
                    : Diagnostic.Kind.WARNING;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            return Diagnostic.Kind.ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
            return Diagnostic.Kind.OTHER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   765
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
    public String getCode() {
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   767
        return diagnosticInfo.key();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   770
    @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
    public String getMessage(Locale locale) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   772
        return defaultFormatter.formatMessage(this, locale);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
    }
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   774
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   775
    public void setFlag(DiagnosticFlag flag) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   776
        flags.add(flag);
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   777
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   778
        if (diagnosticInfo.type == DiagnosticType.ERROR) {
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   779
            switch (flag) {
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   780
                case SYNTAX:
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   781
                    flags.remove(DiagnosticFlag.RECOVERABLE);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   782
                    break;
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   783
                case RESOLVE_ERROR:
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   784
                    flags.add(DiagnosticFlag.RECOVERABLE);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   785
                    break;
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   786
            }
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   787
        }
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   788
    }
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   789
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   790
    public boolean isFlagSet(DiagnosticFlag flag) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   791
        return flags.contains(flag);
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   792
    }
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   793
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   794
    public static class MultilineDiagnostic extends JCDiagnostic {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   795
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   796
        private final List<JCDiagnostic> subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   797
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   798
        public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   799
            super(other.defaultFormatter,
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   800
                  other.diagnosticInfo,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   801
                  other.getLintCategory(),
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   802
                  other.flags,
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   803
                  other.getDiagnosticSource(),
28334
1633de6070ae 8058542: Devise scheme for better diagnostic creation
mcimadamore
parents: 26266
diff changeset
   804
                  other.position);
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   805
            this.subdiagnostics = subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   806
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   807
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   808
        @Override
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   809
        public List<JCDiagnostic> getSubdiagnostics() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   810
            return subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   811
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   812
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   813
        @Override
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   814
        public boolean isMultiline() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   815
            return true;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   816
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   817
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
}