1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.io.File ; 32 import java.util.Hashtable ; 33 import java.util.Stack ; 34 35 36 37 38 52 53 public class SymbolTable { 54 55 private Hashtable packages = new Hashtable (); 56 private Stack scopes = new Stack (); 57 private ScopeIndex index = new ScopeIndex(); 58 59 private File currentFile; 60 private BaseScope baseScope; 61 62 private SymTabAST root; 63 64 66 70 public SymbolTable(SymTabAST aRoot) { 71 scopes = new Stack (); 72 this.root = aRoot; 73 74 baseScope = new BaseScope( this ); 75 pushScope(baseScope); 76 } 77 78 82 public SymTabAST getTree() { 83 return root; 84 } 85 86 103 108 public BaseScope getBaseScope() { 111 return baseScope; 112 } 113 114 119 public Scope getCurrentScope() { 120 return (Scope)scopes.peek(); 121 } 122 123 129 public void pushScope(Scope scope) { 130 scopes.push(scope); 131 } 132 133 139 public Scope popScope() { 140 Scope scope = (Scope)(scopes.pop()); 141 return scope; 142 } 143 144 148 public Hashtable getPackages() { 149 return packages; 152 } 153 154 159 public PackageDef getPackage( String name ) { 160 return (PackageDef)(packages.get( name )); 161 } 162 163 170 public void definePackage( PackageDef pkg, Scope parent ) { 171 parent.addDefinition(pkg); 172 packages.put(pkg.getQualifiedName(), pkg); 173 } 174 175 183 public void defineClass(ClassDef def) { 184 indexScope(def); 185 getCurrentScope().addDefinition(def); 186 } 187 188 196 public void defineMethod(MethodDef method) { 197 indexScope(method); 198 ((ClassDef)getCurrentScope()).addDefinition(method); 199 } 200 201 208 public void defineVariable(VariableDef v) { 209 getCurrentScope().addDefinition(v); 210 } 211 212 220 public void defineBlock(BlockDef blockDef) { 221 indexScope(blockDef); 222 getCurrentScope().addDefinition(blockDef); 223 } 224 225 232 public void defineLabel(LabelDef labelDef) { 234 getCurrentScope().addDefinition(labelDef); 235 } 236 237 243 public void indexScope(Scope scope) { 244 index.addScope(scope); 245 } 246 247 252 public ScopeIndex getScopeIndex() { 253 return index; 254 } 255 256 262 public void setCurrentFile(File file) { 263 currentFile = file; 264 } 265 266 271 public File getCurrentFile() { 272 return currentFile; 273 } 274 } 275 | Popular Tags |