1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/javax/tools/Diagnostic.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,179 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package javax.tools; 1.30 + 1.31 +import java.util.Locale; 1.32 + 1.33 +/** 1.34 + * Interface for diagnostics from tools. A diagnostic usually reports 1.35 + * a problem at a specific position in a source file. However, not 1.36 + * all diagnostics are associated with a position or a file. 1.37 + * 1.38 + * <p>A position is a zero-based character offset from the beginning of 1.39 + * a file. Negative values (except {@link #NOPOS}) are not valid 1.40 + * positions. 1.41 + * 1.42 + * <p>Line and column numbers begin at 1. Negative values (except 1.43 + * {@link #NOPOS}) and 0 are not valid line or column numbers. 1.44 + * 1.45 + * @param <S> the type of source object used by this diagnostic 1.46 + * 1.47 + * @author Peter von der Ahé 1.48 + * @author Jonathan Gibbons 1.49 + * @since 1.6 1.50 + */ 1.51 +public interface Diagnostic<S> { 1.52 + 1.53 + /** 1.54 + * Kinds of diagnostics, for example, error or warning. 1.55 + * 1.56 + * The kind of a diagnostic can be used to determine how the 1.57 + * diagnostic should be presented to the user. For example, 1.58 + * errors might be colored red or prefixed with the word "Error", 1.59 + * while warnings might be colored yellow or prefixed with the 1.60 + * word "Warning". There is no requirement that the Kind 1.61 + * should imply any inherent semantic meaning to the message 1.62 + * of the diagnostic: for example, a tool might provide an 1.63 + * option to report all warnings as errors. 1.64 + */ 1.65 + enum Kind { 1.66 + /** 1.67 + * Problem which prevents the tool's normal completion. 1.68 + */ 1.69 + ERROR, 1.70 + /** 1.71 + * Problem which does not usually prevent the tool from 1.72 + * completing normally. 1.73 + */ 1.74 + WARNING, 1.75 + /** 1.76 + * Problem similar to a warning, but is mandated by the tool's 1.77 + * specification. For example, the Java™ Language 1.78 + * Specification mandates warnings on certain 1.79 + * unchecked operations and the use of deprecated methods. 1.80 + */ 1.81 + MANDATORY_WARNING, 1.82 + /** 1.83 + * Informative message from the tool. 1.84 + */ 1.85 + NOTE, 1.86 + /** 1.87 + * Diagnostic which does not fit within the other kinds. 1.88 + */ 1.89 + OTHER, 1.90 + } 1.91 + 1.92 + /** 1.93 + * Used to signal that no position is available. 1.94 + */ 1.95 + public final static long NOPOS = -1; 1.96 + 1.97 + /** 1.98 + * Gets the kind of this diagnostic, for example, error or 1.99 + * warning. 1.100 + * @return the kind of this diagnostic 1.101 + */ 1.102 + Kind getKind(); 1.103 + 1.104 + /** 1.105 + * Gets the source object associated with this diagnostic. 1.106 + * 1.107 + * @return the source object associated with this diagnostic. 1.108 + * {@code null} if no source object is associated with the 1.109 + * diagnostic. 1.110 + */ 1.111 + S getSource(); 1.112 + 1.113 + /** 1.114 + * Gets a character offset from the beginning of the source object 1.115 + * associated with this diagnostic that indicates the location of 1.116 + * the problem. In addition, the following must be true: 1.117 + * 1.118 + * <p>{@code getStartPostion() <= getPosition()} 1.119 + * <p>{@code getPosition() <= getEndPosition()} 1.120 + * 1.121 + * @return character offset from beginning of source; {@link 1.122 + * #NOPOS} if {@link #getSource()} would return {@code null} or if 1.123 + * no location is suitable 1.124 + */ 1.125 + long getPosition(); 1.126 + 1.127 + /** 1.128 + * Gets the character offset from the beginning of the file 1.129 + * associated with this diagnostic that indicates the start of the 1.130 + * problem. 1.131 + * 1.132 + * @return offset from beginning of file; {@link #NOPOS} if and 1.133 + * only if {@link #getPosition()} returns {@link #NOPOS} 1.134 + */ 1.135 + long getStartPosition(); 1.136 + 1.137 + /** 1.138 + * Gets the character offset from the beginning of the file 1.139 + * associated with this diagnostic that indicates the end of the 1.140 + * problem. 1.141 + * 1.142 + * @return offset from beginning of file; {@link #NOPOS} if and 1.143 + * only if {@link #getPosition()} returns {@link #NOPOS} 1.144 + */ 1.145 + long getEndPosition(); 1.146 + 1.147 + /** 1.148 + * Gets the line number of the character offset returned by 1.149 + * {@linkplain #getPosition()}. 1.150 + * 1.151 + * @return a line number or {@link #NOPOS} if and only if {@link 1.152 + * #getPosition()} returns {@link #NOPOS} 1.153 + */ 1.154 + long getLineNumber(); 1.155 + 1.156 + /** 1.157 + * Gets the column number of the character offset returned by 1.158 + * {@linkplain #getPosition()}. 1.159 + * 1.160 + * @return a column number or {@link #NOPOS} if and only if {@link 1.161 + * #getPosition()} returns {@link #NOPOS} 1.162 + */ 1.163 + long getColumnNumber(); 1.164 + 1.165 + /** 1.166 + * Gets a diagnostic code indicating the type of diagnostic. The 1.167 + * code is implementation-dependent and might be {@code null}. 1.168 + * 1.169 + * @return a diagnostic code 1.170 + */ 1.171 + String getCode(); 1.172 + 1.173 + /** 1.174 + * Gets a localized message for the given locale. The actual 1.175 + * message is implementation-dependent. If the locale is {@code 1.176 + * null} use the default locale. 1.177 + * 1.178 + * @param locale a locale; might be {@code null} 1.179 + * @return a localized message 1.180 + */ 1.181 + String getMessage(Locale locale); 1.182 +}