View Javadoc

1   /*
2    * Created on Jan 11, 2005 
3    *
4    * $Id$
5    */
6   package net.sourceforge.pmd.rules.optimization;
7   
8   import java.util.List;
9   
10  import net.sourceforge.pmd.AbstractRule;
11  import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
12  import net.sourceforge.pmd.symboltable.NameOccurrence;
13  
14  /**
15   * Base class with utility methods for optimization rules
16   *
17   * @author mgriffa
18   */
19  public class AbstractOptimizationRule extends AbstractRule {
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              continue;
34          }
35          return false;
36      }
37  
38  }