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;
    5
    6   import net.sourceforge.pmd.lang.ast.Node;
    7   import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
    8   import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
    9   import net.sourceforge.pmd.lang.java.symboltable.NameOccurrence;
    10
    11  //FUTURE This is not referenced by any RuleSet?
    12  public class SymbolTableTestRule extends AbstractJavaRule {
    13
    14      @Override
    15      public Object visit(ASTFieldDeclaration node,Object data) {
    16          for(ASTVariableDeclaratorId declaration: node.findDescendantsOfType(ASTVariableDeclaratorId.class)) {
    17              for (NameOccurrence no: declaration.getUsages()) {
    18                  Node location = no.getLocation();
    19                  System.out.println(declaration.getImage() + " is used here: " + location.getImage());
    20              }
    21          }
    22          return data;
    23      }
    24  }