com.puppycrawl.tools.checkstyle.checks.coding

Class UnnecessaryParenthesesCheck

Implemented Interfaces:
Configurable, Contextualizable

public class UnnecessaryParenthesesCheck
extends Check

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 associatvity; 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.

Author:
Eric Roe

Method Summary

int[]
getDefaultTokens()
void
leaveToken(DetailAST aAST)
void
visitToken(DetailAST aAST)

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Method Details

getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check

See Also:
Check


leaveToken

public void leaveToken(DetailAST aAST)
Overrides:
leaveToken in interface Check

See Also:
Check


visitToken

public void visitToken(DetailAST aAST)
Overrides:
visitToken in interface Check

See Also:
Check