src/share/classes/javax/tools/Diagnostic.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.tools;
aoqi@0 27
aoqi@0 28 import java.util.Locale;
aoqi@0 29
aoqi@0 30 /**
aoqi@0 31 * Interface for diagnostics from tools. A diagnostic usually reports
aoqi@0 32 * a problem at a specific position in a source file. However, not
aoqi@0 33 * all diagnostics are associated with a position or a file.
aoqi@0 34 *
aoqi@0 35 * <p>A position is a zero-based character offset from the beginning of
aoqi@0 36 * a file. Negative values (except {@link #NOPOS}) are not valid
aoqi@0 37 * positions.
aoqi@0 38 *
aoqi@0 39 * <p>Line and column numbers begin at 1. Negative values (except
aoqi@0 40 * {@link #NOPOS}) and 0 are not valid line or column numbers.
aoqi@0 41 *
aoqi@0 42 * @param <S> the type of source object used by this diagnostic
aoqi@0 43 *
aoqi@0 44 * @author Peter von der Ah&eacute;
aoqi@0 45 * @author Jonathan Gibbons
aoqi@0 46 * @since 1.6
aoqi@0 47 */
aoqi@0 48 public interface Diagnostic<S> {
aoqi@0 49
aoqi@0 50 /**
aoqi@0 51 * Kinds of diagnostics, for example, error or warning.
aoqi@0 52 *
aoqi@0 53 * The kind of a diagnostic can be used to determine how the
aoqi@0 54 * diagnostic should be presented to the user. For example,
aoqi@0 55 * errors might be colored red or prefixed with the word "Error",
aoqi@0 56 * while warnings might be colored yellow or prefixed with the
aoqi@0 57 * word "Warning". There is no requirement that the Kind
aoqi@0 58 * should imply any inherent semantic meaning to the message
aoqi@0 59 * of the diagnostic: for example, a tool might provide an
aoqi@0 60 * option to report all warnings as errors.
aoqi@0 61 */
aoqi@0 62 enum Kind {
aoqi@0 63 /**
aoqi@0 64 * Problem which prevents the tool's normal completion.
aoqi@0 65 */
aoqi@0 66 ERROR,
aoqi@0 67 /**
aoqi@0 68 * Problem which does not usually prevent the tool from
aoqi@0 69 * completing normally.
aoqi@0 70 */
aoqi@0 71 WARNING,
aoqi@0 72 /**
aoqi@0 73 * Problem similar to a warning, but is mandated by the tool's
aoqi@0 74 * specification. For example, the Java&trade; Language
aoqi@0 75 * Specification mandates warnings on certain
aoqi@0 76 * unchecked operations and the use of deprecated methods.
aoqi@0 77 */
aoqi@0 78 MANDATORY_WARNING,
aoqi@0 79 /**
aoqi@0 80 * Informative message from the tool.
aoqi@0 81 */
aoqi@0 82 NOTE,
aoqi@0 83 /**
aoqi@0 84 * Diagnostic which does not fit within the other kinds.
aoqi@0 85 */
aoqi@0 86 OTHER,
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 /**
aoqi@0 90 * Used to signal that no position is available.
aoqi@0 91 */
aoqi@0 92 public final static long NOPOS = -1;
aoqi@0 93
aoqi@0 94 /**
aoqi@0 95 * Gets the kind of this diagnostic, for example, error or
aoqi@0 96 * warning.
aoqi@0 97 * @return the kind of this diagnostic
aoqi@0 98 */
aoqi@0 99 Kind getKind();
aoqi@0 100
aoqi@0 101 /**
aoqi@0 102 * Gets the source object associated with this diagnostic.
aoqi@0 103 *
aoqi@0 104 * @return the source object associated with this diagnostic.
aoqi@0 105 * {@code null} if no source object is associated with the
aoqi@0 106 * diagnostic.
aoqi@0 107 */
aoqi@0 108 S getSource();
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Gets a character offset from the beginning of the source object
aoqi@0 112 * associated with this diagnostic that indicates the location of
aoqi@0 113 * the problem. In addition, the following must be true:
aoqi@0 114 *
aoqi@0 115 * <p>{@code getStartPostion() <= getPosition()}
aoqi@0 116 * <p>{@code getPosition() <= getEndPosition()}
aoqi@0 117 *
aoqi@0 118 * @return character offset from beginning of source; {@link
aoqi@0 119 * #NOPOS} if {@link #getSource()} would return {@code null} or if
aoqi@0 120 * no location is suitable
aoqi@0 121 */
aoqi@0 122 long getPosition();
aoqi@0 123
aoqi@0 124 /**
aoqi@0 125 * Gets the character offset from the beginning of the file
aoqi@0 126 * associated with this diagnostic that indicates the start of the
aoqi@0 127 * problem.
aoqi@0 128 *
aoqi@0 129 * @return offset from beginning of file; {@link #NOPOS} if and
aoqi@0 130 * only if {@link #getPosition()} returns {@link #NOPOS}
aoqi@0 131 */
aoqi@0 132 long getStartPosition();
aoqi@0 133
aoqi@0 134 /**
aoqi@0 135 * Gets the character offset from the beginning of the file
aoqi@0 136 * associated with this diagnostic that indicates the end of the
aoqi@0 137 * problem.
aoqi@0 138 *
aoqi@0 139 * @return offset from beginning of file; {@link #NOPOS} if and
aoqi@0 140 * only if {@link #getPosition()} returns {@link #NOPOS}
aoqi@0 141 */
aoqi@0 142 long getEndPosition();
aoqi@0 143
aoqi@0 144 /**
aoqi@0 145 * Gets the line number of the character offset returned by
aoqi@0 146 * {@linkplain #getPosition()}.
aoqi@0 147 *
aoqi@0 148 * @return a line number or {@link #NOPOS} if and only if {@link
aoqi@0 149 * #getPosition()} returns {@link #NOPOS}
aoqi@0 150 */
aoqi@0 151 long getLineNumber();
aoqi@0 152
aoqi@0 153 /**
aoqi@0 154 * Gets the column number of the character offset returned by
aoqi@0 155 * {@linkplain #getPosition()}.
aoqi@0 156 *
aoqi@0 157 * @return a column number or {@link #NOPOS} if and only if {@link
aoqi@0 158 * #getPosition()} returns {@link #NOPOS}
aoqi@0 159 */
aoqi@0 160 long getColumnNumber();
aoqi@0 161
aoqi@0 162 /**
aoqi@0 163 * Gets a diagnostic code indicating the type of diagnostic. The
aoqi@0 164 * code is implementation-dependent and might be {@code null}.
aoqi@0 165 *
aoqi@0 166 * @return a diagnostic code
aoqi@0 167 */
aoqi@0 168 String getCode();
aoqi@0 169
aoqi@0 170 /**
aoqi@0 171 * Gets a localized message for the given locale. The actual
aoqi@0 172 * message is implementation-dependent. If the locale is {@code
aoqi@0 173 * null} use the default locale.
aoqi@0 174 *
aoqi@0 175 * @param locale a locale; might be {@code null}
aoqi@0 176 * @return a localized message
aoqi@0 177 */
aoqi@0 178 String getMessage(Locale locale);
aoqi@0 179 }

mercurial