[java] local can be final in switches: avoid redundant computation; test data for inc operation (IDEA-229646)

GitOrigin-RevId: d53e55409a8a74c3374356f4943335e676ea0b21
This commit is contained in:
Anna Kozlova
2021-09-27 12:01:34 +00:00
committed by intellij-monorepo-bot
parent 0a83c722e5
commit ce6d666b08
3 changed files with 4 additions and 1 deletions
@@ -126,6 +126,7 @@ public class LocalCanBeFinal extends AbstractBaseJavaLocalInspectionTool impleme
}
super.visitCodeBlock(block);
Set<PsiVariable> declared = getDeclaredVariables(block);
if (declared.isEmpty()) return;
PsiElement anchor = block;
if (block.getParent() instanceof PsiSwitchBlock) {
anchor = block.getParent();
@@ -6,10 +6,12 @@ class Test {
long <warning descr="Variable 'k' can have 'final' modifier">k</warning>;
k = 0;
long l = 0;
int m; m = 0;
break;
case 2:
k = 2;
l = 3;
<error descr="Variable 'm' might not have been initialized">m</error>++;
break;
default:
break;
@@ -44,7 +44,7 @@ public class LocalCanBeFinalTest extends LightJavaCodeInsightFixtureTestCase {
myTool.REPORT_VARIABLES = true;
doTest();
}
public void testSwitchBraches() {
public void testSwitchBranches() {
myTool.REPORT_PARAMETERS = false;
myTool.REPORT_VARIABLES = true;
doTest();