View Javadoc

    1   /*
    2    * Created on Jan 11, 2005
    3    *
    4    * $Id$
    5    */
    6   package net.sourceforge.pmd.lang.java.rule.optimizations;
    7
    8   import java.util.List;
    9
    10  import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
    11  import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
    12  import net.sourceforge.pmd.lang.java.symboltable.NameOccurrence;
    13
    14  /**
    15   * Base class with utility methods for optimization rules
    16   *
    17   * @author mgriffa
    18   */
    19  public class AbstractOptimizationRule extends AbstractJavaRule {
    20
    21      public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
    22          if (node.isInterface()) {
    23              return data;
    24          }
    25          return super.visit(node, data);
    26      }
    27
    28      protected boolean assigned(List<NameOccurrence> usages) {
    29          for (NameOccurrence occ: usages) {
    30              if (occ.isOnLeftHandSide() || occ.isSelfAssignment()) {
    31                  return true;
    32              }
    33          }
    34          return false;
    35      }
    36
    37  }