Path: blob/master/src/java.compiler/share/classes/javax/tools/Diagnostic.java
41152 views
/*1* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.tools;2627import java.util.Locale;2829/**30* Interface for diagnostics from tools. A diagnostic usually reports31* a problem at a specific position in a source file. However, not32* all diagnostics are associated with a position or a file.33*34* <p>A position is a zero-based character offset from the beginning of35* a file. Negative values (except {@link #NOPOS}) are not valid36* positions.37*38* <p>Line and column numbers begin at 1. Negative values (except39* {@link #NOPOS}) and 0 are not valid line or column numbers.40*41* @param <S> the type of source object used by this diagnostic42*43* @author Peter von der Ahé44* @author Jonathan Gibbons45* @since 1.646*/47public interface Diagnostic<S> {4849/**50* Kinds of diagnostics, for example, error or warning.51*52* The kind of a diagnostic can be used to determine how the53* diagnostic should be presented to the user. For example,54* errors might be colored red or prefixed with the word "Error",55* while warnings might be colored yellow or prefixed with the56* word "Warning". There is no requirement that the Kind57* should imply any inherent semantic meaning to the message58* of the diagnostic: for example, a tool might provide an59* option to report all warnings as errors.60*/61enum Kind {62/**63* Problem which prevents the tool's normal completion.64*/65ERROR,66/**67* Problem which does not usually prevent the tool from68* completing normally.69*/70WARNING,71/**72* Problem similar to a warning, but is mandated by the tool's73* specification. For example, the Java Language74* Specification mandates warnings on certain75* unchecked operations and the use of deprecated methods.76*/77MANDATORY_WARNING,78/**79* Informative message from the tool.80*/81NOTE,82/**83* Diagnostic which does not fit within the other kinds.84*/85OTHER,86}8788/**89* Used to signal that no position is available.90*/91public final static long NOPOS = -1;9293/**94* Returns the kind of this diagnostic, for example, error or95* warning.96* @return the kind of this diagnostic97*/98Kind getKind();99100/**101* Returns the source object associated with this diagnostic.102*103* @return the source object associated with this diagnostic.104* {@code null} if no source object is associated with the105* diagnostic.106*/107S getSource();108109/**110* Returns a character offset from the beginning of the source object111* associated with this diagnostic that indicates the location of112* the problem. In addition, the following must be true:113*114* <p>{@code getStartPosition() <= getPosition()}115* <p>{@code getPosition() <= getEndPosition()}116*117* @return character offset from beginning of source; {@link118* #NOPOS} if {@link #getSource()} would return {@code null} or if119* no location is suitable120*/121long getPosition();122123/**124* Returns the character offset from the beginning of the file125* associated with this diagnostic that indicates the start of the126* problem.127*128* @return offset from beginning of file; {@link #NOPOS} if and129* only if {@link #getPosition()} returns {@link #NOPOS}130*/131long getStartPosition();132133/**134* Returns the character offset from the beginning of the file135* associated with this diagnostic that indicates the end of the136* problem.137*138* @return offset from beginning of file; {@link #NOPOS} if and139* only if {@link #getPosition()} returns {@link #NOPOS}140*/141long getEndPosition();142143/**144* Returns the line number of the character offset returned by145* {@linkplain #getPosition()}.146*147* @return a line number or {@link #NOPOS} if and only if {@link148* #getPosition()} returns {@link #NOPOS}149*/150long getLineNumber();151152/**153* Returns the column number of the character offset returned by154* {@linkplain #getPosition()}.155*156* @return a column number or {@link #NOPOS} if and only if {@link157* #getPosition()} returns {@link #NOPOS}158*/159long getColumnNumber();160161/**162* Returns a diagnostic code indicating the type of diagnostic. The163* code is implementation-dependent and might be {@code null}.164*165* @return a diagnostic code166*/167String getCode();168169/**170* Returns a localized message for the given locale. The actual171* message is implementation-dependent. If the locale is {@code172* null} use the default locale.173*174* @param locale a locale; might be {@code null}175* @return a localized message176*/177String getMessage(Locale locale);178}179180181