SingleStatementInBlockFix: fixed main element determination

This commit is contained in:
Tagir Valeev
2018-10-23 16:28:52 +07:00
parent 98b9f95a16
commit f943a97bc8
4 changed files with 22 additions and 3 deletions
@@ -172,12 +172,12 @@ public class SingleStatementInBlockInspection extends BaseInspection {
if (startElement instanceof PsiLoopStatement) {
body = ((PsiLoopStatement)startElement).getBody();
}
else if (startParent instanceof PsiLoopStatement) {
body = ((PsiLoopStatement)startParent).getBody();
}
else if (startElement instanceof PsiIfStatement) {
body = ((PsiIfStatement)startElement).getThenBranch();
}
else if (startParent instanceof PsiLoopStatement) {
body = ((PsiLoopStatement)startParent).getBody();
}
else if (startElement instanceof PsiKeyword) {
assert startParent instanceof PsiIfStatement;
PsiIfStatement ifStatement = (PsiIfStatement)startParent;
@@ -0,0 +1,8 @@
class X {
void f(int[] a) {
for(int aa : a)
if(aa <caret>> 0) System.out.println(
aa
);
}
}
@@ -0,0 +1,10 @@
class X {
void f(int[] a) {
for(int aa : a)
if(aa <caret>> 0) {
System.out.println(
aa
);
}
}
}
@@ -38,6 +38,7 @@ public class SingleStatementInBlockFixTest extends IGQuickFixesTestCase {
public void testIfWithLoop() { doTest("if"); }
public void testIfWithLoop2() { doTest("else"); }
public void testIfWithLoop3() { assertQuickfixNotAvailable(getMessage("else")); }
public void testIfWithLoop4() { doTest("if"); }
public void testElseWithLoop() { doTest("else"); }
public void testTwoComments() { doTest("if"); }
public void testIncompleteIf() { assertQuickfixNotAvailable(getMessage("for")); }