View Javadoc

1   /*
2    * Created on Jan 11, 2005 
3    *
4    * $Id: AbstractOptimizationRule.java,v 1.14 2006/11/30 02:29:13 xlv Exp $
5    */
6   package net.sourceforge.pmd.rules.optimization;
7   
8   import java.util.Iterator;
9   import java.util.List;
10  
11  import net.sourceforge.pmd.AbstractRule;
12  import net.sourceforge.pmd.Rule;
13  import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
14  import net.sourceforge.pmd.symboltable.NameOccurrence;
15  
16  /***
17   * Base class with utility methods for optimization rules
18   *
19   * @author mgriffa
20   */
21  public class AbstractOptimizationRule extends AbstractRule implements Rule {
22  
23      public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
24          if (node.isInterface()) {
25              return data;
26          }
27          return super.visit(node, data);
28      }
29  
30      protected boolean assigned(List usages) {
31          for (Iterator j = usages.iterator(); j.hasNext();) {
32              NameOccurrence occ = (NameOccurrence) j.next();
33              if (occ.isOnLeftHandSide() || occ.isSelfAssignment()) {
34                  return true;
35              }
36              continue;
37          }
38          return false;
39      }
40  
41  }