|
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 7188-7191
Link Here
|
| 7188 |
// javac options |
7188 |
// javac options |
| 7189 |
JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); |
7189 |
JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); |
| 7190 |
} |
7190 |
} |
|
|
7191 |
|
| 7192 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7193 |
// SingleNameReference, assignment of instance field inside a local class method |
| 7194 |
public void test376550_1a() { |
| 7195 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7196 |
return; |
| 7197 |
Map compilerOptions = getCompilerOptions(); |
| 7198 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7199 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7200 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7201 |
this.runNegativeTest( |
| 7202 |
new String[] { |
| 7203 |
"X.java", |
| 7204 |
"public class X {\n" + |
| 7205 |
" int i = 1;\n" + |
| 7206 |
" public void upper1(){}\n" + |
| 7207 |
" public void foo(){\n" + // can't be static |
| 7208 |
" class Local{\n" + |
| 7209 |
" int i2 = 1;\n" + |
| 7210 |
" void method1() {\n" + // can't be static |
| 7211 |
" i = 1;\n" + |
| 7212 |
" }\n" + |
| 7213 |
" }\n" + |
| 7214 |
" }\n" + |
| 7215 |
"}" |
| 7216 |
}, |
| 7217 |
"", |
| 7218 |
null /* no extra class libraries */, |
| 7219 |
true /* flush output directory */, |
| 7220 |
compilerOptions /* custom options */ |
| 7221 |
); |
| 7222 |
} |
| 7223 |
|
| 7224 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7225 |
// SingleNameReference, assignment of instance field of local class inside a local class method |
| 7226 |
public void test376550_1b() { |
| 7227 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7228 |
return; |
| 7229 |
Map compilerOptions = getCompilerOptions(); |
| 7230 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7231 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7232 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7233 |
this.runNegativeTest( |
| 7234 |
new String[] { |
| 7235 |
"X.java", |
| 7236 |
"public class X {\n" + |
| 7237 |
" int i = 1;\n" + |
| 7238 |
" public void upper1(){}\n" + |
| 7239 |
" public void foo(){\n" + // can be static |
| 7240 |
" class Local{\n" + |
| 7241 |
" int i2 = 1;\n" + |
| 7242 |
" void method2() {\n" + // can't be static |
| 7243 |
" i2 = 1;\n" + |
| 7244 |
" }\n" + |
| 7245 |
" }\n" + |
| 7246 |
" }\n" + |
| 7247 |
"}" |
| 7248 |
}, |
| 7249 |
"----------\n" + |
| 7250 |
"1. ERROR in X.java (at line 4)\n" + |
| 7251 |
" public void foo(){\n" + |
| 7252 |
" ^^^^^\n" + |
| 7253 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7254 |
"----------\n", |
| 7255 |
null /* no extra class libraries */, |
| 7256 |
true /* flush output directory */, |
| 7257 |
compilerOptions /* custom options */ |
| 7258 |
); |
| 7259 |
} |
| 7260 |
|
| 7261 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7262 |
// LocalDeclaration with type as a type variable binding |
| 7263 |
public void test376550_2a() { |
| 7264 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7265 |
return; |
| 7266 |
Map compilerOptions = getCompilerOptions(); |
| 7267 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7268 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7269 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7270 |
this.runNegativeTest( |
| 7271 |
new String[] { |
| 7272 |
"X.java", |
| 7273 |
"public class X<T> {\n" + |
| 7274 |
" public void upper1(){}\n" + |
| 7275 |
" public void foo(){\n" + // can be static |
| 7276 |
" class Local<K>{\n" + |
| 7277 |
" void method2() {\n" + // can't be static |
| 7278 |
" K k;\n" + |
| 7279 |
" }\n" + |
| 7280 |
" }\n" + |
| 7281 |
" }\n" + |
| 7282 |
"}" |
| 7283 |
}, |
| 7284 |
"----------\n" + |
| 7285 |
"1. ERROR in X.java (at line 3)\n" + |
| 7286 |
" public void foo(){\n" + |
| 7287 |
" ^^^^^\n" + |
| 7288 |
"The method foo() from the type X<T> can potentially be declared as static\n" + |
| 7289 |
"----------\n", |
| 7290 |
null /* no extra class libraries */, |
| 7291 |
true /* flush output directory */, |
| 7292 |
compilerOptions /* custom options */ |
| 7293 |
); |
| 7294 |
} |
| 7295 |
|
| 7296 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7297 |
// LocalDeclaration with type as a type variable binding |
| 7298 |
public void test376550_2b() { |
| 7299 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7300 |
return; |
| 7301 |
Map compilerOptions = getCompilerOptions(); |
| 7302 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7303 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7304 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7305 |
this.runNegativeTest( |
| 7306 |
new String[] { |
| 7307 |
"X.java", |
| 7308 |
"public class X<T> {\n" + |
| 7309 |
" public void upper1(){}\n" + |
| 7310 |
" public void foo(){\n" + // can't be static |
| 7311 |
" class Local<K>{\n" + |
| 7312 |
" void method2() {\n" + // can't be static |
| 7313 |
" T t;\n" + |
| 7314 |
" }\n" + |
| 7315 |
" }\n" + |
| 7316 |
" }\n" + |
| 7317 |
"}" |
| 7318 |
}, |
| 7319 |
"", |
| 7320 |
null /* no extra class libraries */, |
| 7321 |
true /* flush output directory */, |
| 7322 |
compilerOptions /* custom options */ |
| 7323 |
); |
| 7324 |
} |
| 7325 |
|
| 7326 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7327 |
// MessageSend, calling outer class method inside a local class method |
| 7328 |
public void test376550_3a() { |
| 7329 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7330 |
return; |
| 7331 |
Map compilerOptions = getCompilerOptions(); |
| 7332 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7333 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7334 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7335 |
this.runNegativeTest( |
| 7336 |
new String[] { |
| 7337 |
"X.java", |
| 7338 |
"public class X<T> {\n" + |
| 7339 |
" public void upper1(){}\n" + |
| 7340 |
" public void foo(){\n" + // can't be static |
| 7341 |
" class Local<K>{\n" + |
| 7342 |
" void lower() {}\n" + |
| 7343 |
" void method2() {\n" + // can't be static |
| 7344 |
" upper1();\n" + |
| 7345 |
" }\n" + |
| 7346 |
" }\n" + |
| 7347 |
" }\n" + |
| 7348 |
"}" |
| 7349 |
}, |
| 7350 |
"", |
| 7351 |
null /* no extra class libraries */, |
| 7352 |
true /* flush output directory */, |
| 7353 |
compilerOptions /* custom options */ |
| 7354 |
); |
| 7355 |
} |
| 7356 |
|
| 7357 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7358 |
// MessageSend, calling local class method inside a local class method |
| 7359 |
public void test376550_3b() { |
| 7360 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7361 |
return; |
| 7362 |
Map compilerOptions = getCompilerOptions(); |
| 7363 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7364 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7365 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7366 |
this.runNegativeTest( |
| 7367 |
new String[] { |
| 7368 |
"X.java", |
| 7369 |
"public class X<T> {\n" + |
| 7370 |
" public void upper1(){}\n" + |
| 7371 |
" public void foo(){\n" + // can be static |
| 7372 |
" class Local<K>{\n" + |
| 7373 |
" void lower() {}\n" + |
| 7374 |
" void method2() {\n" + // can't be static |
| 7375 |
" lower();\n" + |
| 7376 |
" }\n" + |
| 7377 |
" }\n" + |
| 7378 |
" }\n" + |
| 7379 |
"}" |
| 7380 |
}, |
| 7381 |
"----------\n" + |
| 7382 |
"1. ERROR in X.java (at line 3)\n" + |
| 7383 |
" public void foo(){\n" + |
| 7384 |
" ^^^^^\n" + |
| 7385 |
"The method foo() from the type X<T> can potentially be declared as static\n" + |
| 7386 |
"----------\n", |
| 7387 |
null /* no extra class libraries */, |
| 7388 |
true /* flush output directory */, |
| 7389 |
compilerOptions /* custom options */ |
| 7390 |
); |
| 7391 |
} |
| 7392 |
|
| 7393 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7394 |
// Local class instance field is an argument in messageSend in local class method |
| 7395 |
public void test376550_4a() { |
| 7396 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7397 |
return; |
| 7398 |
Map compilerOptions = getCompilerOptions(); |
| 7399 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7400 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7401 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7402 |
this.runNegativeTest( |
| 7403 |
new String[] { |
| 7404 |
"X.java", |
| 7405 |
"public class X<T> {\n" + |
| 7406 |
" int i1 = 1;\n" + |
| 7407 |
" public void foo(){\n" + // can be static |
| 7408 |
" class Local<K>{\n" + |
| 7409 |
" int i2 = 1;\n" + |
| 7410 |
" void lower(int i) {}\n" + |
| 7411 |
" void method2() {\n" + // can't be static |
| 7412 |
" lower(i2);\n" + |
| 7413 |
" }\n" + |
| 7414 |
" }\n" + |
| 7415 |
" }\n" + |
| 7416 |
"}" |
| 7417 |
}, |
| 7418 |
"----------\n" + |
| 7419 |
"1. ERROR in X.java (at line 3)\n" + |
| 7420 |
" public void foo(){\n" + |
| 7421 |
" ^^^^^\n" + |
| 7422 |
"The method foo() from the type X<T> can potentially be declared as static\n" + |
| 7423 |
"----------\n", |
| 7424 |
null /* no extra class libraries */, |
| 7425 |
true /* flush output directory */, |
| 7426 |
compilerOptions /* custom options */ |
| 7427 |
); |
| 7428 |
} |
| 7429 |
|
| 7430 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7431 |
// Outerclass instance field is an argument in messageSend in local class method |
| 7432 |
public void test376550_4b() { |
| 7433 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7434 |
return; |
| 7435 |
Map compilerOptions = getCompilerOptions(); |
| 7436 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7437 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7438 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7439 |
this.runNegativeTest( |
| 7440 |
new String[] { |
| 7441 |
"X.java", |
| 7442 |
"public class X<T> {\n" + |
| 7443 |
" int i1 = 1;\n" + |
| 7444 |
" public void foo(){\n" + // can't be static |
| 7445 |
" class Local<K>{\n" + |
| 7446 |
" int i2 = 1;\n" + |
| 7447 |
" void lower(int i) {}\n" + |
| 7448 |
" void method2() {\n" + // can't be static |
| 7449 |
" lower(i1);\n" + |
| 7450 |
" }\n" + |
| 7451 |
" }\n" + |
| 7452 |
" }\n" + |
| 7453 |
"}" |
| 7454 |
}, |
| 7455 |
"", |
| 7456 |
null /* no extra class libraries */, |
| 7457 |
true /* flush output directory */, |
| 7458 |
compilerOptions /* custom options */ |
| 7459 |
); |
| 7460 |
} |
| 7461 |
|
| 7462 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7463 |
// QualifiedNameReference, accessing local class instance field |
| 7464 |
public void test376550_5a() { |
| 7465 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7466 |
return; |
| 7467 |
Map compilerOptions = getCompilerOptions(); |
| 7468 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7469 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7470 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7471 |
this.runNegativeTest( |
| 7472 |
new String[] { |
| 7473 |
"X.java", |
| 7474 |
"public class X {\n" + |
| 7475 |
" int i1 = 1;\n" + |
| 7476 |
" public void foo(){\n" + // can be static |
| 7477 |
" class Local{\n" + |
| 7478 |
" int i2 = 1;\n" + |
| 7479 |
" void method2() {\n" + // can't be static |
| 7480 |
" Local.this.i2 = 1;\n" + |
| 7481 |
" }\n" + |
| 7482 |
" }\n" + |
| 7483 |
" }\n" + |
| 7484 |
"}" |
| 7485 |
}, |
| 7486 |
"----------\n" + |
| 7487 |
"1. ERROR in X.java (at line 3)\n" + |
| 7488 |
" public void foo(){\n" + |
| 7489 |
" ^^^^^\n" + |
| 7490 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7491 |
"----------\n", |
| 7492 |
null /* no extra class libraries */, |
| 7493 |
true /* flush output directory */, |
| 7494 |
compilerOptions /* custom options */ |
| 7495 |
); |
| 7496 |
} |
| 7497 |
|
| 7498 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7499 |
//QualifiedNameReference, accessing outer class instance field |
| 7500 |
public void test376550_5b() { |
| 7501 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7502 |
return; |
| 7503 |
Map compilerOptions = getCompilerOptions(); |
| 7504 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7505 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7506 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7507 |
this.runNegativeTest( |
| 7508 |
new String[] { |
| 7509 |
"X.java", |
| 7510 |
"public class X {\n" + |
| 7511 |
" int i1 = 1;\n" + |
| 7512 |
" public void foo(){\n" + // can't be static |
| 7513 |
" class Local{\n" + |
| 7514 |
" int i2 = 1;\n" + |
| 7515 |
" void method2() {\n" + // can't be static |
| 7516 |
" X.this.i1 = 1;\n" + |
| 7517 |
" }\n" + |
| 7518 |
" }\n" + |
| 7519 |
" }\n" + |
| 7520 |
"}" |
| 7521 |
}, |
| 7522 |
"", |
| 7523 |
null /* no extra class libraries */, |
| 7524 |
true /* flush output directory */, |
| 7525 |
compilerOptions /* custom options */ |
| 7526 |
); |
| 7527 |
} |
| 7528 |
|
| 7529 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7530 |
// QualifiedNameRef.analyseCode() |
| 7531 |
public void test376550_6a() { |
| 7532 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7533 |
return; |
| 7534 |
Map compilerOptions = getCompilerOptions(); |
| 7535 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7536 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7537 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7538 |
this.runNegativeTest( |
| 7539 |
new String[] { |
| 7540 |
"X.java", |
| 7541 |
"public class X {\n" + |
| 7542 |
" int i1 = 1;\n" + |
| 7543 |
" public void foo(){\n" + // can be static |
| 7544 |
" class Local{\n" + |
| 7545 |
" int i2 = 1;\n" + |
| 7546 |
" boolean method2() {\n" + // can't be static |
| 7547 |
" return Local.this.i2 == 1;\n" + |
| 7548 |
" }\n" + |
| 7549 |
" }\n" + |
| 7550 |
" }\n" + |
| 7551 |
"}" |
| 7552 |
}, |
| 7553 |
"----------\n" + |
| 7554 |
"1. ERROR in X.java (at line 3)\n" + |
| 7555 |
" public void foo(){\n" + |
| 7556 |
" ^^^^^\n" + |
| 7557 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7558 |
"----------\n", |
| 7559 |
null /* no extra class libraries */, |
| 7560 |
true /* flush output directory */, |
| 7561 |
compilerOptions /* custom options */ |
| 7562 |
); |
| 7563 |
} |
| 7564 |
|
| 7565 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7566 |
// QualifiedNameRef.analyseCode() |
| 7567 |
public void test376550_6b() { |
| 7568 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7569 |
return; |
| 7570 |
Map compilerOptions = getCompilerOptions(); |
| 7571 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7572 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7573 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7574 |
this.runNegativeTest( |
| 7575 |
new String[] { |
| 7576 |
"X.java", |
| 7577 |
"public class X {\n" + |
| 7578 |
" int i1 = 1;\n" + |
| 7579 |
" public void foo(){\n" + // can't be static |
| 7580 |
" class Local{\n" + |
| 7581 |
" int i2 = 1;\n" + |
| 7582 |
" boolean method2() {\n" + // can't be static |
| 7583 |
" return X.this.i1 == 1;\n" + |
| 7584 |
" }\n" + |
| 7585 |
" }\n" + |
| 7586 |
" }\n" + |
| 7587 |
"}" |
| 7588 |
}, |
| 7589 |
"", |
| 7590 |
null /* no extra class libraries */, |
| 7591 |
true /* flush output directory */, |
| 7592 |
compilerOptions /* custom options */ |
| 7593 |
); |
| 7594 |
} |
| 7595 |
|
| 7596 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7597 |
// QualifiedAllocationExpression, allocating an anonymous type without an enclosing instance of parent type |
| 7598 |
// anon. type is declared in local class |
| 7599 |
public void test376550_7a() { |
| 7600 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7601 |
return; |
| 7602 |
Map compilerOptions = getCompilerOptions(); |
| 7603 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7604 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7605 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7606 |
this.runNegativeTest( |
| 7607 |
new String[] { |
| 7608 |
"X.java", |
| 7609 |
"public class X {\n" + |
| 7610 |
" abstract class AbsUp{}\n" + |
| 7611 |
" public void foo(){\n" + // can be static |
| 7612 |
" class Local{\n" + |
| 7613 |
" abstract class AbsLow{}\n" + |
| 7614 |
" void method2() {\n" + // can't be static |
| 7615 |
" new AbsLow(){};\n" + |
| 7616 |
" }\n" + |
| 7617 |
" }\n" + |
| 7618 |
" }\n" + |
| 7619 |
"}" |
| 7620 |
}, |
| 7621 |
"----------\n" + |
| 7622 |
"1. ERROR in X.java (at line 3)\n" + |
| 7623 |
" public void foo(){\n" + |
| 7624 |
" ^^^^^\n" + |
| 7625 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7626 |
"----------\n", |
| 7627 |
null /* no extra class libraries */, |
| 7628 |
true /* flush output directory */, |
| 7629 |
compilerOptions /* custom options */ |
| 7630 |
); |
| 7631 |
} |
| 7632 |
|
| 7633 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7634 |
// QualifiedAllocationExpression, allocating an anonymous type without an enclosing instance of parent type |
| 7635 |
// anon. type is declared in outer class |
| 7636 |
public void test376550_7b() { |
| 7637 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7638 |
return; |
| 7639 |
Map compilerOptions = getCompilerOptions(); |
| 7640 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7641 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7642 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7643 |
this.runNegativeTest( |
| 7644 |
new String[] { |
| 7645 |
"X.java", |
| 7646 |
"public class X {\n" + |
| 7647 |
" abstract class AbsUp{}\n" + |
| 7648 |
" public void foo(){\n" + // can't be static |
| 7649 |
" class Local{\n" + |
| 7650 |
" abstract class AbsLow{}\n" + |
| 7651 |
" void method2() {\n" + // can't be static |
| 7652 |
" new AbsUp(){};\n" + |
| 7653 |
" }\n" + |
| 7654 |
" }\n" + |
| 7655 |
" }\n" + |
| 7656 |
"}" |
| 7657 |
}, |
| 7658 |
"", |
| 7659 |
null /* no extra class libraries */, |
| 7660 |
true /* flush output directory */, |
| 7661 |
compilerOptions /* custom options */ |
| 7662 |
); |
| 7663 |
} |
| 7664 |
|
| 7665 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7666 |
// FieldRef, from object of a class in outer class |
| 7667 |
public void test376550_8a() { |
| 7668 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7669 |
return; |
| 7670 |
Map compilerOptions = getCompilerOptions(); |
| 7671 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7672 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7673 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7674 |
this.runNegativeTest( |
| 7675 |
new String[] { |
| 7676 |
"X.java", |
| 7677 |
"public class X {\n" + |
| 7678 |
" class AbsUp{ int a;}\n" + |
| 7679 |
" public void foo(){\n" + // can be static |
| 7680 |
" class Local{\n" + |
| 7681 |
" class AbsLow{ int a;}\n" + |
| 7682 |
" void method2() {\n" + // can't be static |
| 7683 |
" int abc = new AbsLow().a;\n" + |
| 7684 |
" }\n" + |
| 7685 |
" }\n" + |
| 7686 |
" }\n" + |
| 7687 |
"}" |
| 7688 |
}, |
| 7689 |
"----------\n" + |
| 7690 |
"1. ERROR in X.java (at line 3)\n" + |
| 7691 |
" public void foo(){\n" + |
| 7692 |
" ^^^^^\n" + |
| 7693 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7694 |
"----------\n", |
| 7695 |
null /* no extra class libraries */, |
| 7696 |
true /* flush output directory */, |
| 7697 |
compilerOptions /* custom options */ |
| 7698 |
); |
| 7699 |
} |
| 7700 |
|
| 7701 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7702 |
//FieldRef, from object of a class in local class |
| 7703 |
public void test376550_8b() { |
| 7704 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7705 |
return; |
| 7706 |
Map compilerOptions = getCompilerOptions(); |
| 7707 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7708 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7709 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7710 |
this.runNegativeTest( |
| 7711 |
new String[] { |
| 7712 |
"X.java", |
| 7713 |
"public class X {\n" + |
| 7714 |
" class AbsUp{ int a;}\n" + |
| 7715 |
" public void foo(){\n" + // can't be static |
| 7716 |
" class Local{\n" + |
| 7717 |
" class AbsLow{ int a;}\n" + |
| 7718 |
" void method2() {\n" + // can't be static |
| 7719 |
" int abc = new AbsUp().a;\n" + |
| 7720 |
" }\n" + |
| 7721 |
" }\n" + |
| 7722 |
" }\n" + |
| 7723 |
"}" |
| 7724 |
}, |
| 7725 |
"", |
| 7726 |
null /* no extra class libraries */, |
| 7727 |
true /* flush output directory */, |
| 7728 |
compilerOptions /* custom options */ |
| 7729 |
); |
| 7730 |
} |
| 7731 |
|
| 7732 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7733 |
// QualifiedNameRef, accessing a field from local class field |
| 7734 |
public void test376550_9a() { |
| 7735 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7736 |
return; |
| 7737 |
Map compilerOptions = getCompilerOptions(); |
| 7738 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7739 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7740 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7741 |
this.runNegativeTest( |
| 7742 |
new String[] { |
| 7743 |
"X.java", |
| 7744 |
"public class X {\n" + |
| 7745 |
" X xup;\n" + |
| 7746 |
" int i = 1;\n" + |
| 7747 |
" public void foo(){\n" + // can be static |
| 7748 |
" class Local{\n" + |
| 7749 |
" X xdown;\n" + |
| 7750 |
" class AbsLow{ int a;}\n" + |
| 7751 |
" void method2() {\n" + // can't be static |
| 7752 |
" int abc = xdown.i;\n" + |
| 7753 |
" }\n" + |
| 7754 |
" }\n" + |
| 7755 |
" }\n" + |
| 7756 |
"}" |
| 7757 |
}, |
| 7758 |
"----------\n" + |
| 7759 |
"1. ERROR in X.java (at line 4)\n" + |
| 7760 |
" public void foo(){\n" + |
| 7761 |
" ^^^^^\n" + |
| 7762 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7763 |
"----------\n", |
| 7764 |
null /* no extra class libraries */, |
| 7765 |
true /* flush output directory */, |
| 7766 |
compilerOptions /* custom options */ |
| 7767 |
); |
| 7768 |
} |
| 7769 |
|
| 7770 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7771 |
// QualifiedNameRef, accessing a field from local class field |
| 7772 |
public void test376550_9b() { |
| 7773 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7774 |
return; |
| 7775 |
Map compilerOptions = getCompilerOptions(); |
| 7776 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7777 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7778 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7779 |
this.runNegativeTest( |
| 7780 |
new String[] { |
| 7781 |
"X.java", |
| 7782 |
"public class X {\n" + |
| 7783 |
" X xup;\n" + |
| 7784 |
" int i = 1;\n" + |
| 7785 |
" public void foo(){\n" + // can't be static |
| 7786 |
" class Local{\n" + |
| 7787 |
" X xdown;\n" + |
| 7788 |
" class AbsLow{ int a;}\n" + |
| 7789 |
" void method2() {\n" + // can't be static |
| 7790 |
" int abc = xup.i;\n" + |
| 7791 |
" }\n" + |
| 7792 |
" }\n" + |
| 7793 |
" }\n" + |
| 7794 |
"}" |
| 7795 |
}, |
| 7796 |
"", |
| 7797 |
null /* no extra class libraries */, |
| 7798 |
true /* flush output directory */, |
| 7799 |
compilerOptions /* custom options */ |
| 7800 |
); |
| 7801 |
} |
| 7802 |
|
| 7803 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7804 |
// QualifiedNameRef, accessing a field from local class field |
| 7805 |
public void test376550_10a() { |
| 7806 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7807 |
return; |
| 7808 |
Map compilerOptions = getCompilerOptions(); |
| 7809 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7810 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7811 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7812 |
this.runNegativeTest( |
| 7813 |
new String[] { |
| 7814 |
"X.java", |
| 7815 |
"public class X {\n" + |
| 7816 |
" X xup;\n" + |
| 7817 |
" int i = 1;\n" + |
| 7818 |
" public void foo(){\n" + // can be static |
| 7819 |
" class Local{\n" + |
| 7820 |
" X xdown;\n" + |
| 7821 |
" void calc(int i1){}\n" + |
| 7822 |
" void method2() {\n" + // can't be static |
| 7823 |
" calc(xdown.i);\n" + |
| 7824 |
" }\n" + |
| 7825 |
" }\n" + |
| 7826 |
" }\n" + |
| 7827 |
"}" |
| 7828 |
}, |
| 7829 |
"----------\n" + |
| 7830 |
"1. ERROR in X.java (at line 4)\n" + |
| 7831 |
" public void foo(){\n" + |
| 7832 |
" ^^^^^\n" + |
| 7833 |
"The method foo() from the type X can potentially be declared as static\n" + |
| 7834 |
"----------\n", |
| 7835 |
null /* no extra class libraries */, |
| 7836 |
true /* flush output directory */, |
| 7837 |
compilerOptions /* custom options */ |
| 7838 |
); |
| 7839 |
} |
| 7840 |
|
| 7841 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7842 |
// QualifiedNameRef, accessing a field from local class field |
| 7843 |
public void test376550_10b() { |
| 7844 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7845 |
return; |
| 7846 |
Map compilerOptions = getCompilerOptions(); |
| 7847 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7848 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7849 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7850 |
this.runNegativeTest( |
| 7851 |
new String[] { |
| 7852 |
"X.java", |
| 7853 |
"public class X {\n" + |
| 7854 |
" X xup;\n" + |
| 7855 |
" int i = 1;\n" + |
| 7856 |
" public void foo(){\n" + // can't be static |
| 7857 |
" class Local{\n" + |
| 7858 |
" X xdown;\n" + |
| 7859 |
" void calc(int i1){}\n" + |
| 7860 |
" void method2() {\n" + // can't be static |
| 7861 |
" calc(xup.i);\n" + |
| 7862 |
" }\n" + |
| 7863 |
" }\n" + |
| 7864 |
" }\n" + |
| 7865 |
"}" |
| 7866 |
}, |
| 7867 |
"", |
| 7868 |
null /* no extra class libraries */, |
| 7869 |
true /* flush output directory */, |
| 7870 |
compilerOptions /* custom options */ |
| 7871 |
); |
| 7872 |
} |
| 7873 |
|
| 7874 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7875 |
// bug test case |
| 7876 |
public void test376550_11() { |
| 7877 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7878 |
return; |
| 7879 |
Map compilerOptions = getCompilerOptions(); |
| 7880 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7881 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7882 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7883 |
this.runNegativeTest( |
| 7884 |
new String[] { |
| 7885 |
"X.java", |
| 7886 |
"import java.util.ArrayList;\n" + |
| 7887 |
"import java.util.Collection;\n" + |
| 7888 |
"public class X {\n" + |
| 7889 |
" private Object o = new Object();\n" + |
| 7890 |
" public final Collection<Object> go() {\n" + // can't be static |
| 7891 |
" return new ArrayList<Object>() {\n" + |
| 7892 |
" { add(o);}\n" + |
| 7893 |
" };\n" + |
| 7894 |
" }\n" + |
| 7895 |
"}" |
| 7896 |
}, |
| 7897 |
"----------\n" + |
| 7898 |
"1. WARNING in X.java (at line 6)\n" + |
| 7899 |
" return new ArrayList<Object>() {\n" + |
| 7900 |
" ^^^^^^^^^^^^^^^^^^^\n" + |
| 7901 |
"The serializable class does not declare a static final serialVersionUID field of type long\n" + |
| 7902 |
"----------\n" + |
| 7903 |
"2. WARNING in X.java (at line 7)\n" + |
| 7904 |
" { add(o);}\n" + |
| 7905 |
" ^\n" + |
| 7906 |
"Read access to enclosing field X.o is emulated by a synthetic accessor method\n" + |
| 7907 |
"----------\n", |
| 7908 |
null /* no extra class libraries */, |
| 7909 |
true /* flush output directory */, |
| 7910 |
compilerOptions /* custom options */ |
| 7911 |
); |
| 7912 |
} |
| 7913 |
|
| 7914 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 |
| 7915 |
public void test376550_12() { |
| 7916 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
| 7917 |
return; |
| 7918 |
Map compilerOptions = getCompilerOptions(); |
| 7919 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
| 7920 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
| 7921 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
| 7922 |
this.runNegativeTest( |
| 7923 |
new String[] { |
| 7924 |
"X.java", |
| 7925 |
"import java.util.ArrayList;\n" + |
| 7926 |
"import java.util.Collection;\n" + |
| 7927 |
"public class X<E> {\n" + |
| 7928 |
" private Object o = new Object();\n" + |
| 7929 |
" public final <E1> Collection<E1> go() {\n" + // CAN be static |
| 7930 |
" return new ArrayList<E1>() {\n" + |
| 7931 |
" { E1 e;}\n" + |
| 7932 |
" };\n" + |
| 7933 |
" }\n" + |
| 7934 |
"}" |
| 7935 |
}, |
| 7936 |
"----------\n" + |
| 7937 |
"1. ERROR in X.java (at line 5)\n" + |
| 7938 |
" public final <E1> Collection<E1> go() {\n" + |
| 7939 |
" ^^^^\n" + |
| 7940 |
"The method go() from the type X<E> can be declared as static\n" + |
| 7941 |
"----------\n" + |
| 7942 |
"2. WARNING in X.java (at line 6)\n" + |
| 7943 |
" return new ArrayList<E1>() {\n" + |
| 7944 |
" ^^^^^^^^^^^^^^^\n" + |
| 7945 |
"The serializable class does not declare a static final serialVersionUID field of type long\n" + |
| 7946 |
"----------\n", |
| 7947 |
null /* no extra class libraries */, |
| 7948 |
true /* flush output directory */, |
| 7949 |
compilerOptions /* custom options */ |
| 7950 |
); |
| 7951 |
} |
| 7191 |
} |
7952 |
} |