diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g index ee6d80466..b9e9fb410 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g @@ -813,10 +813,10 @@ multiplicativeExpression ; unaryExpression - : INC^ unaryExpression - | DEC^ unaryExpression - | MINUS^ {#MINUS.setType(UNARY_MINUS);} unaryExpression - | PLUS^ {#PLUS.setType(UNARY_PLUS);} unaryExpression + : INC^ unaryExpression {ver.verifyNoWSAfter(#INC);} + | DEC^ unaryExpression {ver.verifyNoWSAfter(#DEC);} + | MINUS^ {#MINUS.setType(UNARY_MINUS); ver.verifyNoWSAfter(#MINUS);} unaryExpression + | PLUS^ {#PLUS.setType(UNARY_PLUS); ver.verifyNoWSAfter(#PLUS);} unaryExpression | unaryExpressionNotPlusMinus ; @@ -882,8 +882,8 @@ postfixExpression // possibly add on a post-increment or post-decrement. // allows INC/DEC on too much, but semantics can check - ( in:INC^ {#in.setType(POST_INC);} - | de:DEC^ {#de.setType(POST_DEC);} + ( in:INC^ {#in.setType(POST_INC); ver.verifyNoWSBefore(#in);} + | de:DEC^ {#de.setType(POST_DEC); ver.verifyNoWSBefore(#de);} | // nothing ) ; @@ -1044,10 +1044,10 @@ DIV : '/' {ver.verifyWSAroundEnd(getLine(), getColumn(), "/");} ; DIV_ASSIGN : "/=" {ver.verifyWSAroundEnd(getLine(), getColumn(), "/=");}; PLUS : '+'; // must handle the UNARY_PLUS PLUS_ASSIGN : "+=" {ver.verifyWSAroundEnd(getLine(), getColumn(), "+=");}; -INC : "++" ; +INC : "++" ; // must handle POST_INC MINUS : '-' ; // must handle the UNARY_MINUS MINUS_ASSIGN : "-=" {ver.verifyWSAroundEnd(getLine(), getColumn(), "-=");}; -DEC : "--" ; +DEC : "--" ; // must handle POST_DEC STAR : '*' ; // star is special cause it can be used in imports. STAR_ASSIGN : "*=" {ver.verifyWSAroundEnd(getLine(), getColumn(), "*=");}; MOD : '%' {ver.verifyWSAroundEnd(getLine(), getColumn(), "%");} ; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.tree.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.tree.g index af883ba6f..1894c3b1a 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.tree.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.tree.g @@ -389,15 +389,15 @@ expr | #(DIV expr expr) | #(MOD expr expr) | #(STAR expr expr) - | #(INC expr) { ver.verifyNoWSAfter(#INC); } - | #(DEC expr) { ver.verifyNoWSAfter(#DEC); } - | #(POST_INC expr) { ver.verifyNoWSBefore(#POST_INC); } - | #(POST_DEC expr) { ver.verifyNoWSBefore(#POST_DEC); } + | #(INC expr) + | #(DEC expr) + | #(POST_INC expr) + | #(POST_DEC expr) | #(BNOT expr) { ver.verifyNoWSAfter(#BNOT); } | #(LNOT expr) { ver.verifyNoWSAfter(#LNOT); } | #("instanceof" expr expr) // Java ensures surrounded by WS! - | #(UNARY_MINUS expr) { ver.verifyNoWSAfter(#UNARY_MINUS); } - | #(UNARY_PLUS expr) { ver.verifyNoWSAfter(#UNARY_PLUS); } + | #(UNARY_MINUS expr) + | #(UNARY_PLUS expr) | primaryExpression ; @@ -454,7 +454,7 @@ constant newExpression : #( "new" type ( newArrayDeclarator (arrayInitializer)? - | elist ({ver.reportStartTypeBlock(Scope.ANONINNER, false);} objBlock {ver.reportEndTypeBlock();})? + | elist ( objBlock )? ) ) diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 81a91c583..6b5adf791 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -98,8 +98,11 @@ public class CheckerTest filepath + ":26: '+=' is not proceeded with whitespace.", filepath + ":27: '-=' is not proceeded with whitespace.", filepath + ":27: '-' is proceeded with whitespace.", + filepath + ":27: '+' is proceeded with whitespace.", filepath + ":28: '++' is preceeded with whitespace.", + filepath + ":28: '--' is preceeded with whitespace.", filepath + ":29: '++' is proceeded with whitespace.", + filepath + ":29: '--' is proceeded with whitespace.", filepath + ":35: 'synchronized' is not proceeded with whitespace.", filepath + ":37: 'try' is not proceeded with whitespace.", filepath + ":39: 'catch' is not proceeded with whitespace.", @@ -114,6 +117,7 @@ public class CheckerTest filepath + ":96: '==' is not proceeded with whitespace.", filepath + ":102: '*' is not proceeded with whitespace.", filepath + ":102: '*' is not preceeded with whitespace.", + filepath + ":109: '!' is proceeded with whitespace.", }; verify(c, filepath, expected); } @@ -137,8 +141,11 @@ public class CheckerTest filepath + ":26: '+=' is not proceeded with whitespace.", filepath + ":27: '-=' is not proceeded with whitespace.", filepath + ":27: '-' is proceeded with whitespace.", + filepath + ":27: '+' is proceeded with whitespace.", filepath + ":28: '++' is preceeded with whitespace.", + filepath + ":28: '--' is preceeded with whitespace.", filepath + ":29: '++' is proceeded with whitespace.", + filepath + ":29: '--' is proceeded with whitespace.", filepath + ":35: 'synchronized' is not proceeded with whitespace.", filepath + ":37: 'try' is not proceeded with whitespace.", filepath + ":39: 'catch' is not proceeded with whitespace.", @@ -152,6 +159,7 @@ public class CheckerTest filepath + ":96: '==' is not proceeded with whitespace.", filepath + ":102: '*' is not proceeded with whitespace.", filepath + ":102: '*' is not preceeded with whitespace.", + filepath + ":109: '!' is proceeded with whitespace.", }; verify(c, filepath, expected); } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputWhitespace.java b/src/tests/com/puppycrawl/tools/checkstyle/InputWhitespace.java index a8ff305da..8ae97bf2b 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/InputWhitespace.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/InputWhitespace.java @@ -24,9 +24,9 @@ class InputWhitespace int b= 1; // Ignore 1 b=1; // Ignore 1 b+=1; // Ignore 1 - b -=- 1; // Ignore 2 - b = b ++; // Ignore 1 - b = ++ b; // Ignore 1 + b -=- 1 + (+ b); // Ignore 2 + b = b ++ + b --; // Ignore 1 + b = ++ b - -- b; // Ignore 1 } /** method **/ @@ -101,4 +101,11 @@ class InputWhitespace { int x = 2 *3* 4; } + + /** boolean test **/ + private void boolTest() + { + boolean a = true; + boolean x = ! a; + } }