Lines 15-21
Link Here
|
15 |
<p>The JDT plug-ins include an incremental and batch Java compiler for building Java .class files from source code. There is no direct API provided by the compiler. It is installed as a builder on |
15 |
<p>The JDT plug-ins include an incremental and batch Java compiler for building Java .class files from source code. There is no direct API provided by the compiler. It is installed as a builder on |
16 |
Java projects. Compilation is triggered using standard platform build mechanisms.</p> |
16 |
Java projects. Compilation is triggered using standard platform build mechanisms.</p> |
17 |
|
17 |
|
18 |
<p>The platform build mechanism is described in detail in <a href="../../org.eclipse.platform.doc.isv/guide/resAdv_builders.htm" class="XRef">Incremental project builders</a>.</p> |
18 |
<p>The platform build mechanism is described in detail in <a href="../../org.eclipse.platform.doc.isv/guide/resAdv_builders.htm" class="XRef">Incremental project builders</a>. Details about the batch compiler |
|
|
19 |
and the ant javac adapter are available in <a href="PLUGINS_ROOT/org.eclipse.jdt.doc.user/tasks/task-using_batch_compiler.htm">Using the batch compiler</a> and |
20 |
<a href="PLUGINS_ROOT/org.eclipse.jdt.doc.user/tasks/task-ant_javac_adapter.htm">Using the ant javac adapter</a>. </p> |
19 |
<h3>Compiling code</h3> |
21 |
<h3>Compiling code</h3> |
20 |
<p>You can programmatically compile the Java source files in a project using the build API.</p> |
22 |
<p>You can programmatically compile the Java source files in a project using the build API.</p> |
21 |
<pre class="color1"> |
23 |
<pre class="color1"> |
Lines 56-955
Link Here
|
56 |
myProject.setOptions(options); |
58 |
myProject.setOptions(options); |
57 |
</span> |
59 |
</span> |
58 |
</pre> |
60 |
</pre> |
59 |
<h3>Using the batch compiler</h3> |
|
|
60 |
<h4>Finding the batch compiler</h4> |
61 |
<p>The batch compiler class is located in the JDT Core plug-in. The name of the class is <i>org.eclipse.jdt.compiler.batch.BatchCompiler</i>. It is packaged into |
62 |
<code>plugins/org.eclipse.jdt.core_3.4.0.<qualifier>.jar</code>. Since 3.2, it is also available as a separate download. The name of the file is <code>ecj.jar</code>. Its corresponding source |
63 |
is also available. To get them, go to the <a href="http://download.eclipse.org/eclipse/downloads/">download page</a> and search for the section <b>JDT Core Batch Compiler</b>. This jar contains the |
64 |
batch compiler and the javac ant adapter.</p> |
65 |
|
66 |
<p>Since 3.3, this jar also contains the support for jsr199 (Compiler API) and the support for jsr269 (Annotation processing). <b>In order to use the annotations processing support, a 1.6 VM is |
67 |
required.</b></p> |
68 |
<p>So it can be used as a standalone application and inside an Ant build outside of Eclipse.</p> |
69 |
<h4>Running the batch compiler</h4> |
70 |
<ul> |
71 |
<li>From the command line. |
72 |
<p><code><span class="c3">java -jar org.eclipse.jdt.core_3.4.0<qualifier>.jar -classpath rt.jar A.java</span></code></p> |
73 |
<p>or:</p> |
74 |
<p><code><span class="c3">java -jar ecj.jar -classpath rt.jar A.java</span></code></p> |
75 |
|
76 |
</li> |
77 |
<li>Using the static <code>compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress)</code> method of the class BatchCompiler. |
78 |
<pre class="c4"> |
79 |
|
80 |
org.eclipse.jdt.compiler.CompilationProgress progress = null; // instantiate your subclass |
81 |
org.eclipse.jdt.internal.compiler.batch.BatchCompiler.compile( |
82 |
"-classpath rt.jar A.java", |
83 |
new PrintWriter(System.out), |
84 |
new PrintWriter(System.err), |
85 |
progress); |
86 |
</pre> |
87 |
<p>You can control how progress is reported, or how the batch compiler is canceled, by subclassing the class <i>org.eclipse.jdt.compiler.CompilationProgress</i>.</p> |
88 |
</li> |
89 |
</ul> |
90 |
<h4>Which options are available?</h4> |
91 |
|
92 |
<p>The recommended options have an orange background.</p> |
93 |
<p>When some options are being set multiple times, the batch compiler consumes them from left to right. When the warning option (-warn:....) is used without '+' or '-', this overrides the set of |
94 |
warnings previously specified. So the user should make sure that such an option is given before any other usage of the -warn option.</p> |
95 |
<p>Same applies for the -err: option.</p> |
96 |
<table border="1" cellspacing="2" cellpadding="2"> |
97 |
<tr> |
98 |
<th>Name</th> |
99 |
<th colspan="3">Usage</th> |
100 |
</tr> |
101 |
<tr> |
102 |
<th colspan="4">Classpath options</th> |
103 |
</tr> |
104 |
|
105 |
<tr> |
106 |
<td class="c5" valign="top" width="250">-bootclasspath <dir 1>;<dir 2>;...;<dir P></td> |
107 |
<td class="c5" valign="top" colspan="3">This is a list of directories or jar files used to bootstrap the class files used by the compiler. By default the libraries of the running VM are used. Entries |
108 |
are separated by the platform path separator.<br /> |
109 |
Each directory or file can specify access rules for types between '[' and ']'. |
110 |
<p>If no bootclasspath is specified, the compiler will infer it using the following system properties <code>sun.boot.class.path</code>, <code>vm.boot.class.path</code> or |
111 |
|
112 |
<code>org.apache.harmony.boot.class.path</code> in this order respectively.</p> |
113 |
</td> |
114 |
</tr> |
115 |
<tr> |
116 |
<td class="c5" valign="top" width="250">-cp<br /> |
117 |
-classpath <dir 1>;<dir 2>;...;<dir P></td> |
118 |
|
119 |
<td class="c5" valign="top" colspan="3">This is a list of directories or jar files used to compile the source files. The default value is the value of the property "java.class.path". Entries are |
120 |
separated by the platform path separator.<br /> |
121 |
Each directory or file can specify access rules for types between '[' and ']' (e.g. [-X] to forbid access to type X, [~X] to discourage access to type X, [+p/X:-p/*] to forbid access to all types in |
122 |
package p but allow access to p/X).<br /> |
123 |
The compiler follows the <code>Class-Path</code> clauses of jar files' manifests recursively and appends each referenced jar file to the end of the classpath, provided it is not on the classpath |
124 |
yet.</td> |
125 |
</tr> |
126 |
<tr> |
127 |
<td valign="top" width="250">-extdirs <dir 1>;<dir 2>;...;<dir P></td> |
128 |
|
129 |
<td valign="top" colspan="3">This is a list of directories used to specify the location of extension zip/jar files. Entries are separated by the platform path separator.</td> |
130 |
</tr> |
131 |
<tr> |
132 |
<td valign="top" width="250">-endorseddirs <dir 1>;<dir 2>;...;<dir P></td> |
133 |
<td valign="top" colspan="3">This is a list of directories used to specify the location of endorsed zip/jar files. Entries are separated by the platform path separator.</td> |
134 |
</tr> |
135 |
|
136 |
<tr> |
137 |
<td valign="top" width="250">-sourcepath <dir 1>;<dir 2>;...;<dir P></td> |
138 |
<td valign="top" colspan="3">This is a list of directories used to specify the source files. Entries are separated by the platform path separator.<br /> |
139 |
Each directory can specify access rules for types between '[' and ']'.</td> |
140 |
</tr> |
141 |
<tr> |
142 |
|
143 |
<td class="c5" valign="top" width="250">-d <dir 1>|none</td> |
144 |
<td class="c5" colspan="3">This is used to specify in which directory the generated .class files should be dumped. If it is omitted, no package directory structure is created.<br /> |
145 |
If you want to generate no .class file at all, use <span class="c3">-d none</span>.</td> |
146 |
</tr> |
147 |
<tr> |
148 |
<td valign="top" width="250">-encoding <encoding name></td> |
149 |
<td colspan="3">Specify default encoding for all source files. Custom encoding can also be specified on a per file basis by suffixing each input source file/folder name with <span class= |
150 |
"c3">[<encoding name>]</span>. For example <span class="c3">X.java[utf8]</span> would specify the <code>UTF-8</code> encoding for the compilation unit X.java located in the current user |
151 |
directory. |
152 |
|
153 |
<p>If multiple default source file encodings are specified, the last one will be used.</p> |
154 |
<p>For example:</p> |
155 |
<ul> |
156 |
<li><span class="c3"><code>... -encoding UTF-8 X.java[Cp1252] Y.java[UTF-16] Z.java ....</code></span><br /> |
157 |
All source files will be read using UTF-8 encoding (this includes <span class="c3">Z.java</span>). <span class="c3">X.java</span> will be read using Cp1252 encoding and <span class="c3">Y.java</span> |
158 |
will be read using UTF-16 encoding.</li> |
159 |
|
160 |
<li><span class="c3"><code>... -encoding UTF-8 -encoding UTF-16 ....</code></span><br /> |
161 |
All source files will be read using UTF-16 encoding. The -encoding option for UTF-8 is ignored.</li> |
162 |
<li><span class="c3"><code>... -encoding Cp1252 /foo/bar/X.java[UTF-16] /foo/bar[UTF-8] ....</code></span><br /> |
163 |
All source files will be read using Cp1252 encoding. X.java is the only file inside the /foo/bar directory to be read using the encoding UTF-16. All other files in that directory will use UTF-8 |
164 |
encoding.</li> |
165 |
</ul> |
166 |
</td> |
167 |
</tr> |
168 |
<tr> |
169 |
<th colspan="4">Compliance options</th> |
170 |
</tr> |
171 |
<tr> |
172 |
<td valign="top" width="250">-target 1.1 to 1.7 or (5, 5.0, etc)</td> |
173 |
|
174 |
<td colspan="3">This specifies the .class file target setting. The possible value are: |
175 |
<ul> |
176 |
<li><span class="c3">1.1</span> (major version: 45 minor: 3)</li> |
177 |
<li><span class="c3">1.2</span> (major version: 46 minor: 0)</li> |
178 |
<li><span class="c3">1.3</span> (major version: 47 minor: 0)</li> |
179 |
<li><span class="c3">1.4</span> (major version: 48 minor: 0)</li> |
180 |
|
181 |
<li><span class="c3">1.5</span>, <span class="c3">5</span> or <span class="c3">5.0</span> (major version: 49 minor: 0)</li> |
182 |
<li><span class="c3">1.6</span>, <span class="c3">6</span> or <span class="c3">6.0</span> (major version: 50 minor: 0)</li> |
183 |
|
184 |
<li><span class="c3">1.7</span>, <span class="c3">7</span> or <span class="c3">7.0</span> (major version: 51 minor: 0)</li> |
185 |
</ul> |
186 |
Defaults are: |
187 |
<ul> |
188 |
<li><span class="c3">1.1</span> in <span class="c3">-1.3</span> mode</li> |
189 |
|
190 |
<li><span class="c3">1.2</span> in <span class="c3">-1.4</span> mode</li> |
191 |
<li><span class="c3">1.5</span> in <span class="c3">-1.5</span> mode</li> |
192 |
<li><span class="c3">1.6</span> in <span class="c3">-1.6</span> mode</li> |
193 |
|
194 |
<li><span class="c3">1.7</span> in <span class="c3">-1.7</span> mode</li> |
195 |
</ul> |
196 |
<p>clcd1.1 can be used to generate the StackMap attribute.</p> |
197 |
</td> |
198 |
</tr> |
199 |
<tr> |
200 |
<td valign="top">-1.3</td> |
201 |
<td colspan="3">Set compliance level to <span class="c3">1.3</span>. Implicit -source 1.3 -target 1.1.</td> |
202 |
|
203 |
</tr> |
204 |
<tr> |
205 |
<td valign="top">-1.4</td> |
206 |
<td colspan="3">Set compliance level to <span class="c3">1.4</span> (default). Implicit -source 1.3 -target 1.2.</td> |
207 |
</tr> |
208 |
<tr> |
209 |
<td valign="top">-1.5</td> |
210 |
<td colspan="3">Set compliance level to <span class="c3">1.5</span>. Implicit -source 1.5 -target 1.5.</td> |
211 |
|
212 |
</tr> |
213 |
<tr> |
214 |
<td valign="top">-1.6</td> |
215 |
<td colspan="3">Set compliance level to <span class="c3">1.6</span>. Implicit -source 1.6 -target 1.6.</td> |
216 |
</tr> |
217 |
<tr> |
218 |
<td valign="top">-1.7</td> |
219 |
<td colspan="3">Set compliance level to <span class="c3">1.7</span>. Implicit -source 1.7 -target 1.7.</td> |
220 |
</tr> |
221 |
|
222 |
<tr> |
223 |
<td valign="top" width="250">-source 1.1 to 1.7 or (5, 5.0, etc)</td> |
224 |
<td colspan="3">This is used to specify the source level expected by the compiler.<br /> |
225 |
The possible value are: |
226 |
<ul> |
227 |
<li><span class="c3">1.3</span></li> |
228 |
<li><span class="c3">1.4</span></li> |
229 |
<li><span class="c3">1.5</span>, <span class="c3">5</span> or <span class="c3">5.0</span></li> |
230 |
|
231 |
<li><span class="c3">1.6</span>, <span class="c3">6</span> or <span class="c3">6.0</span></li> |
232 |
<li><span class="c3">1.7</span>, <span class="c3">7</span> or <span class="c3">7.0</span></li> |
233 |
</ul> |
234 |
Defaults are: |
235 |
<ul> |
236 |
|
237 |
<li><span class="c3">1.3</span> in <span class="c3">-1.3</span> mode</li> |
238 |
<li><span class="c3">1.3</span> in <span class="c3">-1.4</span> mode</li> |
239 |
<li><span class="c3">1.5</span> in <span class="c3">-1.5</span> mode</li> |
240 |
|
241 |
<li><span class="c3">1.6</span> in <span class="c3">-1.6</span> mode</li> |
242 |
<li><span class="c3">1.7</span> in <span class="c3">-1.7</span> mode</li> |
243 |
</ul> |
244 |
In <span class="c3">1.4</span>, <span class="c3"><i>assert</i></span> is treated as a keyword. In <span class="c3">1.5</span> and <span class="c3">1.6</span>, <span class="c3"><i>enum</i></span> and |
245 |
|
246 |
<span class="c3"><i>assert</i></span> are treated as a keywords.</td> |
247 |
</tr> |
248 |
<tr> |
249 |
<th colspan="4">Warning options</th> |
250 |
</tr> |
251 |
<tr> |
252 |
<td valign="top">-?:warn -help:warn</td> |
253 |
<td colspan="3">Display advanced warning options</td> |
254 |
</tr> |
255 |
<tr> |
256 |
<td valign="top" width="250" rowspan="70">-warn:...</td> |
257 |
|
258 |
<td valign="top" colspan="3">Specify the set of enabled warnings.<br /> |
259 |
e.g. <span class="c3">-warn:unusedLocal,deprecation</span><br /> |
260 |
<table> |
261 |
<tr> |
262 |
<td>-warn:none</td> |
263 |
<td>disable all warnings</td> |
264 |
</tr> |
265 |
<tr> |
266 |
<td>-warn:<warning tokens separated by ,></td> |
267 |
<td>enable exactly the listed warnings</td> |
268 |
|
269 |
</tr> |
270 |
<tr> |
271 |
<td>-warn:+<warning tokens separated by ,></td> |
272 |
<td>enable additional warnings</td> |
273 |
</tr> |
274 |
<tr> |
275 |
<td>-warn:-<warning tokens separated by ,></td> |
276 |
<td>disable specific warnings</td> |
277 |
</tr> |
278 |
</table> |
279 |
</td> |
280 |
</tr> |
281 |
<tr> |
282 |
<th align="center" width="50">Default</th> |
283 |
<th align="left" width="150">Token name</th> |
284 |
<th align="left">Description</th> |
285 |
</tr> |
286 |
<tr> |
287 |
<td align="center" valign="top">-</td> |
288 |
<td align="left" valign="top">allDeadCode</td> |
289 |
<td valign="top">dead code including trivial if(DEBUG) check</td> |
290 |
</tr> |
291 |
|
292 |
<tr> |
293 |
<td align="center" valign="top">-</td> |
294 |
<td align="left" valign="top">allDeprecation</td> |
295 |
<td valign="top">deprecation even inside deprecated code</td> |
296 |
</tr> |
297 |
<tr> |
298 |
<td align="center" valign="top">-</td> |
299 |
<td align="left" valign="top">allJavadoc</td> |
300 |
<td valign="top">invalid or missing javadoc</td> |
301 |
</tr> |
302 |
<tr> |
303 |
|
304 |
<td align="center" valign="top">-</td> |
305 |
<td align="left" valign="top">allOver-ann</td> |
306 |
<td valign="top">all missing @Override annotations (superclass and superinterfaces)</td> |
307 |
</tr> |
308 |
<tr> |
309 |
<td align="center" valign="top">+</td> |
310 |
<td align="left" valign="top">assertIdentifier</td> |
311 |
<td valign="top">occurrence of <i>assert</i> used as identifier</td> |
312 |
|
313 |
</tr> |
314 |
<tr> |
315 |
<td align="center" valign="top">-</td> |
316 |
<td align="left" valign="top">boxing</td> |
317 |
<td valign="top">autoboxing conversion</td> |
318 |
</tr> |
319 |
<tr> |
320 |
<td align="center" valign="top">+</td> |
321 |
<td align="left" valign="top">charConcat</td> |
322 |
<td valign="top">when a char array is used in a string concatenation without being converted explicitly to a string</td> |
323 |
</tr> |
324 |
|
325 |
<tr> |
326 |
<td align="center" valign="top">+</td> |
327 |
<td align="left" valign="top">compareIdentical</td> |
328 |
<td valign="top">comparing identical expressions</td> |
329 |
</tr> |
330 |
<tr> |
331 |
<td align="center" valign="top">-</td> |
332 |
<td align="left" valign="top">conditionAssign</td> |
333 |
<td valign="top">possible accidental boolean assignment</td> |
334 |
</tr> |
335 |
<tr> |
336 |
|
337 |
<td align="center" valign="top">+</td> |
338 |
<td align="left" valign="top">constructorName</td> |
339 |
<td valign="top">method with constructor name</td> |
340 |
</tr> |
341 |
<tr> |
342 |
<td align="center" valign="top">+</td> |
343 |
<td align="left" valign="top">deadCode</td> |
344 |
<td valign="top">dead code excluding trivial if (DEBUG) check</td> |
345 |
</tr> |
346 |
<tr> |
347 |
<td align="center" valign="top">-</td> |
348 |
|
349 |
<td align="left" valign="top">dep-ann</td> |
350 |
<td valign="top">missing @Deprecated annotation</td> |
351 |
</tr> |
352 |
<tr> |
353 |
<td align="center" valign="top">+</td> |
354 |
<td align="left" valign="top">deprecation</td> |
355 |
<td valign="top">usage of deprecated type or member outside deprecated code</td> |
356 |
</tr> |
357 |
<tr> |
358 |
<td align="center" valign="top">+</td> |
359 |
<td align="left" valign="top">discouraged</td> |
360 |
|
361 |
<td valign="top">use of types matching a discouraged access rule</td> |
362 |
</tr> |
363 |
<tr> |
364 |
<td align="center" valign="top">-</td> |
365 |
<td align="left" valign="top">emptyBlock</td> |
366 |
<td valign="top">undocumented empty block</td> |
367 |
</tr> |
368 |
<tr> |
369 |
<td align="center" valign="top">+</td> |
370 |
<td align="left" valign="top">enumIdentifier</td> |
371 |
<td valign="top">occurrence of <i>enum</i> used as identifier</td> |
372 |
|
373 |
</tr> |
374 |
<tr> |
375 |
<td align="center" valign="top">-</td> |
376 |
<td align="left" valign="top">enumSwitch</td> |
377 |
<td valign="top">incomplete enum switch</td> |
378 |
</tr> |
379 |
<tr> |
380 |
<td align="center" valign="top">-</td> |
381 |
<td align="left" valign="top">fallthrough</td> |
382 |
<td valign="top">possible fall-through case</td> |
383 |
</tr> |
384 |
|
385 |
<tr> |
386 |
<td align="center" valign="top">-</td> |
387 |
<td align="left" valign="top">fieldHiding</td> |
388 |
<td valign="top">field hiding another variable</td> |
389 |
</tr> |
390 |
<tr> |
391 |
<td align="center" valign="top">+</td> |
392 |
<td align="left" valign="top">finalBound</td> |
393 |
<td valign="top">type parameter with final bound</td> |
394 |
</tr> |
395 |
<tr> |
396 |
|
397 |
<td align="center" valign="top">+</td> |
398 |
<td align="left" valign="top">finally</td> |
399 |
<td valign="top">finally block not completing normally</td> |
400 |
</tr> |
401 |
<tr> |
402 |
<td align="center" valign="top">+</td> |
403 |
<td align="left" valign="top">forbidden</td> |
404 |
<td valign="top">use of types matching a forbidden access rule</td> |
405 |
</tr> |
406 |
<tr> |
407 |
<td align="center" valign="top">-</td> |
408 |
|
409 |
<td align="left" valign="top">hashCode</td> |
410 |
<td valign="top">missing hashCode() method when overriding equals()</td> |
411 |
</tr> |
412 |
<tr> |
413 |
<td align="center" valign="top">-</td> |
414 |
<td align="left" valign="top">hiding</td> |
415 |
<td valign="top">macro for fieldHiding, localHiding, typeHiding and maskedCatchBlock</td> |
416 |
</tr> |
417 |
<tr> |
418 |
<td align="center" valign="top">-</td> |
419 |
<td align="left" valign="top">includeAssertNull</td> |
420 |
<td valign="top">raise null warnings for variables that got tainted in an assert expression</td> |
421 |
</tr> |
422 |
<tr> |
423 |
<td align="center" valign="top">-</td> |
424 |
<td align="left" valign="top">indirectStatic</td> |
425 |
<td valign="top">indirect reference to static member</td> |
426 |
</tr> |
427 |
<tr> |
428 |
<td align="center" valign="top">+</td> |
429 |
<td align="left" valign="top">intfAnnotation</td> |
430 |
<td valign="top">annotation type used as super interface</td> |
431 |
</tr> |
432 |
<tr> |
433 |
<td align="center" valign="top">+</td> |
434 |
<td align="left" valign="top">intfNonInherited</td> |
435 |
<td valign="top">interface non-inherited method compatibility</td> |
436 |
|
437 |
</tr> |
438 |
<tr> |
439 |
<td align="center" valign="top">-</td> |
440 |
<td align="left" valign="top">intfRedundant</td> |
441 |
<td valign="top">find redundant superinterfaces</td> |
442 |
</tr> |
443 |
<tr> |
444 |
<td align="center" valign="top">-</td> |
445 |
<td align="left" valign="top">javadoc</td> |
446 |
<td valign="top">invalid javadoc</td> |
447 |
</tr> |
448 |
|
449 |
<tr> |
450 |
<td align="center" valign="top">-</td> |
451 |
<td align="left" valign="top">localHiding</td> |
452 |
<td valign="top">local variable hiding another variable</td> |
453 |
</tr> |
454 |
<tr> |
455 |
<td align="center" valign="top">+</td> |
456 |
<td align="left" valign="top">maskedCatchBlock</td> |
457 |
<td valign="top">hidden catch block</td> |
458 |
</tr> |
459 |
<tr> |
460 |
|
461 |
<td align="center" valign="top">-</td> |
462 |
<td align="left" valign="top">nls</td> |
463 |
<td valign="top">non-nls string literals (lacking of tags //$NON-NLS-<n>)</td> |
464 |
</tr> |
465 |
<tr> |
466 |
<td align="center" valign="top">+</td> |
467 |
<td align="left" valign="top">noEffectAssign</td> |
468 |
<td valign="top">assignment with no effect</td> |
469 |
</tr> |
470 |
|
471 |
<tr> |
472 |
<td align="center" valign="top">-</td> |
473 |
<td align="left" valign="top">null</td> |
474 |
<td valign="top">potential missing or redundant null check</td> |
475 |
</tr> |
476 |
<tr> |
477 |
<td align="center" valign="top">-</td> |
478 |
<td align="left" valign="top">nullDereference</td> |
479 |
<td valign="top">missing null check</td> |
480 |
</tr> |
481 |
<tr> |
482 |
|
483 |
<td align="center" valign="top">-</td> |
484 |
<td align="left" valign="top">over-ann</td> |
485 |
<td valign="top">missing @Override annotation (superclass only)</td> |
486 |
</tr> |
487 |
<tr> |
488 |
<td align="center" valign="top">-</td> |
489 |
<td align="left" valign="top">paramAssign</td> |
490 |
<td valign="top">assignment to a parameter</td> |
491 |
</tr> |
492 |
<tr> |
493 |
<td align="center" valign="top">+</td> |
494 |
|
495 |
<td align="left" valign="top">pkgDefaultMethod</td> |
496 |
<td valign="top">attempt to override package-default method</td> |
497 |
</tr> |
498 |
<tr> |
499 |
<td align="center" valign="top">+</td> |
500 |
<td align="left" valign="top">raw</td> |
501 |
<td valign="top">usage a of raw type (instead of a parameterized type)</td> |
502 |
</tr> |
503 |
<tr> |
504 |
<td align="center" valign="top">-</td> |
505 |
<td align="left" valign="top">semicolon</td> |
506 |
|
507 |
<td valign="top">unnecessary semicolon or empty statement</td> |
508 |
</tr> |
509 |
<tr> |
510 |
<td align="center" valign="top">+</td> |
511 |
<td align="left" valign="top">serial</td> |
512 |
<td valign="top">missing serialVersionUID</td> |
513 |
</tr> |
514 |
<tr> |
515 |
<td align="center" valign="top">-</td> |
516 |
<td align="left" valign="top">specialParamHiding</td> |
517 |
<td valign="top">constructor or setter parameter hiding another field</td> |
518 |
|
519 |
</tr> |
520 |
<tr> |
521 |
<td align="center" valign="top">-</td> |
522 |
<td align="left" valign="top">static-access</td> |
523 |
<td valign="top">macro for indirectStatic and staticReceiver</td> |
524 |
</tr> |
525 |
<tr> |
526 |
<td align="center" valign="top">-</td> |
527 |
<td align="left" valign="top">static-method</td> |
528 |
<td valign="top">an instance method that could be as a static method</td> |
529 |
</tr> |
530 |
<tr> |
531 |
<td align="center" valign="top">+</td> |
532 |
<td align="left" valign="top">staticReceiver</td> |
533 |
<td valign="top">if a non static receiver is used to get a static field or call a static method</td> |
534 |
</tr> |
535 |
|
536 |
<tr> |
537 |
<td align="center" valign="top">-</td> |
538 |
<td align="left" valign="top">super</td> |
539 |
<td valign="top">overriding a method without making a super invocation</td> |
540 |
</tr> |
541 |
<tr> |
542 |
<td align="center" valign="top">+</td> |
543 |
<td align="left" valign="top">suppress</td> |
544 |
<td valign="top">enable @SuppressWarnings</td> |
545 |
</tr> |
546 |
<tr> |
547 |
|
548 |
<td align="center" valign="top">-</td> |
549 |
<td align="left" valign="top">syncOverride</td> |
550 |
<td valign="top">missing synchronized in synchronized method override</td> |
551 |
</tr> |
552 |
<tr> |
553 |
<td align="center" valign="top">-</td> |
554 |
<td align="left" valign="top">syntheticAccess</td> |
555 |
<td valign="top">when performing synthetic access for innerclass</td> |
556 |
</tr> |
557 |
<tr> |
558 |
<td align="center" valign="top">-</td> |
559 |
<td align="left" valign="top">tasks</td> |
560 |
<td valign="top">enable support for tasks tags in source code</td> |
561 |
</tr> |
562 |
<tr> |
563 |
<td align="center" valign="top">+</td> |
564 |
<td align="left" valign="top">typeHiding</td> |
565 |
<td valign="top">type parameter hiding another type</td> |
566 |
</tr> |
567 |
<tr> |
568 |
<td align="center" valign="top">+</td> |
569 |
<td align="left" valign="top">unavoidableGenericProblems</td> |
570 |
<td valign="top">ignore unavoidable type safety problems due to raw APIs</td> |
571 |
</tr> |
572 |
<tr> |
573 |
<td align="center" valign="top">+</td> |
574 |
<td align="left" valign="top">unchecked</td> |
575 |
<td valign="top">unchecked type operation</td> |
576 |
</tr> |
577 |
<tr> |
578 |
<td align="center" valign="top">-</td> |
579 |
<td align="left" valign="top">unnecessaryElse</td> |
580 |
<td valign="top">unnecessary else clause</td> |
581 |
</tr> |
582 |
<tr> |
583 |
<td align="center" valign="top">-</td> |
584 |
<td align="left" valign="top">unqualifiedField</td> |
585 |
<td valign="top">unqualified reference to field</td> |
586 |
|
587 |
</tr> |
588 |
<tr> |
589 |
<td align="center" valign="top">-</td> |
590 |
<td align="left" valign="top">unused</td> |
591 |
<td valign="top">macro for unusedAllocation, unusedArgument, unusedImport, unusedLabel, unusedLocal, unusedPrivate, unusedThrown and unusedTypeArgs</td> |
592 |
</tr> |
593 |
<tr> |
594 |
<td align="center" valign="top">-</td> |
595 |
<td align="left" valign="top">unusedAllocation</td> |
596 |
<td valign="top">allocating an object that is not used</td> |
597 |
</tr> |
598 |
<tr> |
599 |
<td align="center" valign="top">-</td> |
600 |
<td align="left" valign="top">unusedArgument</td> |
601 |
<td valign="top">unused method argument</td> |
602 |
</tr> |
603 |
<tr> |
604 |
<td align="center" valign="top">+</td> |
605 |
<td align="left" valign="top">unusedImport</td> |
606 |
<td valign="top">unused import reference</td> |
607 |
</tr> |
608 |
<tr> |
609 |
<td align="center" valign="top">+</td> |
610 |
<td align="left" valign="top">unusedLabel</td> |
611 |
<td valign="top">unused label</td> |
612 |
</tr> |
613 |
<tr> |
614 |
<td align="center" valign="top">+</td> |
615 |
<td align="left" valign="top">unusedLocal</td> |
616 |
<td valign="top">unused local variable</td> |
617 |
</tr> |
618 |
<tr> |
619 |
<td align="center" valign="top">+</td> |
620 |
|
621 |
<td align="left" valign="top">unusedPrivate</td> |
622 |
<td valign="top">unused private member declaration</td> |
623 |
</tr> |
624 |
<tr> |
625 |
<td align="center" valign="top">-</td> |
626 |
<td align="left" valign="top">unusedThrown</td> |
627 |
<td valign="top">unused declared thrown exception</td> |
628 |
</tr> |
629 |
<tr> |
630 |
<td align="center" valign="top">+</td> |
631 |
<td align="left" valign="top">unusedTypeArgs</td> |
632 |
<td valign="top">unused type arguments for method</td> |
633 |
</tr> |
634 |
<tr> |
635 |
<td align="center" valign="top">-</td> |
636 |
<td align="left" valign="top">uselessTypeCheck</td> |
637 |
<td valign="top">unnecessary cast/instanceof operation</td> |
638 |
</tr> |
639 |
<tr> |
640 |
<td align="center" valign="top">+</td> |
641 |
<td align="left" valign="top">varargsCast</td> |
642 |
<td valign="top">varargs argument need explicit cast</td> |
643 |
</tr> |
644 |
<tr> |
645 |
<td align="center" valign="top">+</td> |
646 |
<td align="left" valign="top">warningToken</td> |
647 |
<td valign="top">unhandled warning token in @SuppressWarnings</td> |
648 |
</tr> |
649 |
<tr> |
650 |
<td valign="top">-nowarn</td> |
651 |
<td colspan="3">No warning (equivalent to <span class="c3">-warn:none</span>)</td> |
652 |
</tr> |
653 |
<tr> |
654 |
<td valign="top" width="250">-err:...</td> |
655 |
<td valign="top" colspan="3">Specify the set of enabled warnings that are converted to errors.<br /> |
656 |
e.g. <span class="c3">-err:unusedLocal,deprecation</span><br /> |
657 |
unusedLocal and deprecation warnings will be converted to errors. All other warnings are still reported as warnings. |
658 |
<table> |
659 |
<tr> |
660 |
<td>-err:<warning tokens separated by ,></td> |
661 |
<td>convert exactly the listed warnings to errors</td> |
662 |
</tr> |
663 |
|
664 |
<tr> |
665 |
<td>-err:+<warning tokens separated by ,></td> |
666 |
<td>convert additional warnings to errors</td> |
667 |
</tr> |
668 |
<tr> |
669 |
<td>-err:-<warning tokens separated by ,></td> |
670 |
<td>remove specific warnings from being converted to errors</td> |
671 |
</tr> |
672 |
</table> |
673 |
</td> |
674 |
</tr> |
675 |
|
676 |
<tr> |
677 |
<td valign="top">-deprecation</td> |
678 |
<td colspan="3">Equivalent to <span class="c3">-warn:+deprecation</span>.</td> |
679 |
</tr> |
680 |
<tr> |
681 |
<td valign="top">-properties <file></td> |
682 |
<td colspan="3">Set warnings/errors option based on the properties file contents. This option can be used with -nowarn, -err:.. or -warn:.. options, but the last one on the command line sets the |
683 |
options to be used.<br /> |
684 |
<p>The properties file contents can be generated by setting project specific settings on an existing java project and using the file in <code>.settings/org.eclipse.jdt.core.prefs</code> file as a |
685 |
properties file, or a simple text file that is defined entry/value pairs using the constants defined in the <code>org.eclipse.jdt.core.JavaCore</code> class.</p> |
686 |
|
687 |
<pre> |
688 |
... |
689 |
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning |
690 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning |
691 |
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore |
692 |
... |
693 |
</pre></td> |
694 |
</tr> |
695 |
<tr> |
696 |
<th colspan="4">Debug options</th> |
697 |
</tr> |
698 |
<tr> |
699 |
<td valign="top">-g[:none|:lines,vars,source]</td> |
700 |
<td colspan="3">Set the debug attributes level<br /> |
701 |
<table> |
702 |
<tr> |
703 |
<th align="left">-g</th> |
704 |
|
705 |
<td colspan="3">All debug info (equivalent to <span class="c3">-g:lines,vars,source</span>)</td> |
706 |
</tr> |
707 |
<tr> |
708 |
<th align="left">-g:none</th> |
709 |
<td colspan="3">No debug info</td> |
710 |
</tr> |
711 |
<tr> |
712 |
<th align="left">-g:[lines,vars,source]</th> |
713 |
<td colspan="3">Selective debug info</td> |
714 |
</tr> |
715 |
|
716 |
</table> |
717 |
</td> |
718 |
</tr> |
719 |
<tr> |
720 |
<td valign="top">-preserveAllLocals</td> |
721 |
<td colspan="3">Explicitly request the compiler to preserve all local variables (for debug purpose). If omitted, the compiler will remove unused locals.</td> |
722 |
</tr> |
723 |
<tr> |
724 |
<th colspan="4">Annotation processing options (require a 1.6 VM or above and are used only if the compliance is 1.6)</th> |
725 |
</tr> |
726 |
<tr> |
727 |
<td>-Akey[=value]</td> |
728 |
<td valign="top" colspan="3">Annotation processors options that are passed to annotation processors. <code>key</code> is made of identifiers separated by dots</td> |
729 |
|
730 |
</tr> |
731 |
<tr> |
732 |
<td>-proc:[only|none]</td> |
733 |
<td valign="top" colspan="3">If <code>-proc:only</code> is specified, the annotation processors will run but no compilation will be performed. If <code>-proc:none</code> is specified, annotation |
734 |
processors will not be discovered or run; compilation will proceed as if no annotation processors were found. By default the compiler must search the classpath for annotation processors, so |
735 |
specifying <code>-proc:none</code> may speed compilation if annotation processing is not required.</td> |
736 |
</tr> |
737 |
<tr> |
738 |
|
739 |
<td>-processor <class1[,class2,...]></td> |
740 |
<td valign="top" colspan="3">Qualified class names of annotation processors to run. If specified, the normal <a href= |
741 |
"http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Processor.html">processor discovery process</a> will be skipped.</td> |
742 |
</tr> |
743 |
<tr> |
744 |
<td>-processorpath <dir 1>;<dir 2>;...;<dir P></td> |
745 |
|
746 |
<td valign="top" colspan="3">A list of directories or jar files which will be searched for annotation processors. Entries are separated by the platform path separator. If not specified, the classpath |
747 |
will be searched instead.</td> |
748 |
</tr> |
749 |
<tr> |
750 |
<td>-s <dir></td> |
751 |
<td valign="top" colspan="3">The directory where generated source files will be created.</td> |
752 |
</tr> |
753 |
<tr> |
754 |
<td>-XprintProcessorInfo</td> |
755 |
<td valign="top" colspan="3">Print information about which annotations and which elements a processor is asked to process</td> |
756 |
</tr> |
757 |
<tr> |
758 |
|
759 |
<td>-XprintRounds</td> |
760 |
<td valign="top" colspan="3">Print information about annotation processing rounds</td> |
761 |
</tr> |
762 |
<tr> |
763 |
<td>-classNames <class1[,class2,...]></td> |
764 |
<td valign="top" colspan="3">Qualified names of binary types that need to be processed</td> |
765 |
</tr> |
766 |
<tr> |
767 |
<th colspan="4">Ignored options (for compatibility with javac options)</th> |
768 |
</tr> |
769 |
<tr> |
770 |
|
771 |
<td>-J<option></td> |
772 |
<td valign="top" colspan="3">Pass option to the virtual machine</td> |
773 |
</tr> |
774 |
<tr> |
775 |
<td>-X<option></td> |
776 |
<td valign="top" colspan="3">Specify non-standard option. -Xemacs is not ignored.</td> |
777 |
</tr> |
778 |
<tr> |
779 |
<td>-X</td> |
780 |
<td valign="top" colspan="3">Print non-standard options and exit</td> |
781 |
|
782 |
</tr> |
783 |
<tr> |
784 |
<td>-O</td> |
785 |
<td valign="top" colspan="3">Optimize for execution time</td> |
786 |
</tr> |
787 |
<tr> |
788 |
<th colspan="4">Advanced options</th> |
789 |
</tr> |
790 |
<tr> |
791 |
<td>@<file></td> |
792 |
<td valign="top" colspan="3">Read command-line arguments from file</td> |
793 |
|
794 |
</tr> |
795 |
<tr> |
796 |
<td>-maxProblems <n></td> |
797 |
<td valign="top" colspan="3">Max number of problems per compilation unit (100 by default)</td> |
798 |
</tr> |
799 |
<tr> |
800 |
<td valign="top">-log <filename></td> |
801 |
<td colspan="3">Specify a log file in which all output from the compiler will be dumped. This is really useful if you want to debug the batch compiler or get a file which contains all errors and |
802 |
warnings from a batch build. If the extension is <b>.xml</b>, the generated log will be an xml file.</td> |
803 |
</tr> |
804 |
|
805 |
<tr> |
806 |
<td valign="top">-Xemacs</td> |
807 |
<td colspan="3">Use emacs style to present errors and warnings locations into the console and regular text logs. XML logs are unaffected by this option. With this option active, the message:<br /> |
808 |
<code><span class="c3">2. WARNING in /workspace/X.java<br /> |
809 |
(at line 8)...</span></code><br /> |
810 |
is presented as:<br /> |
811 |
<code><span class="c3">/workspace/X.java:8: warning: The method...</span></code></td> |
812 |
</tr> |
813 |
<tr> |
814 |
<td valign="top">-proceedOnError[:Fatal]</td> |
815 |
|
816 |
<td colspan="3">Keep compiling in spite of errors, dumping class files with problem methods or problem types. This is recommended only if you want to be able to run your application even if you have |
817 |
remaining errors.<br /> |
818 |
With ":Fatal", all optional errors are treated as fatal and this leads to code that will abort if an error is reached at runtime. Without ":Fatal", optional errors don't prevent the proper code |
819 |
generation and the produced .class files can be run without a problem.</td> |
820 |
</tr> |
821 |
<tr> |
822 |
<td valign="top">-verbose</td> |
823 |
<td colspan="3">Print accessed/processed compilation units in the console or the log file if specified.</td> |
824 |
</tr> |
825 |
<tr> |
826 |
<td valign="top">-referenceInfo</td> |
827 |
<td colspan="3">Compute reference info. This is useful only if connected to the builder. The reference infos are useless otherwise.</td> |
828 |
</tr> |
829 |
|
830 |
<tr> |
831 |
<td valign="top">-progress</td> |
832 |
<td colspan="3">Show progress (only in -log mode).</td> |
833 |
</tr> |
834 |
<tr> |
835 |
<td valign="top">-time</td> |
836 |
<td colspan="3">Display speed information.</td> |
837 |
</tr> |
838 |
<tr> |
839 |
<td valign="top">-noExit</td> |
840 |
<td colspan="3">Do not call <span class="c3">System.exit(n)</span> at end of compilation (<span class="c3">n=0</span> if no error).</td> |
841 |
|
842 |
</tr> |
843 |
<tr> |
844 |
<td valign="top">-repeat <n></td> |
845 |
<td colspan="3">Repeat compilation process <span class="c3"><n></span> times (perf analysis).</td> |
846 |
</tr> |
847 |
<tr> |
848 |
<td valign="top">-inlineJSR</td> |
849 |
<td colspan="3">Inline JSR bytecode (implicit if target >= 1.5).</td> |
850 |
|
851 |
</tr> |
852 |
<tr> |
853 |
<td valign="top">-enableJavadoc</td> |
854 |
<td colspan="3">Consider references inside javadoc.</td> |
855 |
</tr> |
856 |
<tr> |
857 |
<th colspan="4">Helping options</th> |
858 |
</tr> |
859 |
<tr> |
860 |
<td>-? -help</td> |
861 |
<td valign="top" colspan="3">Display the help message.</td> |
862 |
</tr> |
863 |
|
864 |
<tr> |
865 |
<td valign="top">-v -version</td> |
866 |
<td colspan="3">Display the build number of the compiler. This is very useful to report a bug.</td> |
867 |
</tr> |
868 |
<tr> |
869 |
<td valign="top">-showversion</td> |
870 |
<td colspan="3">Display the build number of the compiler and continue. This is very useful to report a bug.</td> |
871 |
</tr> |
872 |
</table> |
873 |
<h4>Examples</h4> |
874 |
<table> |
875 |
<tr> |
876 |
|
877 |
<td valign="top"><code><span class="c3">d:\temp -classpath rt.jar -time -g -d d:/tmp</span></code></td> |
878 |
<td valign="top">It compiles all source files in d:\temp and its subfolders. The classpath is simply rt.jar. It generates all debug attributes and all generated .class files are dumped in d:\tmp. The |
879 |
speed of the compiler will be displayed once the batch process is completed.</td> |
880 |
</tr> |
881 |
<tr> |
882 |
<td valign="top"><code><span class="c3">d:\temp\Test.java -classpath d:\temp;rt.jar -g:none</span></code></td> |
883 |
<td valign="top">It compiles only Test.java and its dependant files if any, retrieving dependant files from d:\temp. The classpath is d:\temp followed by rt.jar, which means that all necessary |
884 |
classes are searched first in d:\temp and then in rt.jar. It generates no debug attributes and all generated .class files are dumped in d:\temp.</td> |
885 |
</tr> |
886 |
</table> |
887 |
<h3>Using the ant javac adapter</h3> |
888 |
<p>The Eclipse compiler can be used inside an Ant buildfile using the javac adapter. In order to use the Eclipse compiler, you simply need to define the <b>build.compiler</b> property in your |
889 |
buildfile.</p> |
890 |
|
891 |
<p>In order to get the batch compiler working in an ant buildfile, the ant runtime classpath needs to contain the Eclipse batch compiler. When you run your ant buildfile:</p> |
892 |
<ol> |
893 |
<li>outside of Eclipse: the easiest way to set up the ant runtime classpath is to add the <code>ecj.jar</code> file using the <code>-lib</code> argument or dumping it inside the <code>ANT_HOME</code> |
894 |
location.</li> |
895 |
<li>inside Eclipse using the same JRE than Eclipse: the Eclipse batch compiler is implicitly added to the ant runtime classpath.</li> |
896 |
<li>inside Eclipse using the different JRE: the Eclipse batch compiler must be explicitly added to the ant runtime classpath. This can be done using the <code>ecj.jar</code> file or using the |
897 |
org.eclipse.jdt.core jar file and the <code>jdtCompilerAdapter.jar</code> file located inside the org.eclipse.jdt.core jar file (this jar file needs to be extracted first).</li> |
898 |
|
899 |
</ol> |
900 |
<p>Here is a small example:</p> |
901 |
<pre> |
902 |
<span class="c2"> |
903 |
<?xml version="1.0" encoding="UTF-8"?> |
904 |
<project name="compile" default="main" basedir="../."> |
905 |
|
906 |
<b><property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/></b> |
907 |
|
908 |
<property name="root" value="${basedir}/src"/> |
909 |
|
910 |
<property name="destdir" value="d:/temp/bin" /> |
911 |
|
912 |
<target name="main"> |
913 |
<javac srcdir="${root}" destdir="${destdir}" debug="on" nowarn="on" extdirs="d:/extdirs" source="1.4"> |
914 |
<classpath> |
915 |
<pathelement location="${basedir}/../org.eclipse.jdt.core/bin"/> |
916 |
|
917 |
</classpath> |
918 |
</javac> |
919 |
</target> |
920 |
</project> |
921 |
</span> |
922 |
</pre> |
923 |
<p>The syntax used for the javac Ant task can be found in the <a href="http://ant.apache.org/manual/Tasks/javac.html">Ant javac task documentation</a>. The current adapter supports the Javac Ant task |
924 |
1.4.1 up to 1.6.5 versions.</p> |
925 |
|
926 |
<p>If you are using a version above 1.5.0, you can use the nested compiler argument element (<code><compilerarg></code>) to specify compiler specific options.</p> |
927 |
<pre> |
928 |
<span class="c2"> |
929 |
... |
930 |
<javac srcdir="${root}" destdir="${destdir}" debug="on" nowarn="on" extdirs="d:/extdirs" source="1.4"> |
931 |
<classpath> |
932 |
<pathelement location="${basedir}/../org.eclipse.jdt.core/bin"/> |
933 |
</classpath> |
934 |
|
935 |
<compilerarg</span> <span class="c6">compiler="org.eclipse.jdt.core.JDTCompilerAdapter"</span> <span class="c2">line="-1.5 -warn:+boxing"/> |
936 |
</javac> |
937 |
... |
938 |
</span> |
939 |
</pre> |
940 |
<b>Note:</b> |
941 |
<ol> |
942 |
<li>To prevent compiler dependant buildfiles, we <em>strongly</em> advise you to use a <code><compilerarg></code> whose "compiler" attribute value is |
943 |
|
944 |
<code>org.eclipse.jdt.core.JDTCompilerAdapter</code>. If this is not set, the buildfile can only be used with the Eclipse compiler. If set, the nested compiler argument is ignored if the name is |
945 |
different from the compiler name specified by the <code>build.compiler</code> property.</li> |
946 |
<li><code><compilerarg></code> should not be used to set values like target value, source value, debug options, or any options that could be set using the defined attributes of the |
947 |
<code>javac</code> ant task. Its usage must be reserved to pass compiler specific options like warning options. When a command-line argument is specified more than once, the Eclipse batch compiler |
948 |
can report errors like: |
949 |
<pre> |
950 |
duplicate target compliance setting specification: 1.5 |
951 |
</pre></li> |
952 |
</ol> |
953 |
<h3>Problem determination</h3> |
61 |
<h3>Problem determination</h3> |
954 |
|
62 |
|
955 |
<p>JDT Core defines a specialized marker (marker type "<b>org.eclipse.jdt.core.problem</b> ") to denote compilation problems. To programmatically discover problems detected by the compiler, the |
63 |
<p>JDT Core defines a specialized marker (marker type "<b>org.eclipse.jdt.core.problem</b> ") to denote compilation problems. To programmatically discover problems detected by the compiler, the |
Lines 1000-1044
Link Here
|
1000 |
</pre> |
108 |
</pre> |
1001 |
<p>You can add an action on the reported problems in the acceptProblem(IProblem) method. In this example, the reported problem will be that <b>Zork cannot be resolved or is not a valid superclass</b> |
109 |
<p>You can add an action on the reported problems in the acceptProblem(IProblem) method. In this example, the reported problem will be that <b>Zork cannot be resolved or is not a valid superclass</b> |
1002 |
and its id is <b>IProblem.SuperclassNotFound</b>.</p> |
110 |
and its id is <b>IProblem.SuperclassNotFound</b>.</p> |
1003 |
<h3>Excluding warnings using <code>SuppressWarnings</code></h3> |
|
|
1004 |
<p>Java 5.0 offers the option to the user to disable compilation warnings relative to a subset of a compilation unit using the annotation <code>java.lang.SuppressWarning</code>.</p> |
1005 |
|
1006 |
<pre> |
1007 |
@SuppressWarning("unused") public void foo() { |
1008 |
String s; |
1009 |
} |
1010 |
</pre> |
1011 |
<p>Without the annotation, the compiler would complain that the local variable <code>s</code> is never used. With the annotation, the compiler silently ignores this warning locally to the |
1012 |
<code>foo</code> method. This enables to keep the warnings in other locations of the same compilation unit or the same project.</p> |
1013 |
<p>The list of tokens that can be used inside a <code>SuppressWarnings</code> annotation is:</p> |
1014 |
|
1015 |
<ul> |
1016 |
<li><span class="c7">all</span> to suppress all warnings</li> |
1017 |
<li><span class="c7">boxing</span> to suppress warnings relative to boxing/unboxing operations</li> |
1018 |
<li><span class="c7">cast</span> to suppress warnings relative to cast operations</li> |
1019 |
<li><span class="c7">dep-ann</span> to suppress warnings relative to deprecated annotation</li> |
1020 |
|
1021 |
<li><span class="c7">deprecation</span> to suppress warnings relative to deprecation</li> |
1022 |
<li><span class="c7">fallthrough</span> to suppress warnings relative to missing breaks in switch statements</li> |
1023 |
<li><span class="c7">finally</span> to suppress warnings relative to finally block that don't return</li> |
1024 |
<li><span class="c7">hiding</span> to suppress warnings relative to locals that hide variable</li> |
1025 |
<li><span class="c7">incomplete-switch</span> to suppress warnings relative to missing entries in a switch statement (enum case)</li> |
1026 |
|
1027 |
<li><span class="c7">javadoc</span> to suppress warnings relative to javadoc warnings</li> |
1028 |
<li><span class="c7">nls</span> to suppress warnings relative to non-nls string literals</li> |
1029 |
<li><span class="c7">null</span> to suppress warnings relative to null analysis</li> |
1030 |
<li><span class="c7">rawtypes</span> to suppress warnings relative to usage of raw types</li> |
1031 |
<li><span class="c7">restriction</span> to suppress warnings relative to usage of discouraged or forbidden references</li> |
1032 |
|
1033 |
<li><span class="c7">serial</span> to suppress warnings relative to missing serialVersionUID field for a serializable class</li> |
1034 |
<li><span class="c7">static-access</span> to suppress warnings relative to incorrect static access</li> |
1035 |
<li><span class="c7">static-method</span> to suppress warnings relative to methods that could be declared as static</li> |
1036 |
<li><span class="c7">super</span> to suppress warnings relative to overriding a method without super invocations</li> |
1037 |
<li><span class="c7">synthetic-access</span> to suppress warnings relative to unoptimized access from inner classes</li> |
1038 |
|
1039 |
<li><span class="c7">unchecked</span> to suppress warnings relative to unchecked operations</li> |
1040 |
<li><span class="c7">unqualified-field-access</span> to suppress warnings relative to field access unqualified</li> |
1041 |
<li><span class="c7">unused</span> to suppress warnings relative to unused code and dead code</li> |
1042 |
</ul> |
1043 |
</body> |
111 |
</body> |
1044 |
</html> |
112 |
</html> |