01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.rules;
04:
05: import net.sourceforge.pmd.AbstractRule;
06: import net.sourceforge.pmd.ast.ASTFieldDeclaration;
07: import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
08: import net.sourceforge.pmd.ast.SimpleNode;
09: import net.sourceforge.pmd.symboltable.NameOccurrence;
10:
11: public class SymbolTableTestRule extends AbstractRule {
12:
13: public Object visit(ASTFieldDeclaration node, Object data) {
14: ASTVariableDeclaratorId declaration = node.findChildrenOfType(
15: ASTVariableDeclaratorId.class).get(0);
16: for (NameOccurrence no : declaration.getUsages()) {
17: SimpleNode location = no.getLocation();
18: System.out.println(declaration.getImage()
19: + " is used here: " + location.getImage());
20: }
21: return data;
22: }
23: }
|