com.puppycrawl.tools.checkstyle.checks.coding

Class UnnecessaryParenthesesCheck

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()
{@inheritDoc}
voidleaveToken(DetailAST aAST)
{@inheritDoc}
voidvisitToken(DetailAST aAST)
{@inheritDoc}

Method Detail

getDefaultTokens

public int[] getDefaultTokens()
{@inheritDoc}

leaveToken

public void leaveToken(DetailAST aAST)
{@inheritDoc}

visitToken

public void visitToken(DetailAST aAST)
{@inheritDoc}