Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2012 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 47-53
Link Here
|
47 |
// Static initializer to specify tests subset using TESTS_* static variables |
47 |
// Static initializer to specify tests subset using TESTS_* static variables |
48 |
// All specified tests which do not belong to the class are skipped... |
48 |
// All specified tests which do not belong to the class are skipped... |
49 |
static { |
49 |
static { |
50 |
// TESTS_NAMES = new String[] { "test293" }; |
50 |
// TESTS_NAMES = new String[] { "testBug365437" }; |
51 |
// TESTS_NUMBERS = new int[] { 297 }; |
51 |
// TESTS_NUMBERS = new int[] { 297 }; |
52 |
// TESTS_RANGE = new int[] { 294, -1 }; |
52 |
// TESTS_RANGE = new int[] { 294, -1 }; |
53 |
} |
53 |
} |
Lines 10148-10151
Link Here
|
10148 |
"Bla cannot be resolved to a type\n" + |
10148 |
"Bla cannot be resolved to a type\n" + |
10149 |
"----------\n"); |
10149 |
"----------\n"); |
10150 |
} |
10150 |
} |
|
|
10151 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 |
10152 |
public void testBug365437a() { |
10153 |
Map customOptions = getCompilerOptions(); |
10154 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10155 |
String testFiles [] = new String[] { |
10156 |
"p/A.java", |
10157 |
"package p;\n" + |
10158 |
"import p1.*;\n" + |
10159 |
"public class A {\n" + |
10160 |
" @p1.PreDestroy\n" + |
10161 |
" private void foo1(){}\n" + |
10162 |
" @PreDestroy\n" + |
10163 |
" private void foo2(){}\n" + |
10164 |
" @SuppressWarnings(\"null\")\n" + |
10165 |
" @PostConstruct\n" + |
10166 |
" private void foo1a(){}\n" + |
10167 |
" @PostConstruct\n" + |
10168 |
" private void foo2a(){}\n" + |
10169 |
" @Deprecated" + |
10170 |
" private void foo3(){}" + |
10171 |
"}\n", |
10172 |
"p1/PreDestroy.java", |
10173 |
"package p1;\n" + |
10174 |
"public @interface PreDestroy{}", |
10175 |
"p1/PostConstruct.java", |
10176 |
"package p1;\n" + |
10177 |
"public @interface PostConstruct{}" |
10178 |
}; |
10179 |
String expectedErrorString = |
10180 |
"----------\n" + |
10181 |
"1. WARNING in p\\A.java (at line 8)\n" + |
10182 |
" @SuppressWarnings(\"null\")\n" + |
10183 |
" ^^^^^^\n" + |
10184 |
"Unnecessary @SuppressWarnings(\"null\")\n" + |
10185 |
"----------\n" + |
10186 |
"2. ERROR in p\\A.java (at line 13)\n" + |
10187 |
" @Deprecated private void foo3(){}}\n" + |
10188 |
" ^^^^^^\n" + |
10189 |
"The method foo3() from the type A is never used locally\n" + |
10190 |
"----------\n"; |
10191 |
runNegativeTest( |
10192 |
true, |
10193 |
testFiles, |
10194 |
null, |
10195 |
customOptions, |
10196 |
expectedErrorString, |
10197 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
10198 |
} |
10199 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 |
10200 |
public void testBug365437b() { |
10201 |
Map customOptions = getCompilerOptions(); |
10202 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10203 |
customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); |
10204 |
customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); |
10205 |
String testFiles [] = new String[] { |
10206 |
"A.java", |
10207 |
"import javax.annotation.*;\n" + |
10208 |
"public class A {\n" + |
10209 |
" @javax.annotation.PreDestroy\n" + |
10210 |
" private void foo1(){}\n" + |
10211 |
" @PreDestroy\n" + |
10212 |
" private void foo2(){}\n" + |
10213 |
" @javax.annotation.Resource\n" + |
10214 |
" private void foo1a(){}\n" + |
10215 |
" @Resource\n" + |
10216 |
" @p.NonNull\n" + |
10217 |
" private Object foo2a(){ return new Object();}\n" + |
10218 |
" @javax.annotation.PostConstruct\n" + |
10219 |
" @Deprecated\n" + |
10220 |
" private void foo3(){}\n" + |
10221 |
" @p.NonNull\n" + |
10222 |
" private Object foo3a(){ return new Object();}\n" + |
10223 |
"}\n", |
10224 |
"p/NonNull.java", |
10225 |
"package p;\n" + |
10226 |
"import static java.lang.annotation.ElementType.*;\n" + |
10227 |
"import java.lang.annotation.*;\n" + |
10228 |
"@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE})\n" + |
10229 |
"public @interface NonNull {\n" + |
10230 |
"}" |
10231 |
}; |
10232 |
String expectedErrorString = |
10233 |
"----------\n" + |
10234 |
"1. ERROR in A.java (at line 16)\n" + |
10235 |
" private Object foo3a(){ return new Object();}\n" + |
10236 |
" ^^^^^^^\n" + |
10237 |
"The method foo3a() from the type A is never used locally\n" + |
10238 |
"----------\n"; |
10239 |
runNegativeTest( |
10240 |
true, |
10241 |
testFiles, |
10242 |
null, |
10243 |
customOptions, |
10244 |
expectedErrorString, |
10245 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
10246 |
} |
10247 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 |
10248 |
// @SafeVarargs |
10249 |
public void testBug365437c() { |
10250 |
if (this.complianceLevel < ClassFileConstants.JDK1_7) return; |
10251 |
Map customOptions = getCompilerOptions(); |
10252 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10253 |
String testFiles [] = new String[] { |
10254 |
"p/A.java", |
10255 |
"package p;\n" + |
10256 |
"import p1.*;\n" + |
10257 |
"public class A {\n" + |
10258 |
" @p1.PreDestroy\n" + |
10259 |
" private void foo1(){}\n" + |
10260 |
" @PreDestroy\n" + |
10261 |
" private void foo2(){}\n" + |
10262 |
" @SuppressWarnings(\"null\")\n" + |
10263 |
" @PostConstruct\n" + |
10264 |
" private void foo1a(){}\n" + |
10265 |
" @PostConstruct\n" + |
10266 |
" private void foo2a(){}\n" + |
10267 |
" @SafeVarargs" + |
10268 |
" private final void foo3(Object... o){}" + |
10269 |
"}\n", |
10270 |
"p1/PreDestroy.java", |
10271 |
"package p1;\n" + |
10272 |
"public @interface PreDestroy{}", |
10273 |
"p1/PostConstruct.java", |
10274 |
"package p1;\n" + |
10275 |
"public @interface PostConstruct{}" |
10276 |
}; |
10277 |
String expectedErrorString = |
10278 |
"----------\n" + |
10279 |
"1. WARNING in p\\A.java (at line 8)\n" + |
10280 |
" @SuppressWarnings(\"null\")\n" + |
10281 |
" ^^^^^^\n" + |
10282 |
"Unnecessary @SuppressWarnings(\"null\")\n" + |
10283 |
"----------\n" + |
10284 |
"2. ERROR in p\\A.java (at line 13)\n" + |
10285 |
" @SafeVarargs private final void foo3(Object... o){}}\n" + |
10286 |
" ^^^^^^^^^^^^^^^^^\n" + |
10287 |
"The method foo3(Object...) from the type A is never used locally\n" + |
10288 |
"----------\n"; |
10289 |
runNegativeTest( |
10290 |
true, |
10291 |
testFiles, |
10292 |
null, |
10293 |
customOptions, |
10294 |
expectedErrorString, |
10295 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
10296 |
} |
10297 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 |
10298 |
// unused constructor |
10299 |
public void testBug365437d() { |
10300 |
Map customOptions = getCompilerOptions(); |
10301 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10302 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10303 |
customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); |
10304 |
customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); |
10305 |
this.runNegativeTest( |
10306 |
true, |
10307 |
new String[] { |
10308 |
"Example.java", |
10309 |
"class Example {\n" + |
10310 |
" @p.Annot\n" + |
10311 |
" private Example() {\n" + |
10312 |
" }\n" + |
10313 |
" public Example(int i) {\n" + |
10314 |
" }\n" + |
10315 |
"}\n" + |
10316 |
"class E1 {\n" + |
10317 |
" @Deprecated\n" + |
10318 |
" private E1() {}\n" + |
10319 |
" public E1(long l) {}\n" + |
10320 |
"}\n" + |
10321 |
"class E2 {\n" + |
10322 |
" @SuppressWarnings(\"null\")\n" + |
10323 |
" private E2() {}\n" + |
10324 |
" public E2(long l) {}\n" + |
10325 |
"}\n" + |
10326 |
"class E3 {\n" + |
10327 |
" @p.NonNull\n" + |
10328 |
" private E3() {}\n" + |
10329 |
" public E3(long l) {}\n" + |
10330 |
"}\n" + |
10331 |
"class E4 {\n" + |
10332 |
" @Deprecated\n" + |
10333 |
" @p.Annot\n" + |
10334 |
" private E4() {}\n" + |
10335 |
" public E4(long l) {}\n" + |
10336 |
"}\n", |
10337 |
"p/NonNull.java", |
10338 |
"package p;\n" + |
10339 |
"import static java.lang.annotation.ElementType.*;\n" + |
10340 |
"import java.lang.annotation.*;\n" + |
10341 |
"@Target({TYPE, METHOD,PARAMETER,CONSTRUCTOR})\n" + |
10342 |
"public @interface NonNull {\n" + |
10343 |
"}", |
10344 |
"p/Annot.java", |
10345 |
"package p;\n" + |
10346 |
"import static java.lang.annotation.ElementType.*;\n" + |
10347 |
"import java.lang.annotation.*;\n" + |
10348 |
"@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, CONSTRUCTOR})\n" + |
10349 |
"public @interface Annot {\n" + |
10350 |
"}" |
10351 |
}, |
10352 |
null, customOptions, |
10353 |
"----------\n" + |
10354 |
"1. ERROR in Example.java (at line 10)\n" + |
10355 |
" private E1() {}\n" + |
10356 |
" ^^^^\n" + |
10357 |
"The constructor E1() is never used locally\n" + |
10358 |
"----------\n" + |
10359 |
"2. WARNING in Example.java (at line 14)\n" + |
10360 |
" @SuppressWarnings(\"null\")\n" + |
10361 |
" ^^^^^^\n" + |
10362 |
"Unnecessary @SuppressWarnings(\"null\")\n" + |
10363 |
"----------\n" + |
10364 |
"3. ERROR in Example.java (at line 15)\n" + |
10365 |
" private E2() {}\n" + |
10366 |
" ^^^^\n" + |
10367 |
"The constructor E2() is never used locally\n" + |
10368 |
"----------\n" + |
10369 |
"4. ERROR in Example.java (at line 20)\n" + |
10370 |
" private E3() {}\n" + |
10371 |
" ^^^^\n" + |
10372 |
"The constructor E3() is never used locally\n" + |
10373 |
"----------\n", |
10374 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
10375 |
} |
10376 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 |
10377 |
// unused field |
10378 |
public void testBug365437e() { |
10379 |
Map customOptions = getCompilerOptions(); |
10380 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10381 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10382 |
customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); |
10383 |
customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); |
10384 |
this.runNegativeTest( |
10385 |
true, |
10386 |
new String[] { |
10387 |
"Example.java", |
10388 |
"class Example {\n" + |
10389 |
" @p.Annot\n" + |
10390 |
" private int Ex;\n" + |
10391 |
"}\n" + |
10392 |
"class E1 {\n" + |
10393 |
" @Deprecated\n" + |
10394 |
" private int E1;\n" + |
10395 |
"}\n" + |
10396 |
"class E2 {\n" + |
10397 |
" @SuppressWarnings(\"null\")\n" + |
10398 |
" private int E2;\n" + |
10399 |
"}\n" + |
10400 |
"class E3 {\n" + |
10401 |
" @p.NonNull\n" + |
10402 |
" private int E3;\n" + |
10403 |
"}\n" + |
10404 |
"class E4 {\n" + |
10405 |
" @Deprecated\n" + |
10406 |
" @p.Annot\n" + |
10407 |
" private int E4;\n" + |
10408 |
"}\n", |
10409 |
"p/NonNull.java", |
10410 |
"package p;\n" + |
10411 |
"import static java.lang.annotation.ElementType.*;\n" + |
10412 |
"import java.lang.annotation.*;\n" + |
10413 |
"@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, FIELD})\n" + |
10414 |
"public @interface NonNull {\n" + |
10415 |
"}", |
10416 |
"p/Annot.java", |
10417 |
"package p;\n" + |
10418 |
"import static java.lang.annotation.ElementType.*;\n" + |
10419 |
"import java.lang.annotation.*;\n" + |
10420 |
"@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, FIELD})\n" + |
10421 |
"public @interface Annot {\n" + |
10422 |
"}" |
10423 |
}, |
10424 |
null, customOptions, |
10425 |
"----------\n" + |
10426 |
"1. ERROR in Example.java (at line 7)\n" + |
10427 |
" private int E1;\n" + |
10428 |
" ^^\n" + |
10429 |
"The value of the field E1.E1 is not used\n" + |
10430 |
"----------\n" + |
10431 |
"2. WARNING in Example.java (at line 10)\n" + |
10432 |
" @SuppressWarnings(\"null\")\n" + |
10433 |
" ^^^^^^\n" + |
10434 |
"Unnecessary @SuppressWarnings(\"null\")\n" + |
10435 |
"----------\n" + |
10436 |
"3. ERROR in Example.java (at line 11)\n" + |
10437 |
" private int E2;\n" + |
10438 |
" ^^\n" + |
10439 |
"The value of the field E2.E2 is not used\n" + |
10440 |
"----------\n" + |
10441 |
"4. ERROR in Example.java (at line 15)\n" + |
10442 |
" private int E3;\n" + |
10443 |
" ^^\n" + |
10444 |
"The value of the field E3.E3 is not used\n" + |
10445 |
"----------\n", |
10446 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
10447 |
} |
10448 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 |
10449 |
// unused type |
10450 |
public void testBug365437f() { |
10451 |
Map customOptions = getCompilerOptions(); |
10452 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10453 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); |
10454 |
customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); |
10455 |
customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); |
10456 |
this.runNegativeTest( |
10457 |
true, |
10458 |
new String[] { |
10459 |
"Example.java", |
10460 |
"class Example {\n" + |
10461 |
" @p.Annot\n" + |
10462 |
" private class Ex{}\n" + |
10463 |
"}\n" + |
10464 |
"class E1 {\n" + |
10465 |
" @Deprecated\n" + |
10466 |
" private class E11{}\n" + |
10467 |
"}\n" + |
10468 |
"class E2 {\n" + |
10469 |
" @SuppressWarnings(\"null\")\n" + |
10470 |
" private class E22{}\n" + |
10471 |
"}\n" + |
10472 |
"class E3 {\n" + |
10473 |
" @p.NonNull\n" + |
10474 |
" private class E33{}\n" + |
10475 |
"}\n" + |
10476 |
"class E4 {\n" + |
10477 |
" @Deprecated\n" + |
10478 |
" @p.Annot\n" + |
10479 |
" private class E44{}\n" + |
10480 |
"}\n", |
10481 |
"p/NonNull.java", |
10482 |
"package p;\n" + |
10483 |
"import static java.lang.annotation.ElementType.*;\n" + |
10484 |
"import java.lang.annotation.*;\n" + |
10485 |
"@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE})\n" + |
10486 |
"public @interface NonNull {\n" + |
10487 |
"}", |
10488 |
"p/Annot.java", |
10489 |
"package p;\n" + |
10490 |
"import static java.lang.annotation.ElementType.*;\n" + |
10491 |
"import java.lang.annotation.*;\n" + |
10492 |
"@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, CONSTRUCTOR})\n" + |
10493 |
"public @interface Annot {\n" + |
10494 |
"}" |
10495 |
}, |
10496 |
null, customOptions, |
10497 |
"----------\n" + |
10498 |
"1. ERROR in Example.java (at line 7)\n" + |
10499 |
" private class E11{}\n" + |
10500 |
" ^^^\n" + |
10501 |
"The type E1.E11 is never used locally\n" + |
10502 |
"----------\n" + |
10503 |
"2. WARNING in Example.java (at line 10)\n" + |
10504 |
" @SuppressWarnings(\"null\")\n" + |
10505 |
" ^^^^^^\n" + |
10506 |
"Unnecessary @SuppressWarnings(\"null\")\n" + |
10507 |
"----------\n" + |
10508 |
"3. ERROR in Example.java (at line 11)\n" + |
10509 |
" private class E22{}\n" + |
10510 |
" ^^^\n" + |
10511 |
"The type E2.E22 is never used locally\n" + |
10512 |
"----------\n" + |
10513 |
"4. ERROR in Example.java (at line 15)\n" + |
10514 |
" private class E33{}\n" + |
10515 |
" ^^^\n" + |
10516 |
"The type E3.E33 is never used locally\n" + |
10517 |
"----------\n", |
10518 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
10519 |
} |
10151 |
} |
10520 |
} |