mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-380307 "Fix all 'Code block contains single statement' problems in file" changes semantics
GitOrigin-RevId: 24a924d763405960425c35436372f57ab64a70e9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
65b042142d
commit
86d095cd79
@@ -22,6 +22,7 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -175,6 +176,7 @@ public class SingleStatementInBlockInspection extends BaseInspection implements
|
||||
return null;
|
||||
}
|
||||
if (!(body instanceof PsiBlockStatement block)) return null;
|
||||
if (SingleStatementInBlockVisitor.isDanglingElseProblem(ControlFlowUtils.stripBraces(block), block)) return null;
|
||||
return new BlockData(statement, block);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class X {
|
||||
static int test(int[] a) {
|
||||
if (a[0] == 0) <caret>{
|
||||
if (a[1] == 0) return 1;
|
||||
else if (a[1] == 1) return 2;
|
||||
} else return 3;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class X {
|
||||
static int test(int[] a) {
|
||||
if (a[0] == 0) <caret>{
|
||||
if (a[1] == 0) return 1;
|
||||
else {
|
||||
if (a[1] == 1) return 2;
|
||||
}
|
||||
} else return 3;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ public class SingleStatementInBlockFixTest extends IGQuickFixesTestCase {
|
||||
public void testIncompleteIf() { assertQuickfixNotAvailable(getMessage("for")); }
|
||||
public void testNestedFor() { assertQuickfixNotAvailable(getMessage("for")); }
|
||||
public void testNestedFor2() { doTest("for"); }
|
||||
public void testFixAll() { super.doTest("Fix all 'Code block contains single statement' problems in file");}
|
||||
public void testHighlighting() {
|
||||
myFixture.configureByText("Test.java", """
|
||||
class X {
|
||||
|
||||
Reference in New Issue
Block a user