EmptyStatementBodyInspection: delete body on empty foreach

This commit is contained in:
Tagir Valeev
2019-01-21 15:44:36 +07:00
parent b6fe08dbf9
commit c016d59b0c
3 changed files with 17 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
// "Delete element" "true"
class Test {
void test(String[] arr) {
}
}

View File

@@ -0,0 +1,8 @@
// "Delete element" "true"
class Test {
void test(String[] arr) {
fo<caret>r (String string : arr) {
}
}
}

View File

@@ -125,7 +125,10 @@ public class EmptyStatementBodyInspection extends BaseInspection {
@Override
public void visitForeachStatement(@NotNull PsiForeachStatement statement) {
super.visitForeachStatement(statement);
checkLoopStatement(statement);
final PsiStatement body = statement.getBody();
if (body != null && isEmpty(body)) {
registerStatementError(statement, createFix(statement, statement.getIteratedValue()));
}
}
private void checkLoopStatement(PsiLoopStatement statement) {