KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > rules > SymbolTableTestRule


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 JavaDoc;
14
15 public class SymbolTableTestRule extends AbstractRule implements Rule {
16
17     public Object JavaDoc visit(ASTFieldDeclaration node,Object JavaDoc data) {
18         ASTVariableDeclaratorId declaration = (ASTVariableDeclaratorId)node.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
19         for (Iterator JavaDoc 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 }
27
Popular Tags