View Javadoc

    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.rules;
    5
    6   import net.sourceforge.pmd.AbstractRule;
    7   import net.sourceforge.pmd.Rule;
    8   import net.sourceforge.pmd.ast.ASTFieldDeclaration;
    9   import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
    10  import net.sourceforge.pmd.ast.SimpleNode;
    11  import net.sourceforge.pmd.symboltable.NameOccurrence;
    12
    13  import java.util.Iterator;
    14
    15  public class SymbolTableTestRule extends AbstractRule implements Rule {
    16
    17      public Object visit(ASTFieldDeclaration node,Object data) {
    18          ASTVariableDeclaratorId declaration = (ASTVariableDeclaratorId)node.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
    19          for (Iterator iter = declaration.getUsages().iterator();iter.hasNext();) {
    20              NameOccurrence no = (NameOccurrence)iter.next();
    21              SimpleNode location = no.getLocation();
    22              System.out.println(declaration.getImage() + " is used here: " + location.getImage());
    23          }
    24          return data;
    25      }
    26  }