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 array handling in AvoidReassigningParameters and UnusedFormalParameter.
|
||||||
Fixed bug in UselessOverridingMethod: false + when adding synchronization.
|
Fixed bug in UselessOverridingMethod: false + when adding synchronization.
|
||||||
Fixed false positives in LocalVariableCouldBeFinal.
|
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.
|
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.
|
CloseResource rule now checks code without java.sql import.
|
||||||
ArrayIsStoredDirectly rule now checks Constructors
|
ArrayIsStoredDirectly rule now checks Constructors
|
||||||
|
@ -137,6 +137,19 @@ public class Foo {
|
|||||||
public void bar(int a) {
|
public void bar(int a) {
|
||||||
x[--a] = 1;
|
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>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
@ -124,20 +124,35 @@ public class NameOccurrence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelfAssignment() {
|
public boolean isSelfAssignment() {
|
||||||
if (location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTPreDecrementExpression || location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTPreIncrementExpression || location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTPostfixExpression) {
|
Node l = location;
|
||||||
return true;
|
while (true) {
|
||||||
}
|
Node p = l.jjtGetParent();
|
||||||
|
Node gp = p.jjtGetParent();
|
||||||
if (location.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTStatementExpression) {
|
Node node = gp.jjtGetParent();
|
||||||
ASTStatementExpression exp = (ASTStatementExpression) location.jjtGetParent().jjtGetParent().jjtGetParent();
|
if (node instanceof ASTPreDecrementExpression || node instanceof ASTPreIncrementExpression || node instanceof ASTPostfixExpression) {
|
||||||
if (exp.jjtGetNumChildren() >= 2 && exp.jjtGetChild(1) instanceof ASTAssignmentOperator) {
|
return true;
|
||||||
ASTAssignmentOperator op = (ASTAssignmentOperator) exp.jjtGetChild(1);
|
}
|
||||||
if (op.isCompound()) {
|
|
||||||
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() {
|
public boolean isThisOrSuper() {
|
||||||
|
Reference in New Issue
Block a user