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, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public 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()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processpublic void leaveToken(DetailAST ast)
AbstractCheck
leaveToken
in class AbstractCheck
ast
- the token leavingCopyright © 2001–2018. All rights reserved.