mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[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:
committed by
intellij-monorepo-bot
parent
0a83c722e5
commit
ce6d666b08
+1
@@ -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();
|
||||
|
||||
+2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user