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