[intention-preview] IDEA-317060 fix creation of a statement from expression

GitOrigin-RevId: 95c10072de86b6c86354823c9dec8a828bebcef4
This commit is contained in:
Mikhail Pyltsin
2023-04-07 16:18:01 +00:00
committed by intellij-monorepo-bot
parent 8b508e991d
commit cab7eb3b00
3 changed files with 23 additions and 0 deletions
@@ -45,6 +45,7 @@ public final class RemoveUnusedVariableUtil {
List<PsiElement> sideEffects = new ArrayList<>();
boolean hasSideEffects = checkSideEffects(element, variableToIgnore, sideEffects);
if (!hasSideEffects || sideEffects.isEmpty()) return RemoveMode.DELETE_ALL;
if (!PsiUtil.isStatement(element)) return RemoveMode.DELETE_ALL;
return RemoveMode.MAKE_STATEMENT;
}
@@ -0,0 +1,7 @@
// "Remove redundant initializer" "true-preview"
class A {
void test2(){
String str;
}
}
@@ -0,0 +1,15 @@
// "Remove redundant initializer" "true-preview"
class A {
void test2(){
String str = switch<caret> (1) {
case 1 -> "a";
default ->
{
str = "b";
System.out.println(str);
yield str + "c";
}
};
}
}