01: package net.sourceforge.pmd.rules;
02:
03: import net.sourceforge.pmd.AbstractRule;
04: import net.sourceforge.pmd.ast.ASTAssignmentOperator;
05: import net.sourceforge.pmd.ast.ASTExpression;
06: import net.sourceforge.pmd.ast.ASTIfStatement;
07: import net.sourceforge.pmd.ast.ASTWhileStatement;
08: import net.sourceforge.pmd.ast.Node;
09:
10: public class AssignmentInOperand extends AbstractRule {
11:
12: public Object visit(ASTExpression node, Object data) {
13: Node parent = node.jjtGetParent();
14: if ((parent instanceof ASTWhileStatement || parent instanceof ASTIfStatement)
15: && node
16: .containsChildOfType(ASTAssignmentOperator.class)) {
17: addViolation(data, node);
18: return data;
19: }
20: return super.visit(node, data);
21: }
22:
23: }
|