author | naoto |
Fri, 16 Feb 2018 14:03:34 -0800 | |
changeset 48910 | 67cdc215ed70 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25287 | 2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package javax.tools; |
|
27 |
||
28 |
import java.util.Locale; |
|
29 |
||
30 |
/** |
|
31 |
* Interface for diagnostics from tools. A diagnostic usually reports |
|
32 |
* a problem at a specific position in a source file. However, not |
|
33 |
* all diagnostics are associated with a position or a file. |
|
34 |
* |
|
35 |
* <p>A position is a zero-based character offset from the beginning of |
|
36 |
* a file. Negative values (except {@link #NOPOS}) are not valid |
|
37 |
* positions. |
|
38 |
* |
|
39 |
* <p>Line and column numbers begin at 1. Negative values (except |
|
40 |
* {@link #NOPOS}) and 0 are not valid line or column numbers. |
|
41 |
* |
|
42 |
* @param <S> the type of source object used by this diagnostic |
|
43 |
* |
|
44 |
* @author Peter von der Ahé |
|
45 |
* @author Jonathan Gibbons |
|
46 |
* @since 1.6 |
|
47 |
*/ |
|
48 |
public interface Diagnostic<S> { |
|
49 |
||
50 |
/** |
|
51 |
* Kinds of diagnostics, for example, error or warning. |
|
20616
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
52 |
* |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
53 |
* The kind of a diagnostic can be used to determine how the |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
54 |
* diagnostic should be presented to the user. For example, |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
55 |
* errors might be colored red or prefixed with the word "Error", |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
56 |
* while warnings might be colored yellow or prefixed with the |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
57 |
* word "Warning". There is no requirement that the Kind |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
58 |
* should imply any inherent semantic meaning to the message |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
59 |
* of the diagnostic: for example, a tool might provide an |
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
60 |
* option to report all warnings as errors. |
10 | 61 |
*/ |
62 |
enum Kind { |
|
63 |
/** |
|
64 |
* Problem which prevents the tool's normal completion. |
|
65 |
*/ |
|
66 |
ERROR, |
|
67 |
/** |
|
68 |
* Problem which does not usually prevent the tool from |
|
69 |
* completing normally. |
|
70 |
*/ |
|
71 |
WARNING, |
|
72 |
/** |
|
73 |
* Problem similar to a warning, but is mandated by the tool's |
|
74 |
* specification. For example, the Java™ Language |
|
20616
ed49d47555ee
6525408: DiagnosticListener should receive MANDATORY_WARNING in standard compiler mode
jjg
parents:
5520
diff
changeset
|
75 |
* Specification mandates warnings on certain |
10 | 76 |
* unchecked operations and the use of deprecated methods. |
77 |
*/ |
|
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 |
/** |
|
25287 | 95 |
* Returns the kind of this diagnostic, for example, error or |
10 | 96 |
* warning. |
97 |
* @return the kind of this diagnostic |
|
98 |
*/ |
|
99 |
Kind getKind(); |
|
100 |
||
101 |
/** |
|
25287 | 102 |
* Returns the source object associated with this diagnostic. |
10 | 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 |
/** |
|
25287 | 111 |
* Returns a character offset from the beginning of the source object |
10 | 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 |
/** |
|
25287 | 125 |
* Returns the character offset from the beginning of the file |
10 | 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 |
/** |
|
25287 | 135 |
* Returns the character offset from the beginning of the file |
10 | 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 |
/** |
|
25287 | 145 |
* Returns the line number of the character offset returned by |
10 | 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 |
/** |
|
25287 | 154 |
* Returns the column number of the character offset returned by |
10 | 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 |
/** |
|
25287 | 163 |
* Returns a diagnostic code indicating the type of diagnostic. The |
10 | 164 |
* code is implementation-dependent and might be {@code null}. |
165 |
* |
|
166 |
* @return a diagnostic code |
|
167 |
*/ |
|
168 |
String getCode(); |
|
169 |
||
170 |
/** |
|
25287 | 171 |
* Returns a localized message for the given locale. The actual |
10 | 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 |
} |