Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#331 TypecastParenPad firing on paren expression after cast

release_4.0
closed
5
2012-10-10
2005-06-09
Dale King
No

I have TypecastParenPad configured for nospace and it
is reporting an error on lines where I am typecasting a
parenthesized expression.

For example here is a line that reports a failure on
the last parenthesis on the line because it has
whitespace before it:

i = (int) ( d1 / d2 );

That parenthesis should be ignored by the TypecastParenPad.

Discussion

  • Logged In: YES
    user_id=746148

    We incorrectly detect whether LPAREN is part of typecast

     
  • Logged In: YES
    user_id=746148

    Fix committed to CVS for 4.0

    diff -c -r1.9 ParenPadCheck.java


    src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/ParenPadCheck.java
    9 Jan 2005 10:50:56 -0000 1.9


    src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/ParenPadCheck.java
    15 Jun 2005 11:26:19 -0000


    62,69
    * @author Oliver Burn
    * @version 1.0

    /
    ! public class ParenPadCheck
    ! extends AbstractParenPadCheck
    {
    / @see com.puppycrawl.tools.checkstyle.api.Check /
    public int[] getDefaultTokens()
    --- 62,68 ----
    * @author Oliver Burn
    * @version 1.0

    /
    ! public class ParenPadCheck extends AbstractParenPadCheck
    {
    /
    @see com.puppycrawl.tools.checkstyle.api.Check /
    public int[] getDefaultTokens()
    **
    87,93
    }
    }
    else if ((aAST.getParent() == null)
    ! || (aAST.getParent().getType() !=
    TokenTypes.TYPECAST))
    {
    if (!isFollowsEmptyForIterator(aAST)) {
    processRight(aAST);
    --- 86,94 ----
    }
    }
    else if ((aAST.getParent() == null)
    ! || (aAST.getParent().getType() !=
    TokenTypes.TYPECAST)
    ! ||
    (aAST.getParent().findFirstToken(TokenTypes.RPAREN)
    ! != aAST))
    {
    if (!isFollowsEmptyForIterator(aAST)) {
    processRight(aAST);
    Index:
    src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheck.java
    ===================================================================
    RCS file:
    /cvsroot/checkstyle/checkstyle/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheck.java,v
    retrieving revision 1.4
    diff -c -r1.4 TypecastParenPadCheck.java

    src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheck.java
    9 Jan 2005 10:50:56 -0000 1.4
    ---
    src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/TypecastParenPadCheck.java
    15 Jun 2005 11:26:19 -0000
    ***
    48,55
    * @author Oliver Burn
    * @version 1.0

    /
    ! public class TypecastParenPadCheck
    ! extends AbstractParenPadCheck
    {
    /
    @see com.puppycrawl.tools.checkstyle.api.Check /
    public int[] getRequiredTokens()
    --- 48,54 ----
    * @author Oliver Burn
    * @version 1.0

    /
    ! public class TypecastParenPadCheck extends
    AbstractParenPadCheck
    {
    /
    @see com.puppycrawl.tools.checkstyle.api.Check */
    public int[] getRequiredTokens()***
    72,78 ***
    processLeft(aAST);
    }
    else if ((aAST.getParent() != null)
    ! && (aAST.getParent().getType() ==
    TokenTypes.TYPECAST))
    {
    processRight(aAST);
    }
    --- 71,79 ----
    processLeft(aAST);
    }
    else if ((aAST.getParent() != null)
    ! && (aAST.getParent().getType() ==
    TokenTypes.TYPECAST)
    ! &&
    (aAST.getParent().findFirstToken(TokenTypes.RPAREN)
    ! == aAST))
    {
    processRight(aAST);
    }