Class UnnecessaryParenthesesExtendedCheck
- 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.UnnecessaryParenthesesExtendedCheck
-
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable,com.puppycrawl.tools.checkstyle.api.Contextualizable
public class UnnecessaryParenthesesExtendedCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheckChecks if unnecessary parentheses are used in a statement or expression. The check will flag the following with warnings:
return (x); // parens around identifier return (x + 1); // parens around return value int x = (y / 2 + 1); // parens around assignment rhs for (int i = (0); i < 10; i++) { // parens around literal t -= (z + 1); // parens around assignment rhsThe check is not "type aware", that is to say, it can't tell if parentheses are unnecessary based on the types in an expression. It also doesn't know about operator precedence and associativity; therefore it won't catch something like
int x = (a + b) + c;In the above case, given that a, b, and c are all
intvariables, the parentheses arounda + bare not needed.- Since:
- 1.8.0
- Author:
- Eric Roe, Antonenko Dmitriy
-
-
Field Summary
Fields Modifier and Type Field Description static StringMSG_KEY_ASSIGNWarning message key.static StringMSG_KEY_EXPRWarning message key.static StringMSG_KEY_IDENTWarning message key.static StringMSG_KEY_LITERALWarning message key.static StringMSG_KEY_RETURNWarning message key.static StringMSG_KEY_STRINGWarning message key.
-
Constructor Summary
Constructors Constructor Description UnnecessaryParenthesesExtendedCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]getAcceptableTokens()int[]getDefaultTokens()int[]getRequiredTokens()voidleaveToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)voidsetIgnoreCalculationOfBooleanVariables(boolean ignoreCalculationOfBooleanVariables)Sets flag to IgnoreCalculationOfBooleanVariables.voidsetIgnoreCalculationOfBooleanVariablesWithAssert(boolean ignoreCalculationOfBooleanVariablesWithAssert)Sets flag to IgnoreCalculationOfBooleanVariablesWithAssert.voidsetIgnoreCalculationOfBooleanVariablesWithReturn(boolean ignoreCalculationOfBooleanVariablesWithReturn)Sets flag to IgnoreCalculationOfBooleanVariablesWithReturn.voidvisitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, 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_ASSIGN
public static final String MSG_KEY_ASSIGN
Warning message key.- See Also:
- Constant Field Values
-
MSG_KEY_EXPR
public static final String MSG_KEY_EXPR
Warning message key.- See Also:
- Constant Field Values
-
MSG_KEY_IDENT
public static final String MSG_KEY_IDENT
Warning message key.- See Also:
- Constant Field Values
-
MSG_KEY_LITERAL
public static final String MSG_KEY_LITERAL
Warning message key.- See Also:
- Constant Field Values
-
MSG_KEY_RETURN
public static final String MSG_KEY_RETURN
Warning message key.- See Also:
- Constant Field Values
-
MSG_KEY_STRING
public static final String MSG_KEY_STRING
Warning message key.- See Also:
- Constant Field Values
-
-
Method Detail
-
getDefaultTokens
public int[] getDefaultTokens()
- Specified by:
getDefaultTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getAcceptableTokens
public int[] getAcceptableTokens()
- Specified by:
getAcceptableTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()
- Specified by:
getRequiredTokensin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
visitTokenin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
leaveToken
public void leaveToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
leaveTokenin classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
setIgnoreCalculationOfBooleanVariables
public final void setIgnoreCalculationOfBooleanVariables(boolean ignoreCalculationOfBooleanVariables)
Sets flag to IgnoreCalculationOfBooleanVariables.- Parameters:
ignoreCalculationOfBooleanVariables- if true ignore unnecessary parentheses check in calculation of boolean.
-
setIgnoreCalculationOfBooleanVariablesWithReturn
public final void setIgnoreCalculationOfBooleanVariablesWithReturn(boolean ignoreCalculationOfBooleanVariablesWithReturn)
Sets flag to IgnoreCalculationOfBooleanVariablesWithReturn.- Parameters:
ignoreCalculationOfBooleanVariablesWithReturn- if true ignore unnecessary parentheses check in calculation of boolean with return state.
-
setIgnoreCalculationOfBooleanVariablesWithAssert
public final void setIgnoreCalculationOfBooleanVariablesWithAssert(boolean ignoreCalculationOfBooleanVariablesWithAssert)
Sets flag to IgnoreCalculationOfBooleanVariablesWithAssert.- Parameters:
ignoreCalculationOfBooleanVariablesWithAssert- if true ignore unnecessary parentheses check in calculation of boolean with assert state
-
-