public class AvoidNotShortCircuitOperatorsForBooleanCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
boolean x = true; boolean result = true | x || false; // a warning here2. Using of not short-circuit operators while overriding a Boolean variable.
boolean x = true; boolean result = false; // any code result &= true | x || false; // a warning here3. Expression calculated with not short-circuit operators contains at least one boolean operand.
public boolean isTrue() {
return this.z | MyObject.is() // no warnings here
|| isModifier() && isNotTrue();
}
...
boolean r=true;
public boolean isTrue() {
return this.z | true && r // a warning here
|| isModifier() && isNotTrue();
}
| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
A key to search the warning message text in "messages.properties" file.
|
| Constructor and Description |
|---|
AvoidNotShortCircuitOperatorsForBooleanCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
List<String> |
getSupportedOperandsNames(com.puppycrawl.tools.checkstyle.api.DetailAST exprParentAST)
Searches for all supported operands names in current expression.
|
boolean |
hasTrueOrFalseLiteral(com.puppycrawl.tools.checkstyle.api.DetailAST parentAST)
Checks is the current expression has
keywords "true" or "false".
|
boolean |
isBooleanExpression(com.puppycrawl.tools.checkstyle.api.DetailAST node)
Checks that current expression is calculated using "|", "&", "|=", "&="
operators contains at least one Boolean operand.
|
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST detailAST) |
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeveritypublic static final String MSG_KEY
public AvoidNotShortCircuitOperatorsForBooleanCheck()
public final int[] getDefaultTokens()
getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getAcceptableTokens()
getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getRequiredTokens()
getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic final void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST detailAST)
visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic final boolean isBooleanExpression(com.puppycrawl.tools.checkstyle.api.DetailAST node)
node - - current TokenTypes.EXPR node to check.public final List<String> getSupportedOperandsNames(com.puppycrawl.tools.checkstyle.api.DetailAST exprParentAST)
exprParentAST - - the current TokenTypes.EXPR parent node.public final boolean hasTrueOrFalseLiteral(com.puppycrawl.tools.checkstyle.api.DetailAST parentAST)
parentAST - - the current TokenTypes.EXPR parent node.Copyright © 2021. All rights reserved.