View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.java.rule.optimizations;
5   
6   import java.util.List;
7   
8   import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
9   import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
10  import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence;
11  import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
12  
13  /**
14   * Base class with utility methods for optimization rules
15   *
16   * @author mgriffa
17   * @since Created on Jan 11, 2005 
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              JavaNameOccurrence jocc = (JavaNameOccurrence)occ;
31              if (jocc.isOnLeftHandSide() || jocc.isSelfAssignment()) {
32                  return true;
33              }
34          }
35          return false;
36      }
37  
38  }