diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementVisitorBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementVisitorBase.java index cf2400063ac5..1efc91fce5b6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementVisitorBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementVisitorBase.java @@ -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; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementWithoutBracesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementWithoutBracesInspection.java index 7356a59093bc..a71f6f2443b9 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementWithoutBracesInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementWithoutBracesInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/statements_without_braces/ControlFlowStatements.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/statements_without_braces/ControlFlowStatements.java index 821eacd76b8f..756715d7eeb1 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/statements_without_braces/ControlFlowStatements.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/statements_without_braces/ControlFlowStatements.java @@ -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(); + } + } } \ No newline at end of file