#1407 UselessParentheses "&" and "+" operator precedence

This commit is contained in:
Andreas Dangel
2015-09-26 10:23:43 +02:00
parent f3da33cca2
commit 145780de9c
3 changed files with 54 additions and 2 deletions

View File

@ -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

View File

@ -251,6 +251,47 @@ public class Useless {
public boolean test(Object a, Object b) {
return (a == null) == (b == null);
}
}
]]></code>
</test-code>
<test-code>
<description>#1407 UselessParentheses "&amp;" and "+" operator precedence</description>
<expected-problems>12</expected-problems>
<expected-linenumbers>3,4,5,6,7,8,9,10,11,12,13,14</expected-linenumbers>
<code><![CDATA[
class ExampleClass {
void exampleExpressions() {
eUseless = (a++) + b;
eUseless = (a--) + b;
eUseless = (++a) + b;
eUseless = (--a) + b;
eUseless = (+a) + b;
eUseless = (-a) + b;
eUseless = (~a) + b;
eUseless = (!a) + b;
eUseless = (a * b) + c;
eUseless = (a / b) + c;
eUseless = (a % b) + c;
eUseless = (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;
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;
}
}
]]></code>
</test-code>

View File

@ -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:**