IDEA-160599 (False positive "Java | Code style issues | Control flow statement without braces" for "else if")

This commit is contained in:
Bas Leijdekkers
2016-09-01 12:24:24 +02:00
parent 9e4ed849c9
commit 25dbb4f50c
3 changed files with 20 additions and 2 deletions
@@ -140,7 +140,7 @@ public abstract class ControlFlowStatementVisitorBase extends BaseInspectionVisi
}
}
private boolean isHighlightOnlyKeyword(PsiElement element) {
protected boolean isHighlightOnlyKeyword(@NotNull PsiElement element) {
if (!isOnTheFly()) {
return true;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -140,6 +140,15 @@ public class ControlFlowStatementWithoutBracesInspection
@Contract("null->false")
@Override
protected boolean isApplicable(PsiStatement body) {
if (body instanceof PsiIfStatement && isHighlightOnlyKeyword(body)) {
final PsiElement parent = body.getParent();
if (parent instanceof PsiIfStatement) {
final PsiIfStatement ifStatement = (PsiIfStatement)parent;
if (ifStatement.getElseBranch() == body) {
return false;
}
}
}
return body != null && !(body instanceof PsiBlockStatement);
}
@@ -36,4 +36,13 @@ class T {
else System.out.println(0);
else System.out.println("no");
}
void fff(String[] a) {
if (a.length == 0) {
System.out.println();
}
else if (a.length > 10) {
System.out.println();
}
}
}