Class ConfusingConditionCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.github.sevntu.checkstyle.checks.coding.ConfusingConditionCheck
-
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable
,com.puppycrawl.tools.checkstyle.api.Contextualizable
public class ConfusingConditionCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
This check prevents negation within an "if" expression if "else" is present.
For example, rephrase:
if (x != y) smth1(); else smth2(); as: if (x == y) smth2(); else smth1();Examples:
"if" expression contains negationif (a != b && c != d) { smth1(); } else { smth2(); }
You can escape of negation in "if" expression
and swapped code in "if" and "else" block:if (a == b || c == d) { smth2(); } else { smth1(); }
- Since:
- 1.9.0
- Author:
- Vadim Panasiuk
-
-
Constructor Summary
Constructors Constructor Description ConfusingConditionCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getAcceptableTokens()
int[]
getDefaultTokens()
int[]
getRequiredTokens()
void
setIgnoreInnerIf(boolean aIgnoreInnerIf)
Enable(true) | Disable(false) warnings for all inner "if".void
setIgnoreNullCaseInIf(boolean ignoreNullCaseInIf)
Disable(true) | Enable(false) warnings.void
setIgnoreSequentialIf(boolean ignoreSequentialIf)
Enable(true) | Disable(false) warnings for all "if" that follows the "else".void
setIgnoreThrowInElse(boolean ignoreThrowInElse)
Disable(true) | Enable(false) warnings.void
setMultiplyFactorForElseBlocks(int multiplyFactorForElseBlocks)
Sets multiplyFactorForElseBlocks field.void
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST literalIf)
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
-
-
-
Field Detail
-
MSG_KEY
public static final String MSG_KEY
The key is pointing to the message text String in "messages.properties file".This message used for common cases.- See Also:
- Constant Field Values
-
-
Method Detail
-
setIgnoreInnerIf
public void setIgnoreInnerIf(boolean aIgnoreInnerIf)
Enable(true) | Disable(false) warnings for all inner "if".- Parameters:
aIgnoreInnerIf
- ignore inner if
-
setIgnoreSequentialIf
public void setIgnoreSequentialIf(boolean ignoreSequentialIf)
Enable(true) | Disable(false) warnings for all "if" that follows the "else".- Parameters:
ignoreSequentialIf
- ignore sequential if
-
setIgnoreNullCaseInIf
public void setIgnoreNullCaseInIf(boolean ignoreNullCaseInIf)
Disable(true) | Enable(false) warnings.- Parameters:
ignoreNullCaseInIf
- if true disable warnings for "if".
-
setIgnoreThrowInElse
public void setIgnoreThrowInElse(boolean ignoreThrowInElse)
Disable(true) | Enable(false) warnings.- Parameters:
ignoreThrowInElse
- if true disable warnings for "if".
-
setMultiplyFactorForElseBlocks
public void setMultiplyFactorForElseBlocks(int multiplyFactorForElseBlocks)
Sets multiplyFactorForElseBlocks field.- Parameters:
multiplyFactorForElseBlocks
- define multiplyFactorForElseBlocks field.- See Also:
multiplyFactorForElseBlocks
-
getDefaultTokens
public int[] getDefaultTokens()
- Specified by:
getDefaultTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getAcceptableTokens
public int[] getAcceptableTokens()
- Specified by:
getAcceptableTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()
- Specified by:
getRequiredTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST literalIf)
- Overrides:
visitToken
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
-