mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspection] EA-974827 incorrect behavior for EnhancedSwitchMigration when a variable is outside switch scope
GitOrigin-RevId: 5c88546b27597aba2b75141eb49439eb1a779dc8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4d18cc897e
commit
c402552b77
@@ -812,6 +812,9 @@ public final class EnhancedSwitchMigrationInspection extends AbstractBaseJavaLoc
|
||||
final LocalsOrMyInstanceFieldsControlFlowPolicy policy = LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance();
|
||||
final ControlFlow controlFlow = ControlFlowFactory.getInstance(declaration.getProject()).getControlFlow(declaration.getParent(), policy);
|
||||
final int switchStart = controlFlow.getStartOffset(statement);
|
||||
if (switchStart <= 0) {
|
||||
return null;
|
||||
}
|
||||
final ControlFlow beforeFlow = new ControlFlowSubRange(controlFlow, 0, switchStart);
|
||||
if (!ControlFlowUtil.isVariableDefinitelyAssigned(assignedVariable, beforeFlow)) {
|
||||
return null;
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with enhanced 'switch' statement" "true-preview"
|
||||
|
||||
class NotDefenitessignment1 {
|
||||
void test(int x) {
|
||||
String s = "1";
|
||||
Runnable runnable = () -> {
|
||||
switch (x) {
|
||||
case 1 -> s = "2";
|
||||
case 2 -> s = "3";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with enhanced 'switch' statement" "true-preview"
|
||||
|
||||
class NotDefenitessignment1 {
|
||||
void test(int x) {
|
||||
String s = "1";
|
||||
Runnable runnable = () -> {
|
||||
switc<caret>h (x) {
|
||||
case 1:
|
||||
s = "2";
|
||||
break;
|
||||
case 2:
|
||||
s = "3";
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
|
||||
Reference in New Issue
Block a user