forked from phoedos/pmd
pmd: fix #1104 IdempotentOperation false positive
This commit is contained in:
parent
dc64e2df77
commit
a417f0003f
@ -1,6 +1,7 @@
|
|||||||
????? ??, 2013 - 5.0.5:
|
????? ??, 2013 - 5.0.5:
|
||||||
|
|
||||||
Fixed bug 991: AvoidSynchronizedAtMethodLevel for static methods
|
Fixed bug 991: AvoidSynchronizedAtMethodLevel for static methods
|
||||||
|
Fixed bug 1104: IdempotentOperation false positive
|
||||||
Fixed bug 1111: False positive: Useless parentheses
|
Fixed bug 1111: False positive: Useless parentheses
|
||||||
Fixed bug 1114: CPD - Tokenizer not initialized with requested properties
|
Fixed bug 1114: CPD - Tokenizer not initialized with requested properties
|
||||||
Fixed bug 1118: ClassCastException in pmd.lang.ecmascript.ast.ASTElementGet
|
Fixed bug 1118: ClassCastException in pmd.lang.ecmascript.ast.ASTElementGet
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.sourceforge.pmd.lang.java.rule.design;
|
package net.sourceforge.pmd.lang.java.rule.design;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.sourceforge.pmd.lang.ast.Node;
|
import net.sourceforge.pmd.lang.ast.Node;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentOperator;
|
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentOperator;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
|
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
|
||||||
@ -59,6 +61,21 @@ public class IdempotentOperationsRule extends AbstractJavaRule {
|
|||||||
return super.visit(node, data);
|
return super.visit(node, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ASTPrimarySuffix> lhsSuffixes = lhs.jjtGetParent().jjtGetParent().findDescendantsOfType(ASTPrimarySuffix.class);
|
||||||
|
List<ASTPrimarySuffix> rhsSuffixes = rhs.jjtGetParent().jjtGetParent().findDescendantsOfType(ASTPrimarySuffix.class);
|
||||||
|
if (lhsSuffixes.size() != rhsSuffixes.size()) {
|
||||||
|
return super.visit(node, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lhsSuffixes.size(); i++) {
|
||||||
|
ASTPrimarySuffix l = lhsSuffixes.get(i);
|
||||||
|
ASTPrimarySuffix r = rhsSuffixes.get(i);
|
||||||
|
|
||||||
|
if (!l.hasImageEqualTo(r.getImage())) {
|
||||||
|
return super.visit(node, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addViolation(data, node);
|
addViolation(data, node);
|
||||||
return super.visit(node, data);
|
return super.visit(node, data);
|
||||||
}
|
}
|
||||||
|
@ -61,4 +61,16 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>#1104 IdempotentOperation false positive</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void bar() {
|
||||||
|
SignDelayer.this.sign = SignDelayer.this.arg.sign();
|
||||||
|
MMultiplexer.this.lastEvent = MMultiplexer.this.firstEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user