pmd: fixed bug #1012 False positive: Useless parentheses.

This commit is contained in:
Andreas Dangel 2013-01-19 18:49:19 +01:00
parent 7989ae1863
commit ac8e3314a3
4 changed files with 24 additions and 3 deletions

View File

@ -1,5 +1,6 @@
???? ??, 2012 - 5.0.2:
Fixed bug 1012: False positive: Useless parentheses.
Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation
Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners)
Fixed bug 1043: node.getEndLine() always returns 0 (ECMAscript)

View File

@ -225,7 +225,8 @@ public class Test {
//Expression/ConditionalAndExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
count(./CastExpression)=0 and
count(./EqualityExpression/MultiplicativeExpression)=0]
count(./EqualityExpression/MultiplicativeExpression)=0 and
count(./ConditionalOrExpression)=0]
|
//Expression/ConditionalOrExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
@ -237,7 +238,10 @@ public class Test {
count(./CastExpression)=0 and
count(./EqualityExpression)=0]
|
//Expression/AdditiveExpression/PrimaryExpression/PrimaryPrefix/Expression[count(*)=1 and not(./CastExpression) and not(./ConditionalExpression)]
//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral = 'true'])]/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
not(./CastExpression) and
not(./ConditionalExpression)]
|
//Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and

View File

@ -20,7 +20,7 @@ public class UnnecessaryRulesTest extends SimpleAggregatorTst {
addRule(RULESET, "UnusedNullCheckInEquals");
addRule(RULESET, "UselessOverridingMethod");
addRule(RULESET, "UselessOperationOnImmutable");
addRule(RULESET, "UselessParentheses");
addRule(RULESET, "UselessParentheses");
}
public static junit.framework.Test suite() {

View File

@ -177,6 +177,22 @@ public class Test {
int dayCount = 4;
String description = dayCount + " " + (dayCount == 1 ? oneDay : moreDays);
}
}
]]></code>
</test-code>
<test-code>
<description>#1012 False positive: Useless parentheses.</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
public void testMethod() {
if((lookahead.type == Keyword.STRING || lookahead.type == Keyword.NUMBER) && lookahead.type != baseType)
throw new IncompatibleAttributeTypeException(attribute);
System.out.println( "number " + ( 1 + 2 ) );
if(lookahead.type != baseType && (lookahead.type == Keyword.STRING || lookahead.type == Keyword.NUMBER))
throw new IncompatibleAttributeTypeException(attribute);
}
}
]]></code>
</test-code>