View | Details | Raw Unified | Return to bug 197448 | Differences between
and this patch

Collapse All | Expand All

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

Return to bug 197448