diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheck.java
index ec57bb15d..96d589ad1 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheck.java
@@ -27,7 +27,7 @@ import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
import java.util.Stack;
/**
- * Restricts nested boolean operators (&&, || and ^) to
+ * Restricts nested boolean operators (&&, ||, &, | and ^) to
* a specified depth (default = 3).
*
* @author Simon Harris
@@ -69,7 +69,11 @@ public final class BooleanExpressionComplexityCheck extends Check
/** {@inheritDoc} */
public int[] getRequiredTokens()
{
- return getDefaultTokens();
+ return new int[] {
+ TokenTypes.CTOR_DEF,
+ TokenTypes.METHOD_DEF,
+ TokenTypes.EXPR,
+ };
}
/**
diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/metrics/BooleanExpressionComplexityCheckTestInput.java b/src/testinputs/com/puppycrawl/tools/checkstyle/metrics/BooleanExpressionComplexityCheckTestInput.java
index cc39f3cbc..18b17e1cd 100644
--- a/src/testinputs/com/puppycrawl/tools/checkstyle/metrics/BooleanExpressionComplexityCheckTestInput.java
+++ b/src/testinputs/com/puppycrawl/tools/checkstyle/metrics/BooleanExpressionComplexityCheckTestInput.java
@@ -24,6 +24,11 @@ public class BooleanExpressionComplexityCheckTestInput {
}
public boolean equals(Object object) {
- return (((_a && (_b & _c)) || (_c ^ _d)));
+ return (((_a && (_b & _c)) || (_c ^ _d) || (_a && _d)));
+ }
+
+ public boolean bitwise()
+ {
+ return (((_a & (_b & _c)) | (_c ^ _d) | (_a & _d)));
}
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheckTest.java
index 26170b6ed..5fd443fcb 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheckTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/BooleanExpressionComplexityCheckTest.java
@@ -12,7 +12,20 @@ public class BooleanExpressionComplexityCheckTest extends BaseCheckTestCase
createCheckConfig(BooleanExpressionComplexityCheck.class);
String[] expected = {
- "13:9: Boolean expression complexity is 4 (max allowed is 3).",
+ "13:9: Boolean expression complexity is 4 (max allowed is 3).",
+ "32:9: Boolean expression complexity is 6 (max allowed is 3).",
+ };
+
+ verify(checkConfig, getPath("metrics" + File.separator + "BooleanExpressionComplexityCheckTestInput.java"), expected);
+ }
+
+ public void testNoBitwise() throws Exception {
+ DefaultConfiguration checkConfig =
+ createCheckConfig(BooleanExpressionComplexityCheck.class);
+ checkConfig.addAttribute("max", "5");
+ checkConfig.addAttribute("tokens", "BXOR,LAND,LOR");
+
+ String[] expected = {
};
verify(checkConfig, getPath("metrics" + File.separator + "BooleanExpressionComplexityCheckTestInput.java"), expected);
diff --git a/src/xdocs/config_metrics.xml b/src/xdocs/config_metrics.xml
index 795276146..587b39b76 100755
--- a/src/xdocs/config_metrics.xml
+++ b/src/xdocs/config_metrics.xml
@@ -13,7 +13,8 @@
Restrict the number of number of &&, ||
+ class="code">&&, ||,
+ &, |
and ^ in an expression.
+ Note that the operators & and + | are not only integer bitwise operators, they are also the + + non-shortcut versions of the boolean operators + && and ||. +
+ To configure the check to ignore & and + |: +
+New features:
+