public class UnnecessaryParenthesesCheck extends AbstractCheck
Checks 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 rhs
The 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 int variables, the parentheses around a + b
are not needed.
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_ASSIGN
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_EXPR
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_IDENT
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_LAMBDA
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_LITERAL
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_RETURN
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_STRING
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
UnnecessaryParenthesesCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
void |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, log, setClassLoader, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final String MSG_IDENT
public static final String MSG_ASSIGN
public static final String MSG_EXPR
public static final String MSG_LITERAL
public static final String MSG_STRING
public static final String MSG_RETURN
public static final String MSG_LAMBDA
public UnnecessaryParenthesesCheck()
public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processpublic void leaveToken(DetailAST ast)
AbstractCheckleaveToken in class AbstractCheckast - the token leavingCopyright © 2001–2018. All rights reserved.