langtools/src/share/classes/javax/tools/Diagnostic.java
author poonam
Tue, 26 Feb 2013 08:58:20 -0800
changeset 15808 c75f11af1033
parent 5520 86e4b9a9da40
child 20616 ed49d47555ee
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     2
 * Copyright (c) 2005, 2006, 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.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    enum Kind {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
         * Problem which prevents the tool's normal completion.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        ERROR,
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
         * Problem which does not usually prevent the tool from
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
         * completing normally.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        WARNING,
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
         * Problem similar to a warning, but is mandated by the tool's
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
         * specification.  For example, the Java&trade; Language
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
         * Specification, 3rd Ed. mandates warnings on certain
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
         * unchecked operations and the use of deprecated methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        MANDATORY_WARNING,
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
         * Informative message from the tool.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        NOTE,
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
         * Diagnostic which does not fit within the other kinds.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        OTHER,
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * Used to signal that no position is available.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    public final static long NOPOS = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * Gets the kind of this diagnostic, for example, error or
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * @return the kind of this diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    Kind getKind();
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * Gets the source object associated with this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * @return the source object associated with this diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * {@code null} if no source object is associated with the
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * diagnostic.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    S getSource();
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * Gets a character offset from the beginning of the source object
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * associated with this diagnostic that indicates the location of
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * the problem.  In addition, the following must be true:
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * <p>{@code getStartPostion() <= getPosition()}
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * <p>{@code getPosition() <= getEndPosition()}
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @return character offset from beginning of source; {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * #NOPOS} if {@link #getSource()} would return {@code null} or if
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * no location is suitable
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    long getPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * Gets the character offset from the beginning of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * associated with this diagnostic that indicates the start of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * problem.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * @return offset from beginning of file; {@link #NOPOS} if and
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * only if {@link #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    long getStartPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * Gets the character offset from the beginning of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * associated with this diagnostic that indicates the end of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * problem.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * @return offset from beginning of file; {@link #NOPOS} if and
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * only if {@link #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    long getEndPosition();
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * Gets the line number of the character offset returned by
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * {@linkplain #getPosition()}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * @return a line number or {@link #NOPOS} if and only if {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * #getPosition()} returns {@link #NOPOS}
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    long getLineNumber();
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * Gets the column number of the character offset returned by
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 column 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 getColumnNumber();
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * Gets a diagnostic code indicating the type of diagnostic.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * code is implementation-dependent and might be {@code null}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * @return a diagnostic code
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    String getCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * Gets a localized message for the given locale.  The actual
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * message is implementation-dependent.  If the locale is {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * null} use the default locale.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * @param locale a locale; might be {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * @return a localized message
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    String getMessage(Locale locale);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
}