aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package javax.tools; aoqi@0: aoqi@0: import java.util.Locale; aoqi@0: aoqi@0: /** aoqi@0: * Interface for diagnostics from tools. A diagnostic usually reports aoqi@0: * a problem at a specific position in a source file. However, not aoqi@0: * all diagnostics are associated with a position or a file. aoqi@0: * aoqi@0: *

A position is a zero-based character offset from the beginning of aoqi@0: * a file. Negative values (except {@link #NOPOS}) are not valid aoqi@0: * positions. aoqi@0: * aoqi@0: *

Line and column numbers begin at 1. Negative values (except aoqi@0: * {@link #NOPOS}) and 0 are not valid line or column numbers. aoqi@0: * aoqi@0: * @param the type of source object used by this diagnostic aoqi@0: * aoqi@0: * @author Peter von der Ahé aoqi@0: * @author Jonathan Gibbons aoqi@0: * @since 1.6 aoqi@0: */ aoqi@0: public interface Diagnostic { aoqi@0: aoqi@0: /** aoqi@0: * Kinds of diagnostics, for example, error or warning. aoqi@0: * aoqi@0: * The kind of a diagnostic can be used to determine how the aoqi@0: * diagnostic should be presented to the user. For example, aoqi@0: * errors might be colored red or prefixed with the word "Error", aoqi@0: * while warnings might be colored yellow or prefixed with the aoqi@0: * word "Warning". There is no requirement that the Kind aoqi@0: * should imply any inherent semantic meaning to the message aoqi@0: * of the diagnostic: for example, a tool might provide an aoqi@0: * option to report all warnings as errors. aoqi@0: */ aoqi@0: enum Kind { aoqi@0: /** aoqi@0: * Problem which prevents the tool's normal completion. aoqi@0: */ aoqi@0: ERROR, aoqi@0: /** aoqi@0: * Problem which does not usually prevent the tool from aoqi@0: * completing normally. aoqi@0: */ aoqi@0: WARNING, aoqi@0: /** aoqi@0: * Problem similar to a warning, but is mandated by the tool's aoqi@0: * specification. For example, the Java™ Language aoqi@0: * Specification mandates warnings on certain aoqi@0: * unchecked operations and the use of deprecated methods. aoqi@0: */ aoqi@0: MANDATORY_WARNING, aoqi@0: /** aoqi@0: * Informative message from the tool. aoqi@0: */ aoqi@0: NOTE, aoqi@0: /** aoqi@0: * Diagnostic which does not fit within the other kinds. aoqi@0: */ aoqi@0: OTHER, aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Used to signal that no position is available. aoqi@0: */ aoqi@0: public final static long NOPOS = -1; aoqi@0: aoqi@0: /** aoqi@0: * Gets the kind of this diagnostic, for example, error or aoqi@0: * warning. aoqi@0: * @return the kind of this diagnostic aoqi@0: */ aoqi@0: Kind getKind(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the source object associated with this diagnostic. aoqi@0: * aoqi@0: * @return the source object associated with this diagnostic. aoqi@0: * {@code null} if no source object is associated with the aoqi@0: * diagnostic. aoqi@0: */ aoqi@0: S getSource(); aoqi@0: aoqi@0: /** aoqi@0: * Gets a character offset from the beginning of the source object aoqi@0: * associated with this diagnostic that indicates the location of aoqi@0: * the problem. In addition, the following must be true: aoqi@0: * aoqi@0: *

{@code getStartPostion() <= getPosition()} aoqi@0: *

{@code getPosition() <= getEndPosition()} aoqi@0: * aoqi@0: * @return character offset from beginning of source; {@link aoqi@0: * #NOPOS} if {@link #getSource()} would return {@code null} or if aoqi@0: * no location is suitable aoqi@0: */ aoqi@0: long getPosition(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the character offset from the beginning of the file aoqi@0: * associated with this diagnostic that indicates the start of the aoqi@0: * problem. aoqi@0: * aoqi@0: * @return offset from beginning of file; {@link #NOPOS} if and aoqi@0: * only if {@link #getPosition()} returns {@link #NOPOS} aoqi@0: */ aoqi@0: long getStartPosition(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the character offset from the beginning of the file aoqi@0: * associated with this diagnostic that indicates the end of the aoqi@0: * problem. aoqi@0: * aoqi@0: * @return offset from beginning of file; {@link #NOPOS} if and aoqi@0: * only if {@link #getPosition()} returns {@link #NOPOS} aoqi@0: */ aoqi@0: long getEndPosition(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the line number of the character offset returned by aoqi@0: * {@linkplain #getPosition()}. aoqi@0: * aoqi@0: * @return a line number or {@link #NOPOS} if and only if {@link aoqi@0: * #getPosition()} returns {@link #NOPOS} aoqi@0: */ aoqi@0: long getLineNumber(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the column number of the character offset returned by aoqi@0: * {@linkplain #getPosition()}. aoqi@0: * aoqi@0: * @return a column number or {@link #NOPOS} if and only if {@link aoqi@0: * #getPosition()} returns {@link #NOPOS} aoqi@0: */ aoqi@0: long getColumnNumber(); aoqi@0: aoqi@0: /** aoqi@0: * Gets a diagnostic code indicating the type of diagnostic. The aoqi@0: * code is implementation-dependent and might be {@code null}. aoqi@0: * aoqi@0: * @return a diagnostic code aoqi@0: */ aoqi@0: String getCode(); aoqi@0: aoqi@0: /** aoqi@0: * Gets a localized message for the given locale. The actual aoqi@0: * message is implementation-dependent. If the locale is {@code aoqi@0: * null} use the default locale. aoqi@0: * aoqi@0: * @param locale a locale; might be {@code null} aoqi@0: * @return a localized message aoqi@0: */ aoqi@0: String getMessage(Locale locale); aoqi@0: }