forked from phoedos/pmd
Fixed false positives in MethodArgumentCouldBeFinal.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4837 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -36,6 +36,7 @@ Fixed several rules (exceptions on jdk 1.5 and jdk 1.6 source code).
|
||||
Fixed array handling in AvoidReassigningParameters and UnusedFormalParameter.
|
||||
Fixed bug in UselessOverridingMethod: false + when adding synchronization.
|
||||
Fixed false positives in LocalVariableCouldBeFinal.
|
||||
Fixed false positives in MethodArgumentCouldBeFinal.
|
||||
Rules can now call RuleContext.getSourceType() if they need to make different checks on JDK 1.4 and 1.5 code.
|
||||
CloseResource rule now checks code without java.sql import.
|
||||
ArrayIsStoredDirectly rule now checks Constructors
|
||||
|
@ -137,6 +137,19 @@ public class Foo {
|
||||
public void bar(int a) {
|
||||
x[--a] = 1;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
same as above but with extra parenthesis
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar(int a) {
|
||||
x[--(a)] = 1;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -124,20 +124,35 @@ public class NameOccurrence {
|
||||
}
|
||||
|
||||
public boolean isSelfAssignment() {
|
||||
if (location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTPreDecrementExpression || location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTPreIncrementExpression || location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTPostfixExpression) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTStatementExpression) {
|
||||
ASTStatementExpression exp = (ASTStatementExpression) location.jjtGetParent().jjtGetParent().jjtGetParent();
|
||||
if (exp.jjtGetNumChildren() >= 2 && exp.jjtGetChild(1) instanceof ASTAssignmentOperator) {
|
||||
ASTAssignmentOperator op = (ASTAssignmentOperator) exp.jjtGetChild(1);
|
||||
if (op.isCompound()) {
|
||||
return true;
|
||||
Node l = location;
|
||||
while (true) {
|
||||
Node p = l.jjtGetParent();
|
||||
Node gp = p.jjtGetParent();
|
||||
Node node = gp.jjtGetParent();
|
||||
if (node instanceof ASTPreDecrementExpression || node instanceof ASTPreIncrementExpression || node instanceof ASTPostfixExpression) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node instanceof ASTStatementExpression) {
|
||||
ASTStatementExpression exp = (ASTStatementExpression) node;
|
||||
if (exp.jjtGetNumChildren() >= 2 && exp.jjtGetChild(1) instanceof ASTAssignmentOperator) {
|
||||
ASTAssignmentOperator op = (ASTAssignmentOperator) exp.jjtGetChild(1);
|
||||
if (op.isCompound()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deal with extra parenthesis: "(i)++"
|
||||
if (p instanceof ASTPrimaryPrefix && p.jjtGetNumChildren() == 1 &&
|
||||
gp instanceof ASTPrimaryExpression && gp.jjtGetNumChildren() == 1&&
|
||||
node instanceof ASTExpression && node.jjtGetNumChildren() == 1) {
|
||||
l = node;
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isThisOrSuper() {
|
||||
|
Reference in New Issue
Block a user