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.ast.ASTFieldDeclaration;
    8   import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
    9   import net.sourceforge.pmd.ast.SimpleNode;
    10  import net.sourceforge.pmd.symboltable.NameOccurrence;
    11
    12  public class SymbolTableTestRule extends AbstractRule {
    13
    14      public Object visit(ASTFieldDeclaration node,Object data) {
    15          ASTVariableDeclaratorId declaration = node.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
    16          for (NameOccurrence no: declaration.getUsages()) {
    17              SimpleNode location = no.getLocation();
    18              System.out.println(declaration.getImage() + " is used here: " + location.getImage());
    19          }
    20          return data;
    21      }
    22  }