Lines 160-165
Link Here
|
160 |
null, true, options); |
160 |
null, true, options); |
161 |
} |
161 |
} |
162 |
|
162 |
|
|
|
163 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
164 |
// [compiler] warning on fall through |
165 |
// basic scenario |
166 |
public void test006() { |
167 |
Map options = getCompilerOptions(); |
168 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
169 |
this.runNegativeTest( |
170 |
new String[] { |
171 |
"X.java", |
172 |
"public class X {\n" + |
173 |
" public void test(int p) {\n" + |
174 |
" switch (p) {\n" + |
175 |
" case 0:\n" + |
176 |
" System.out.println(0); // silent because first case\n" + |
177 |
" case 1:\n" + |
178 |
" System.out.println(1); // complain: possible fall-through\n" + |
179 |
" break;\n" + |
180 |
" case 2:\n" + |
181 |
" System.out.println(3); // silent because of break\n" + |
182 |
" return;\n" + |
183 |
" case 3: // silent because of return\n" + |
184 |
" case 4: // silent because grouped cases\n" + |
185 |
" default:\n" + |
186 |
" System.out.println(\"default\"); //$NON-NLS-1$\n" + |
187 |
" }\n" + |
188 |
" }\n" + |
189 |
"}" |
190 |
}, |
191 |
"----------\n" + |
192 |
"1. ERROR in X.java (at line 6)\n" + |
193 |
" case 1:\n" + |
194 |
" ^^^^^^\n" + |
195 |
"Possible fall-through case\n" + |
196 |
"----------\n", |
197 |
null, true, options); |
198 |
} |
199 |
|
200 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
201 |
// [compiler] warning on fall through |
202 |
// SuppressWarnings effect - explicit fall-through token |
203 |
public void test007() { |
204 |
if (COMPLIANCE_1_5.equals(this.complianceLevel)) { |
205 |
Map options = getCompilerOptions(); |
206 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.WARNING); |
207 |
this.runNegativeTest( |
208 |
new String[] { |
209 |
"X.java", |
210 |
"public class X {\n" + |
211 |
" @SuppressWarnings(\"fall-through\")\n" + |
212 |
" public void test(int p) {\n" + |
213 |
" switch (p) {\n" + |
214 |
" case 0:\n" + |
215 |
" System.out.println(0); // silent because first case\n" + |
216 |
" case 1:\n" + |
217 |
" System.out.println(1); // silent because of SuppressWarnings\n" + |
218 |
" }\n" + |
219 |
" }\n" + |
220 |
" Zork z;\n" + // complain on Zork (unknown type) |
221 |
"}" |
222 |
}, |
223 |
"----------\n" + |
224 |
"1. ERROR in X.java (at line 11)\n" + |
225 |
" Zork z;\n" + |
226 |
" ^^^^\n" + |
227 |
"Zork cannot be resolved to a type\n" + |
228 |
"----------\n", |
229 |
null, true, options); |
230 |
} |
231 |
} |
232 |
|
233 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
234 |
// [compiler] warning on fall through |
235 |
// deep return (1) |
236 |
public void test008() { |
237 |
Map options = getCompilerOptions(); |
238 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
239 |
this.runConformTest( |
240 |
new String[] { |
241 |
"X.java", |
242 |
"public class X {\n" + |
243 |
" public void test(int p) {\n" + |
244 |
" switch (p) {\n" + |
245 |
" case 0:\n" + |
246 |
" System.out.println(0);\n" + |
247 |
" if (true) {\n" + |
248 |
" return;\n" + |
249 |
" }\n" + |
250 |
" case 1:\n" + |
251 |
" System.out.println(1);\n" + |
252 |
" }\n" + |
253 |
" }\n" + |
254 |
"}" |
255 |
}, |
256 |
"", |
257 |
null, true, null, options, null); |
258 |
} |
259 |
|
260 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
261 |
// [compiler] warning on fall through |
262 |
// deep return (2) |
263 |
public void test009() { |
264 |
Map options = getCompilerOptions(); |
265 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
266 |
this.runConformTest( |
267 |
new String[] { |
268 |
"X.java", |
269 |
"public class X {\n" + |
270 |
" public void test(int p, boolean b) {\n" + |
271 |
" switch (p) {\n" + |
272 |
" case 0:\n" + |
273 |
" System.out.println(0);\n" + |
274 |
" if (b) {\n" + |
275 |
" return;\n" + |
276 |
" }\n" + |
277 |
" else {\n" + |
278 |
" return;\n" + |
279 |
" }\n" + |
280 |
" case 1:\n" + |
281 |
" System.out.println(1);\n" + |
282 |
" }\n" + |
283 |
" }\n" + |
284 |
"}" |
285 |
}, |
286 |
"", |
287 |
null, true, null, options, null); |
288 |
} |
289 |
|
290 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
291 |
// [compiler] warning on fall through |
292 |
// deep return (3), limit: cannot recognize that we won't return |
293 |
public void test010() { |
294 |
Map options = getCompilerOptions(); |
295 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
296 |
this.runNegativeTest( |
297 |
new String[] { |
298 |
"X.java", |
299 |
"public class X {\n" + |
300 |
" public void test(int p, boolean b) {\n" + |
301 |
" switch (p) {\n" + |
302 |
" case 0:\n" + |
303 |
" System.exit(0);\n" + |
304 |
" case 1:\n" + // complain |
305 |
" System.out.println(1);\n" + |
306 |
" }\n" + |
307 |
" }\n" + |
308 |
"}" |
309 |
}, |
310 |
"----------\n" + |
311 |
"1. ERROR in X.java (at line 6)\n" + |
312 |
" case 1:\n" + |
313 |
" ^^^^^^\n" + |
314 |
"Possible fall-through case\n" + |
315 |
"----------\n", |
316 |
null, true, options); |
317 |
} |
318 |
|
319 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
320 |
// [compiler] warning on fall through |
321 |
// SuppressWarnings effect - implicit, using all token |
322 |
public void test011() { |
323 |
if (COMPLIANCE_1_5.equals(this.complianceLevel)) { |
324 |
Map options = getCompilerOptions(); |
325 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.WARNING); |
326 |
this.runNegativeTest( |
327 |
new String[] { |
328 |
"X.java", |
329 |
"public class X {\n" + |
330 |
" @SuppressWarnings(\"all\")\n" + |
331 |
" public void test(int p) {\n" + |
332 |
" switch (p) {\n" + |
333 |
" case 0:\n" + |
334 |
" System.out.println(0); // silent because first case\n" + |
335 |
" case 1:\n" + |
336 |
" System.out.println(1); // silent because of SuppressWarnings\n" + |
337 |
" }\n" + |
338 |
" }\n" + |
339 |
" Zork z;\n" + // complain on Zork (unknown type) |
340 |
"}" |
341 |
}, |
342 |
"----------\n" + |
343 |
"1. ERROR in X.java (at line 11)\n" + |
344 |
" Zork z;\n" + |
345 |
" ^^^^\n" + |
346 |
"Zork cannot be resolved to a type\n" + |
347 |
"----------\n", |
348 |
null, true, options); |
349 |
} |
350 |
} |
351 |
|
352 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
353 |
// [compiler] warning on fall through |
354 |
// skip because of comment |
355 |
public void test012() { |
356 |
Map options = getCompilerOptions(); |
357 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
358 |
this.runConformTest( |
359 |
new String[] { |
360 |
"X.java", |
361 |
"public class X {\n" + |
362 |
" public void test(int p) {\n" + |
363 |
" switch (p) {\n" + |
364 |
" case 0:\n" + |
365 |
" System.out.println(0); // silent because first case\n" + |
366 |
" // on purpose fall-through\n" + |
367 |
" case 1:\n" + |
368 |
" System.out.println(1); // silent because of comment alone on its line above \n" + |
369 |
" }\n" + |
370 |
" }\n" + |
371 |
"}" |
372 |
}, |
373 |
"", |
374 |
null, true, null, options, null); |
375 |
} |
376 |
|
377 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
378 |
// [compiler] warning on fall through |
379 |
// skip because of comment - default label |
380 |
public void test013() { |
381 |
Map options = getCompilerOptions(); |
382 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
383 |
this.runConformTest( |
384 |
new String[] { |
385 |
"X.java", |
386 |
"public class X {\n" + |
387 |
" public void test(int p) {\n" + |
388 |
" switch (p) {\n" + |
389 |
" case 0:\n" + |
390 |
" System.out.println(0); // silent because first case\n" + |
391 |
" // on purpose fall-through\n" + |
392 |
" default:\n" + |
393 |
" System.out.println(1); // silent because of comment alone on its line above \n" + |
394 |
" }\n" + |
395 |
" }\n" + |
396 |
"}" |
397 |
}, |
398 |
"", |
399 |
null, true, null, options, null); |
400 |
} |
401 |
|
402 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
403 |
// [compiler] warning on fall through |
404 |
// basic scenario: default label |
405 |
public void test014() { |
406 |
Map options = getCompilerOptions(); |
407 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
408 |
this.runNegativeTest( |
409 |
new String[] { |
410 |
"X.java", |
411 |
"public class X {\n" + |
412 |
" public void test(int p) {\n" + |
413 |
" switch (p) {\n" + |
414 |
" case 0:\n" + |
415 |
" System.out.println(0); // silent because first case\n" + |
416 |
// note: the comment above is not alone on its line, hence it does not |
417 |
// protect against fall-through diagnostic |
418 |
" default:\n" + |
419 |
" System.out.println(1); // complain: possible fall-through\n" + |
420 |
" }\n" + |
421 |
" }\n" + |
422 |
"}" |
423 |
}, |
424 |
"----------\n" + |
425 |
"1. ERROR in X.java (at line 6)\n" + |
426 |
" default:\n" + |
427 |
" ^^^^^^^\n" + |
428 |
"Possible fall-through case\n" + |
429 |
"----------\n", |
430 |
null, true, options); |
431 |
} |
432 |
|
433 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
434 |
// [compiler] warning on fall through |
435 |
// skip because of comment - variants |
436 |
public void test015() { |
437 |
Map options = getCompilerOptions(); |
438 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
439 |
this.runNegativeTest( |
440 |
new String[] { |
441 |
"X.java", |
442 |
"public class X {\n" + |
443 |
" public void test(int p) {\n" + |
444 |
" switch (p) {\n" + |
445 |
" case 0:\n" + |
446 |
" System.out.println(0); // silent because first case\n" + |
447 |
" // on purpose fall-through\n" + |
448 |
"\n" + // extraneous line breaks fall-through protection |
449 |
" case 1:\n" + |
450 |
" System.out.println(1); // silent because of comment alone on its line above \n" + |
451 |
" }\n" + |
452 |
" }\n" + |
453 |
"}" |
454 |
}, |
455 |
"----------\n" + |
456 |
"1. ERROR in X.java (at line 8)\n" + |
457 |
" case 1:\n" + |
458 |
" ^^^^^^\n" + |
459 |
"Possible fall-through case\n" + |
460 |
"----------\n", |
461 |
null, true, options); |
462 |
} |
463 |
|
464 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
465 |
// [compiler] warning on fall through |
466 |
// skip because of comment - variants |
467 |
public void test016() { |
468 |
Map options = getCompilerOptions(); |
469 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
470 |
this.runNegativeTest( |
471 |
new String[] { |
472 |
"X.java", |
473 |
"public class X {\n" + |
474 |
" public void test(int p) {\n" + |
475 |
" switch (p) {\n" + |
476 |
" case 0:\n" + |
477 |
" System.out.println(0); // silent because first case\n" + |
478 |
" // on purpose fall-through\n" + |
479 |
" /* other comment */\n" + // non-single line comment breaks fall-through protection |
480 |
" case 1:\n" + |
481 |
" System.out.println(1); // silent because of comment alone on its line above \n" + |
482 |
" }\n" + |
483 |
" }\n" + |
484 |
"}" |
485 |
}, |
486 |
"----------\n" + |
487 |
"1. ERROR in X.java (at line 8)\n" + |
488 |
" case 1:\n" + |
489 |
" ^^^^^^\n" + |
490 |
"Possible fall-through case\n" + |
491 |
"----------\n", |
492 |
null, true, options); |
493 |
} |
494 |
|
495 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
496 |
// [compiler] warning on fall through |
497 |
// skip because of comment - variants |
498 |
public void test017() { |
499 |
Map options = getCompilerOptions(); |
500 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
501 |
this.runConformTest( |
502 |
new String[] { |
503 |
"X.java", |
504 |
"public class X {\n" + |
505 |
" public void test(int p) {\n" + |
506 |
" switch (p) {\n" + |
507 |
" case 0:\n" + |
508 |
" System.out.println(0);\n" + |
509 |
"// on purpose fall-through\n" + // very beginning of line |
510 |
" case 1:\n" + |
511 |
" System.out.println(1); // silent because of comment alone on its line above \n" + |
512 |
" }\n" + |
513 |
" }\n" + |
514 |
"}" |
515 |
}, |
516 |
"", |
517 |
null, true, null, options, null); |
518 |
} |
519 |
|
520 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 |
521 |
// [compiler] warning on fall through |
522 |
// skip because of comment - variants |
523 |
public void test018() { |
524 |
Map options = getCompilerOptions(); |
525 |
options.put(CompilerOptions.OPTION_ReportPossibleFallThroughCase, CompilerOptions.ERROR); |
526 |
this.runConformTest( |
527 |
new String[] { |
528 |
"X.java", |
529 |
"public class X {\n" + |
530 |
" public void test(int p) {\n" + |
531 |
" switch (p) {\n" + |
532 |
" case 0:\n" + |
533 |
" System.out.println(0);\n" + |
534 |
" //\n" + // empty line comment alone upon its line |
535 |
" case 1:\n" + |
536 |
" System.out.println(1); // silent because of comment alone on its line above \n" + |
537 |
" }\n" + |
538 |
" }\n" + |
539 |
"}" |
540 |
}, |
541 |
"", |
542 |
null, true, null, options, null); |
543 |
} |
544 |
|
163 |
public static Class testClass() { |
545 |
public static Class testClass() { |
164 |
return FlowAnalysisTest.class; |
546 |
return FlowAnalysisTest.class; |
165 |
} |
547 |
} |