From 145780de9cf3a25c8b19d3bb640db4dc0426e1ba Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 26 Sep 2015 10:23:43 +0200 Subject: [PATCH] #1407 UselessParentheses "&" and "+" operator precedence --- .../resources/rulesets/java/unnecessary.xml | 13 +++++- .../unnecessary/xml/UselessParentheses.xml | 41 +++++++++++++++++++ src/site/markdown/overview/changelog.md | 2 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/resources/rulesets/java/unnecessary.xml b/pmd-java/src/main/resources/rulesets/java/unnecessary.xml index 97d5e1ff09..fab472e320 100644 --- a/pmd-java/src/main/resources/rulesets/java/unnecessary.xml +++ b/pmd-java/src/main/resources/rulesets/java/unnecessary.xml @@ -243,8 +243,17 @@ public class Test { //Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral = 'true'])]/PrimaryExpression[1]/PrimaryPrefix/Expression[ count(*)=1 and not(./CastExpression) and - not(./ConditionalExpression) and - not(./ShiftExpression)] + not(./AdditiveExpression[@Image = '-']) and + not(./ShiftExpression) and + not(./RelationalExpression) and + not(./InstanceOfExpression) and + not(./EqualityExpression) and + not(./AndExpression) and + not(./ExclusiveOrExpression) and + not(./InclusiveOrExpression) and + not(./ConditionalAndExpression) and + not(./ConditionalOrExpression) and + not(./ConditionalExpression)] | //Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Expression[ count(*)=1 and diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml index be24fde05d..120cd03e2b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml @@ -251,6 +251,47 @@ public class Useless { public boolean test(Object a, Object b) { return (a == null) == (b == null); } +} + ]]> + + + + #1407 UselessParentheses "&" and "+" operator precedence + 12 + 3,4,5,6,7,8,9,10,11,12,13,14 + > b) + c; + eGood = (a >>> b) + c; + eGood = (a < b) + c; + eGood = (a > b) + c; + eGood = (a <= b) + c; + eGood = (a >= b) + c; + eGood = (a instanceof b) + c; + eGood = (a == b) + c; + eGood = (a != b) + c; + eGood = (a & b) + c; + eGood = (a ^ b) + c; + eGood = (a | b) + c; + eGood = (a && b) + c; + eGood = (a || b) + c; + eGood = (a ? b : c) + d; + } } ]]> diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 5b64df6296..4b8f86978c 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -26,6 +26,8 @@ [#1387](https://sourceforge.net/p/pmd/bugs/1387/): CloseResource has false positive for ResultSet * java-strings/InsufficientStringBufferDeclaration: [#1409](https://sourceforge.net/p/pmd/bugs/1409/): NullPointerException in InsufficientStringBufferRule +* java-unnecessary/UselessParentheses: + [#1407](https://sourceforge.net/p/pmd/bugs/1407/): UselessParentheses "&" and "+" operator precedence **API Changes:**