IDEA-160599 (False positive "Java | Code style issues | Control flow statement withou...
authorBas Leijdekkers <basleijdekkers@gmail.com>
Thu, 1 Sep 2016 10:23:45 +0000 (12:23 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Thu, 1 Sep 2016 10:24:24 +0000 (12:24 +0200)
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementVisitorBase.java
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ControlFlowStatementWithoutBracesInspection.java
plugins/InspectionGadgets/test/com/siyeh/igtest/style/statements_without_braces/ControlFlowStatements.java

index cf2400063ac50f91103a6cf3610a0a128b001472..1efc91fce5b6b64731e460de2cd8c5b1f4d29969 100644 (file)
@@ -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;
     }
index 7356a59093bc59e95c3246228de4c808e3363990..a71f6f2443b92f37cf81cef4f8bead6912e9ebc1 100644 (file)
@@ -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);
     }
 
index 821eacd76b8faa6e096398b6647a53825f09c38c..756715d7eeb125109245484c1a77ea6af97fe98d 100644 (file)
@@ -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