1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 32 import java.util.Set ; 33 import java.util.TreeSet ; 34 35 36 37 public class ReferenceThreshold extends ReferenceTool { 38 private Set _underreferencedDefinitions; 39 private int _threshold; 40 41 public ReferenceThreshold(SymbolTable table, int threshold) { 42 super(table.getTree()); 43 _threshold = threshold; 44 _underreferencedDefinitions = new TreeSet (); 45 go(); 46 } 47 48 private void go() { 49 collectUnderreferencedDefinitions(); 50 } 51 52 private void collectUnderreferencedDefinitions() { 53 handleNode(_tree); 54 } 55 56 protected void handleNode(SymTabAST node) { 57 if (node.isMeaningful()) { 58 IDefinition def = node.getDefinition(); 59 if (def != null && 60 def.getNumReferences() <= _threshold && 61 def instanceof Definition) { 62 if (def.getQualifiedName().indexOf("test") < 0 && 66 def.getQualifiedName().indexOf("main") < 0) { 67 _underreferencedDefinitions.add(def); 68 } 69 } 70 } 71 72 walkChildren(node); 73 } 74 75 public Set getUnderreferencedDefinitions() { 76 return _underreferencedDefinitions; 77 } 78 } 79 | Popular Tags |