public class TernaryPerExpressionCountCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
String str = null; String x = str != null ? "A" : "B" + str == null ? "C" : "D"; System.out.println(x);
Output for code above is "D", but more obvious would be "BC".
Check has following properties:
callString = "{? = call " +
(StringUtils.hasLength(catalogNameToUse)
? catalogNameToUse + "." : "") +
(StringUtils.hasLength(schemaNameToUse)
? schemaNameToUse + "." : "") +
procedureNameToUse + "(";
When using ignoreIsolatedTernaryOnLine (value = true), even without
ignoreTernaryOperatorsInBraces option Check won't warn on code below:
int a = (d == 5) ? d : f + ((d == 6) ? g : k);
| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
TernaryPerExpressionCountCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
void |
setIgnoreIsolatedTernaryOnLine(boolean ignoreIsolatedTernaryOnLine)
Sets parameter to ignore expressions in case if ternary operator is isolated in line.
|
void |
setIgnoreTernaryOperatorsInBraces(boolean ignoreTernaryOperatorsInBraces)
Sets parameter to ignore ternary operators in braces, default value =
true.
|
void |
setMaxTernaryPerExpressionCount(int maxTernaryPerExpressionCount)
Sets the maximum number of ternary operators, default value = 1.
|
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST expressionNode) |
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 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 void setMaxTernaryPerExpressionCount(int maxTernaryPerExpressionCount)
maxTernaryPerExpressionCount - Number of ternary operators per expressionIllegalArgumentException - when maxTernaryPerExpressionCount less zeropublic void setIgnoreTernaryOperatorsInBraces(boolean ignoreTernaryOperatorsInBraces)
ignoreTernaryOperatorsInBraces - ignore ternary operators in bracespublic void setIgnoreIsolatedTernaryOnLine(boolean ignoreIsolatedTernaryOnLine)
ignoreIsolatedTernaryOnLine - ignore expressions in case if ternary
operator is isolated in linepublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST expressionNode)
visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheckCopyright © 2021. All rights reserved.