View Javadoc

    1   package net.sourceforge.pmd.rules;
    2
    3   import net.sourceforge.pmd.AbstractRule;
    4   import net.sourceforge.pmd.ast.ASTAssignmentOperator;
    5   import net.sourceforge.pmd.ast.ASTExpression;
    6   import net.sourceforge.pmd.ast.ASTIfStatement;
    7   import net.sourceforge.pmd.ast.ASTWhileStatement;
    8   import net.sourceforge.pmd.ast.Node;
    9
    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.containsChildOfType(ASTAssignmentOperator.class))
    16          {
    17              addViolation(data, node);
    18              return data;
    19          }
    20          return super.visit(node, data);
    21      }
    22
    23  }