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