1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.util.ArrayList ; 32 import java.util.List ; 33 import java.util.ListIterator ; 34 35 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 36 37 40 public class ReferenceCounter extends ReferenceTool { 41 private List _references = new ArrayList (); 42 private List _resolvedReferences = new ArrayList (); 43 private List _unresolvedReferences = new ArrayList (); 44 45 public ReferenceCounter(SymbolTable table) { 46 super(table.getTree()); 47 countReferences(); 48 } 49 50 53 public int numberOfReferences() { 54 return _references.size(); 55 } 56 57 60 public int numberOfResolvedReferences() { 61 return _resolvedReferences.size(); 62 } 63 64 public int numberOfUnresolvedReferences() { 65 return _unresolvedReferences.size(); 66 } 67 68 public ListIterator getUnresolvedReferences() { 69 return _unresolvedReferences.listIterator(); 70 } 71 72 private void countReferences() { 73 handleNode( _tree ); 74 } 75 76 protected void handleNode( SymTabAST node ) { 77 if (node.getType() == TokenTypes.IDENT && node.isMeaningful()) { 78 _references.add( node ); 79 if (node.getDefinition() != null && !(node.getDefinition() instanceof UnknownClass)) { 80 _resolvedReferences.add( node ); 81 } 82 else { 83 _unresolvedReferences.add( node ); 84 } 85 } 86 walkChildren( node ); 87 } 88 } 89 | Popular Tags |