langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 17582 4079713129dd
child 25010 64c8d860c984
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14259
diff changeset
     2
 * Copyright (c) 2003, 2013, 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;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import javax.tools.Diagnostic;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
    35
import com.sun.tools.javac.api.DiagnosticFormatter;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
    36
import com.sun.tools.javac.code.Lint.LintCategory;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11055
diff changeset
    37
import com.sun.tools.javac.tree.EndPosTable;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
/** An abstraction of a diagnostic message generated by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    44
 *  <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
    45
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
public class JCDiagnostic implements Diagnostic<JavaFileObject> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    /** A factory for creating diagnostic objects. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    public static class Factory {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        /** The context key for the diagnostic factory. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17582
diff changeset
    53
        protected static final Context.Key<JCDiagnostic.Factory> diagnosticFactoryKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        /** Get the Factory instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        public static Factory instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
            Factory instance = context.get(diagnosticFactoryKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
            if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
                instance = new Factory(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
            return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
    63
        DiagnosticFormatter<JCDiagnostic> formatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        final String prefix;
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    65
        final Set<DiagnosticFlag> defaultErrorFlags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        /** Create a new diagnostic factory. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        protected Factory(Context context) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
    69
            this(JavacMessages.instance(context), "compiler");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            context.put(diagnosticFactoryKey, this);
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    71
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    72
            final Options options = Options.instance(context);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    73
            initOptions(options);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    74
            options.addListener(new Runnable() {
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    75
               public void run() {
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    76
                   initOptions(options);
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
        }
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    80
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 7681
diff changeset
    81
        private void initOptions(Options options) {
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    82
            if (options.isSet("onlySyntaxErrorsUnrecoverable"))
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    83
                defaultErrorFlags.add(DiagnosticFlag.RECOVERABLE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        /** Create a new diagnostic factory. */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
    87
        public Factory(JavacMessages messages, String prefix) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            this.prefix = prefix;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
    89
            this.formatter = new BasicDiagnosticFormatter(messages);
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
    90
            defaultErrorFlags = EnumSet.of(DiagnosticFlag.MANDATORY);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
         * Create an error diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
         *  @param source The source of the compilation unit, if any, in which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
         *  @param pos    The source position at which to report the error.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
         *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
         *  @param args   Fields of the error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        public JCDiagnostic error(
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   102
            return create(ERROR, null, defaultErrorFlags, source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
         * Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
         *  @param source The source of the compilation unit, if any, in which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
         *  @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
   109
         *  @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
   110
         *  @param args   Fields of the warning message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
         *  @see MandatoryWarningHandler
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        public JCDiagnostic mandatoryWarning(
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   114
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   115
            return create(WARNING, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args);
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) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   130
            return create(WARNING, lc, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   131
        }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   132
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   133
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   134
         * Create a warning diagnostic.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   135
         *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   136
         *  @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
   137
         *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   138
         *  @see MandatoryWarningHandler
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   139
         */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   140
        public JCDiagnostic warning(
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   141
                 LintCategory lc, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   142
            return create(WARNING, lc, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
         * Create a warning diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
         *  @param source The source of the compilation unit, if any, in which to report the warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
         *  @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
   149
         *  @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
   150
         *  @param args   Fields of the warning message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        public JCDiagnostic warning(
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   154
            return create(WARNING, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
6151
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
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   157
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   158
         * Create a warning diagnostic.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   159
         *  @param lc     The lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   160
         *  @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
   161
         *  @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
   162
         *  @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
   163
         *  @param args   Fields of the warning message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   164
         *  @see MandatoryWarningHandler
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   165
         */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   166
        public JCDiagnostic warning(
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   167
                 LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   168
            return create(WARNING, lc, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
         * Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   173
         *  @param key    The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   174
         *  @param args   Fields of the message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
         *  @see MandatoryWarningHandler
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   178
            return create(NOTE, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, null, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
         * Create a note diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
         *  @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
   184
         *  @param args   Fields of the message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        public JCDiagnostic note(String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   187
            return create(NOTE, null, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
         * Create a note diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
         *  @param source The source of the compilation unit, if any, in which to report the note.
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
         *  @param pos    The source position at which to report the note.
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   194
         *  @param key    The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   195
         *  @param args   Fields of the message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        public JCDiagnostic note(
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
                DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   199
            return create(NOTE, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
         * 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
   204
         *  @param key    The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   205
         *  @param args   Fields of the message.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        public JCDiagnostic fragment(String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   208
            return create(FRAGMENT, null, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args);
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   209
        }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   210
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   211
        /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   212
         * 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
   213
         * no lint category.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   214
         *  @param kind        The diagnostic kind
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   215
         *  @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
   216
         *  @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
   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.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   219
         */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   220
        public JCDiagnostic create(
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   221
                DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   222
            return create(kind, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args);
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   223
        }
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   224
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   225
        /**
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   226
         * Create a new diagnostic of the given kind.
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   227
         *  @param kind        The diagnostic kind
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   228
         *  @param lc          The lint category, if applicable, or null
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   229
         *  @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
   230
         *  @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
   231
         *  @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
   232
         *  @param key         The key for the localized message.
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   233
         *  @param args        Fields of the message.
3143
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   234
         */
0413d5b5b7fd 6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents: 1591
diff changeset
   235
        public JCDiagnostic create(
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   236
                DiagnosticType kind, LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   237
            return new JCDiagnostic(formatter, kind, lc, flags, source, pos, qualify(kind, key), args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        protected String qualify(DiagnosticType t, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            return prefix + "." + t.key + "." + key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     * Create a fragment diagnostic, for use as an argument in other diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     *  @param key    The key for the localized error message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     *  @param args   Fields of the error message.
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   251
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     */
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   253
    @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    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
   255
        return new JCDiagnostic(getFragmentFormatter(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                              FRAGMENT,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   257
                              null,
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   258
                              EnumSet.noneOf(DiagnosticFlag.class),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                              null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                              null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                              "compiler." + FRAGMENT.key + "." + key,
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                              args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   264
    //where
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   265
    @Deprecated
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   266
    public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() {
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   267
        if (fragmentFormatter == null) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1109
diff changeset
   268
            fragmentFormatter = new BasicDiagnosticFormatter(JavacMessages.getDefaultMessages());
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   269
        }
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   270
        return fragmentFormatter;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   271
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * A DiagnosticType defines the type of the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     **/
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    public enum DiagnosticType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        /** A fragment of an enclosing diagnostic. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        FRAGMENT("misc"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        /** A note: similar to, but less serious than, a warning. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        NOTE("note"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        /** A warning. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        WARNING("warn"),
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        /** An error. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        ERROR("err");
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        final String key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        /** Create a DiagnosticType.
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
         * @param key A string used to create the resource key for the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        DiagnosticType(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            this.key = key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 17582
diff changeset
   294
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * A DiagnosticPosition provides information about the positions in a file
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     * that gave rise to a diagnostic. It always defines a "preferred" position
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     * that most accurately defines the location of the diagnostic, it may also
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     * provide a related tree node that spans that location.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    public static interface DiagnosticPosition {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        /** Gets the tree node, if any, to which the diagnostic applies. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        JCTree getTree();
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        /** If there is a tree node, get the start position of the tree node.
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
         *  Otherwise, just returns the same as getPreferredPosition(). */
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        int getStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        /** Get the position within the file that most accurately defines the
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
         *  location for the diagnostic. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        int getPreferredPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        /** If there is a tree node, and if endPositions are available, get
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
         *  the end position of the tree node. Otherwise, just returns the
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
         *  same as getPreferredPosition(). */
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 11052
diff changeset
   314
        int getEndPosition(EndPosTable endPosTable);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     * A DiagnosticPosition that simply identifies a position, but no related
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     * tree node, as the location for a diagnostic. Used for scanner and parser
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     * diagnostics. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    public static class SimpleDiagnosticPosition implements DiagnosticPosition {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        public SimpleDiagnosticPosition(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            this.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        public JCTree getTree() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        public int getStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        public int getPreferredPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 11052
diff changeset
   338
        public int getEndPosition(EndPosTable endPosTable) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        private final int pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   345
    public enum DiagnosticFlag {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   346
        MANDATORY,
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   347
        RESOLVE_ERROR,
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   348
        SYNTAX,
16326
9b94bafef533 8009227: Certain diagnostics should not be deferred
mcimadamore
parents: 16309
diff changeset
   349
        RECOVERABLE,
9b94bafef533 8009227: Certain diagnostics should not be deferred
mcimadamore
parents: 16309
diff changeset
   350
        NON_DEFERRABLE,
17582
4079713129dd 8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents: 16326
diff changeset
   351
        COMPRESSED
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   352
    }
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   353
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    private final DiagnosticType type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    private final DiagnosticSource source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    private final DiagnosticPosition position;
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    private final int line;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    private final int column;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
    private final String key;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   360
    protected final Object[] args;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   361
    private final Set<DiagnosticFlag> flags;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   362
    private final LintCategory lintCategory;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
     * Create a diagnostic object.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   366
     * @param formatter the formatter to use for the diagnostic
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     * @param dt the type of diagnostic
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   368
     * @param lc     the lint category for the diagnostic
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   369
     * @param source the name of the source file, or null if none.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     * @param pos the character offset within the source file, if given.
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     * @param key a resource key to identify the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     * @param args arguments to be included in the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
     */
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   374
    protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                       DiagnosticType dt,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   376
                       LintCategory lc,
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   377
                       Set<DiagnosticFlag> flags,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                       DiagnosticSource source,
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
                       DiagnosticPosition pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                       String key,
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   381
                       Object... args) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   385
        this.defaultFormatter = formatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        this.type = dt;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   387
        this.lintCategory = lc;
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   388
        this.flags = flags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        this.source = source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        this.position = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        this.key = key;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14259
diff changeset
   392
        this.args = args;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        if (n == Position.NOPOS || source == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            line = column = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            line = source.getLineNumber(n);
1109
853d8c191eac 6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents: 1040
diff changeset
   399
            column = source.getColumnNumber(n, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     * Get the type of this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * @return the type of this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public DiagnosticType getType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    /**
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   412
     * Get the subdiagnostic list
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   413
     * @return subdiagnostic list
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   414
     */
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   415
    public List<JCDiagnostic> getSubdiagnostics() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   416
        return List.nil();
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   417
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   418
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   419
    public boolean isMultiline() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   420
        return false;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   421
    }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   422
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   423
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
     * Check whether or not this diagnostic is required to be shown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
     * @return true if this diagnostic is required to be shown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    public boolean isMandatory() {
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   428
        return flags.contains(DiagnosticFlag.MANDATORY);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    /**
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   432
     * 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
   433
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   434
    public boolean hasLintCategory() {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   435
        return (lintCategory != null);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   436
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   437
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   438
    /**
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   439
     * 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
   440
     */
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   441
    public LintCategory getLintCategory() {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   442
        return lintCategory;
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   443
    }
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   444
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   445
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
     * Get the name of the source file referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
     * @return the name of the source referred to with this diagnostic, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    public JavaFileObject getSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        if (source == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            return source.getFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
     * Get the source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
     * @return the source referred to with this diagnostic, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    public DiagnosticSource getDiagnosticSource() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        return source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
    protected int getIntStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        return (position == null ? Position.NOPOS : position.getStartPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
    protected int getIntPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        return (position == null ? Position.NOPOS : position.getPreferredPosition());
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    protected int getIntEndPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
    public long getStartPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        return getIntStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
    public long getPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        return getIntPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
    public long getEndPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        return getIntEndPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
16309
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   488
    public DiagnosticPosition getDiagnosticPosition() {
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   489
        return position;
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   490
    }
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 15385
diff changeset
   491
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
     * Get the line number within the source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
     * @return  the line number within the source referred to by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
    public long getLineNumber() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        return line;
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
     * Get the column number within the line of source referred to by this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
     * @return  the column number within the line of source referred to by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
    public long getColumnNumber() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        return column;
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
     * Get the arguments to be included in the text of the diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
     * @return  the arguments to be included in the text of the diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
    public Object[] getArgs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        return args;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
     * Get the prefix string associated with this type of diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
     * @return the prefix string associated with this type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
    public String getPrefix() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        return getPrefix(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
     * Get the prefix string associated with a particular type of diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
     * @return the prefix string associated with a particular type of diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
    public String getPrefix(DiagnosticType dt) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   529
        return defaultFormatter.formatKind(this, Locale.getDefault());
942
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   530
    }
98e1d4f8aacd 6720185: DiagnosticFormatter refactoring
mcimadamore
parents: 939
diff changeset
   531
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
     * Return the standard presentation of this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
     */
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3143
diff changeset
   535
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
    public String toString() {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   537
        return defaultFormatter.format(this,Locale.getDefault());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   540
    private DiagnosticFormatter<JCDiagnostic> defaultFormatter;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   541
    @Deprecated
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   542
    private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
    // Methods for javax.tools.Diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
    public Diagnostic.Kind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        switch (type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        case NOTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
            return Diagnostic.Kind.NOTE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        case WARNING:
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   551
            return flags.contains(DiagnosticFlag.MANDATORY)
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   552
                    ? Diagnostic.Kind.MANDATORY_WARNING
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   553
                    : Diagnostic.Kind.WARNING;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            return Diagnostic.Kind.ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
            return Diagnostic.Kind.OTHER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    public String getCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        return key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
    public String getMessage(Locale locale) {
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 942
diff changeset
   566
        return defaultFormatter.formatMessage(this, locale);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
    }
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   568
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   569
    public void setFlag(DiagnosticFlag flag) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   570
        flags.add(flag);
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   571
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   572
        if (type == DiagnosticType.ERROR) {
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   573
            switch (flag) {
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   574
                case SYNTAX:
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   575
                    flags.remove(DiagnosticFlag.RECOVERABLE);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   576
                    break;
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   577
                case RESOLVE_ERROR:
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   578
                    flags.add(DiagnosticFlag.RECOVERABLE);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   579
                    break;
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   580
            }
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 6356
diff changeset
   581
        }
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   582
    }
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   583
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   584
    public boolean isFlagSet(DiagnosticFlag flag) {
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   585
        return flags.contains(flag);
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   586
    }
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   587
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   588
    public static class MultilineDiagnostic extends JCDiagnostic {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   589
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   590
        private final List<JCDiagnostic> subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   592
        public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   593
            super(other.defaultFormatter,
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   594
                  other.getType(),
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   595
                  other.getLintCategory(),
6356
af24929939ca 6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents: 6151
diff changeset
   596
                  other.flags,
1591
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   597
                  other.getDiagnosticSource(),
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   598
                  other.position,
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   599
                  other.getCode(),
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   600
                  other.getArgs());
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   601
            this.subdiagnostics = subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   602
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   603
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   604
        @Override
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   605
        public List<JCDiagnostic> getSubdiagnostics() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   606
            return subdiagnostics;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   607
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   608
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   609
        @Override
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   610
        public boolean isMultiline() {
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   611
            return true;
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   612
        }
e5a618442f5f 6768932: Add support for multiline diagnostics
mcimadamore
parents: 1471
diff changeset
   613
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
}