src/java.compiler/share/classes/javax/tools/Diagnostic.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25874 langtools/src/java.compiler/share/classes/javax/tools/Diagnostic.java@83c19f00452c
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
     2
 * Copyright (c) 2005, 2014, 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: 10
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: 10
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: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
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 javax.tools;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.Locale;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 * Interface for diagnostics from tools.  A diagnostic usually reports
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * a problem at a specific position in a source file.  However, not
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * all diagnostics are associated with a position or a file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * <p>A position is a zero-based character offset from the beginning of
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * a file.  Negative values (except {@link #NOPOS}) are not valid
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * positions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * <p>Line and column numbers begin at 1.  Negative values (except
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * {@link #NOPOS}) and 0 are not valid line or column numbers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @param <S> the type of source object used by this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @author Jonathan Gibbons
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
public interface Diagnostic<S> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * Kinds of diagnostics, for example, error or warning.
20616
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    52
     *
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    53
     * The kind of a diagnostic can be used to determine how the
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    54
     * diagnostic should be presented to the user. For example,
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    55
     * errors might be colored red or prefixed with the word "Error",
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    56
     * while warnings might be colored yellow or prefixed with the
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    57
     * word "Warning". There is no requirement that the Kind
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    58
     * should imply any inherent semantic meaning to the message
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    59
     * of the diagnostic: for example, a tool might provide an
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    60
     * option to report all warnings as errors.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    enum Kind {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
         * Problem which prevents the tool's normal completion.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        ERROR,
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
         * Problem which does not usually prevent the tool from
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
         * completing normally.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        WARNING,
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
         * Problem similar to a warning, but is mandated by the tool's
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
         * specification.  For example, the Java&trade; Language
20616
ed49d47555ee 6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents: 5520
diff changeset
    75
         * Specification mandates warnings on certain
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
         * unchecked operations and the use of deprecated methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        MANDATORY_WARNING,
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
         * Informative message from the tool.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        NOTE,
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
         * Diagnostic which does not fit within the other kinds.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        OTHER,
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * Used to signal that no position is available.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    public final static long NOPOS = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
    95
     * Returns the kind of this diagnostic, for example, error or
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * @return the kind of this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    Kind getKind();
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   102
     * Returns the source object associated with this diagnostic.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * @return the source object associated with this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * {@code null} if no source object is associated with the
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    S getSource();
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   111
     * Returns a character offset from the beginning of the source object
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * associated with this diagnostic that indicates the location of
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * the problem.  In addition, the following must be true:
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * <p>{@code getStartPostion() <= getPosition()}
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * <p>{@code getPosition() <= getEndPosition()}
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * @return character offset from beginning of source; {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * #NOPOS} if {@link #getSource()} would return {@code null} or if
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * no location is suitable
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    long getPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   125
     * Returns the character offset from the beginning of the file
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * associated with this diagnostic that indicates the start of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * problem.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * @return offset from beginning of file; {@link #NOPOS} if and
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * only if {@link #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    long getStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   135
     * Returns the character offset from the beginning of the file
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * associated with this diagnostic that indicates the end of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * problem.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * @return offset from beginning of file; {@link #NOPOS} if and
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * only if {@link #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    long getEndPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   145
     * Returns the line number of the character offset returned by
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * {@linkplain #getPosition()}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @return a line number or {@link #NOPOS} if and only if {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    long getLineNumber();
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   154
     * Returns the column number of the character offset returned by
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * {@linkplain #getPosition()}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * @return a column number or {@link #NOPOS} if and only if {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    long getColumnNumber();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   163
     * Returns a diagnostic code indicating the type of diagnostic.  The
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * code is implementation-dependent and might be {@code null}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * @return a diagnostic code
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    String getCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20616
diff changeset
   171
     * Returns a localized message for the given locale.  The actual
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * message is implementation-dependent.  If the locale is {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * null} use the default locale.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * @param locale a locale; might be {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * @return a localized message
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    String getMessage(Locale locale);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
}