Diagnostic.java revision 2571:10fc81ac75b4
1166124Srafan/* 2166124Srafan * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. 3166124Srafan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4166124Srafan * 5166124Srafan * This code is free software; you can redistribute it and/or modify it 6166124Srafan * under the terms of the GNU General Public License version 2 only, as 7166124Srafan * published by the Free Software Foundation. Oracle designates this 8166124Srafan * particular file as subject to the "Classpath" exception as provided 9166124Srafan * by Oracle in the LICENSE file that accompanied this code. 10166124Srafan * 11166124Srafan * This code is distributed in the hope that it will be useful, but WITHOUT 12166124Srafan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13166124Srafan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14166124Srafan * version 2 for more details (a copy is included in the LICENSE file that 15166124Srafan * accompanied this code). 16166124Srafan * 17166124Srafan * You should have received a copy of the GNU General Public License version 18166124Srafan * 2 along with this work; if not, write to the Free Software Foundation, 19166124Srafan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20166124Srafan * 21166124Srafan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22166124Srafan * or visit www.oracle.com if you need additional information or have any 23166124Srafan * questions. 24166124Srafan */ 25166124Srafan 26166124Srafanpackage javax.tools; 27166124Srafan 28166124Srafanimport java.util.Locale; 29166124Srafan 30166124Srafan/** 31166124Srafan * Interface for diagnostics from tools. A diagnostic usually reports 32166124Srafan * a problem at a specific position in a source file. However, not 33166124Srafan * all diagnostics are associated with a position or a file. 34166124Srafan * 35166124Srafan * <p>A position is a zero-based character offset from the beginning of 36166124Srafan * a file. Negative values (except {@link #NOPOS}) are not valid 37166124Srafan * positions. 38166124Srafan * 39166124Srafan * <p>Line and column numbers begin at 1. Negative values (except 40166124Srafan * {@link #NOPOS}) and 0 are not valid line or column numbers. 41166124Srafan * 42166124Srafan * @param <S> the type of source object used by this diagnostic 43166124Srafan * 44166124Srafan * @author Peter von der Ahé 45166124Srafan * @author Jonathan Gibbons 46166124Srafan * @since 1.6 47166124Srafan */ 48166124Srafanpublic interface Diagnostic<S> { 49166124Srafan 50166124Srafan /** 51166124Srafan * Kinds of diagnostics, for example, error or warning. 52166124Srafan * 53166124Srafan * The kind of a diagnostic can be used to determine how the 54166124Srafan * diagnostic should be presented to the user. For example, 55166124Srafan * errors might be colored red or prefixed with the word "Error", 56166124Srafan * while warnings might be colored yellow or prefixed with the 57166124Srafan * word "Warning". There is no requirement that the Kind 58166124Srafan * should imply any inherent semantic meaning to the message 59166124Srafan * of the diagnostic: for example, a tool might provide an 60166124Srafan * option to report all warnings as errors. 61166124Srafan */ 62166124Srafan enum Kind { 63166124Srafan /** 64166124Srafan * Problem which prevents the tool's normal completion. 65166124Srafan */ 66166124Srafan ERROR, 67166124Srafan /** 68166124Srafan * Problem which does not usually prevent the tool from 69166124Srafan * completing normally. 70166124Srafan */ 71166124Srafan WARNING, 72166124Srafan /** 73166124Srafan * Problem similar to a warning, but is mandated by the tool's 74166124Srafan * specification. For example, the Java™ Language 75166124Srafan * Specification mandates warnings on certain 76166124Srafan * unchecked operations and the use of deprecated methods. 77166124Srafan */ 78 MANDATORY_WARNING, 79 /** 80 * Informative message from the tool. 81 */ 82 NOTE, 83 /** 84 * Diagnostic which does not fit within the other kinds. 85 */ 86 OTHER, 87 } 88 89 /** 90 * Used to signal that no position is available. 91 */ 92 public final static long NOPOS = -1; 93 94 /** 95 * Returns the kind of this diagnostic, for example, error or 96 * warning. 97 * @return the kind of this diagnostic 98 */ 99 Kind getKind(); 100 101 /** 102 * Returns the source object associated with this diagnostic. 103 * 104 * @return the source object associated with this diagnostic. 105 * {@code null} if no source object is associated with the 106 * diagnostic. 107 */ 108 S getSource(); 109 110 /** 111 * Returns a character offset from the beginning of the source object 112 * associated with this diagnostic that indicates the location of 113 * the problem. In addition, the following must be true: 114 * 115 * <p>{@code getStartPostion() <= getPosition()} 116 * <p>{@code getPosition() <= getEndPosition()} 117 * 118 * @return character offset from beginning of source; {@link 119 * #NOPOS} if {@link #getSource()} would return {@code null} or if 120 * no location is suitable 121 */ 122 long getPosition(); 123 124 /** 125 * Returns the character offset from the beginning of the file 126 * associated with this diagnostic that indicates the start of the 127 * problem. 128 * 129 * @return offset from beginning of file; {@link #NOPOS} if and 130 * only if {@link #getPosition()} returns {@link #NOPOS} 131 */ 132 long getStartPosition(); 133 134 /** 135 * Returns the character offset from the beginning of the file 136 * associated with this diagnostic that indicates the end of the 137 * problem. 138 * 139 * @return offset from beginning of file; {@link #NOPOS} if and 140 * only if {@link #getPosition()} returns {@link #NOPOS} 141 */ 142 long getEndPosition(); 143 144 /** 145 * Returns the line number of the character offset returned by 146 * {@linkplain #getPosition()}. 147 * 148 * @return a line number or {@link #NOPOS} if and only if {@link 149 * #getPosition()} returns {@link #NOPOS} 150 */ 151 long getLineNumber(); 152 153 /** 154 * Returns the column number of the character offset returned by 155 * {@linkplain #getPosition()}. 156 * 157 * @return a column number or {@link #NOPOS} if and only if {@link 158 * #getPosition()} returns {@link #NOPOS} 159 */ 160 long getColumnNumber(); 161 162 /** 163 * Returns a diagnostic code indicating the type of diagnostic. The 164 * code is implementation-dependent and might be {@code null}. 165 * 166 * @return a diagnostic code 167 */ 168 String getCode(); 169 170 /** 171 * Returns a localized message for the given locale. The actual 172 * message is implementation-dependent. If the locale is {@code 173 * null} use the default locale. 174 * 175 * @param locale a locale; might be {@code null} 176 * @return a localized message 177 */ 178 String getMessage(Locale locale); 179} 180