1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 32 33 import java.util.Enumeration ; 34 import java.util.Iterator ; 35 36 public class DefinitionTraverser { 37 38 protected SymbolTable _symbolTable; 39 40 public DefinitionTraverser( SymbolTable symbolTable ) { 41 _symbolTable = symbolTable; 42 } 43 44 public void traverse() { 45 Enumeration packages = _symbolTable.getPackages().elements(); 46 while ( packages.hasMoreElements() ) { 47 traverse( (PackageDef)(packages.nextElement()) ); 48 } 49 } 50 51 private void traverse( Definition def ) { 52 if ( def instanceof PackageDef ) { 53 traverse( (PackageDef)def ); 54 } 55 else if (def instanceof AnonymousInnerClass) { 56 traverse((AnonymousInnerClass)def); 57 } 58 else if ( def instanceof ClassDef ) { 59 traverse( (ClassDef)def ); 60 } 61 else if (def instanceof DefaultConstructor) { 62 traverse((DefaultConstructor)def); 63 } 64 else if ( def instanceof MethodDef ) { 65 traverse( (MethodDef)def ); 66 } 67 else if ( def instanceof BlockDef ) { 68 traverse( (BlockDef)def ); 69 } 70 else if ( def instanceof VariableDef ) { 71 traverse( (VariableDef)def ); 72 } 73 else if ( def instanceof LabelDef ) { 74 traverse( (LabelDef)def ); 75 } 76 } 77 78 private void traverse(PackageDef pkg) { 79 handlePackage(pkg); 80 traversePackage(pkg); 81 } 82 83 private void traverse(AnonymousInnerClass innerClass) { 84 handleAnonymousInnerClass(innerClass); 85 traverseChildren(innerClass); 86 } 87 88 private void traverse( ClassDef classDef ) { 89 handleClass( classDef ); 90 traverseChildren( classDef ); 91 } 92 93 private void traverse(DefaultConstructor constructor) { 94 handleDefaultConstructor(constructor); 95 } 96 97 private void traverse( MethodDef method ) { 98 handleMethod( method ); 99 traverseChildren( method ); 100 } 101 102 private void traverse( BlockDef block ) { 103 handleBlock( block ); 104 traverseChildren( block ); 105 } 106 107 private void traverse( VariableDef variable ) { 108 handleVariable( variable ); 109 } 110 111 private void traverse( LabelDef label ) { 112 handleLabel( label ); 113 } 114 115 private void traversePackage(PackageDef pkg) { 116 Iterator definitions = pkg.getClasses(); 117 while (definitions.hasNext()) { 118 ClassDef classDef = (ClassDef)definitions.next(); 119 traverse(classDef); 120 } 121 } 122 123 private void traverseChildren(Scope scope) { 124 Enumeration definitions = scope.getDefinitions(); 125 while ( definitions.hasMoreElements() ) { 126 Definition def = (Definition)(definitions.nextElement()); 127 traverse(def); 128 } 129 } 130 131 protected void handlePackage( PackageDef pkg ) {} 132 protected void handleAnonymousInnerClass(AnonymousInnerClass innerClass) {} 133 protected void handleClass( ClassDef classDef ) {} 134 protected void handleDefaultConstructor(DefaultConstructor constructor) {} 135 protected void handleMethod( MethodDef method ) {} 136 protected void handleBlock( BlockDef block ) {} 137 protected void handleVariable( VariableDef variable ) {} 138 protected void handleLabel( LabelDef label ) {} 139 } 140 | Popular Tags |