1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 32 33 import java.util.Enumeration ; 34 import java.util.Hashtable ; 35 import java.util.Iterator ; 36 import java.util.SortedSet ; 37 import java.util.TreeSet ; 38 import java.util.Vector ; 39 40 41 50 public abstract class Scope extends Definition { 51 52 protected SortedSet referencesInScope = new TreeSet (); 54 55 protected Hashtable elements = new Hashtable (); 56 protected Hashtable labels = new Hashtable (); 57 protected Hashtable classes = new Hashtable (); 58 59 public Scope( String name, Scope parentScope, SymTabAST node ) { 60 super( name, parentScope, node ); 61 } 62 63 public void addDefinition(VariableDef def) { 64 elements.put(def.getName(), def); 65 } 66 67 public void addDefinition(BlockDef def) { 68 elements.put(def.getName(), def); 69 } 70 71 public void addDefinition(ClassDef def) { 72 classes.put(def.getName(), def); 73 } 74 75 public void addDefinition(LabelDef def) { 76 labels.put(def.getName(), def); 77 } 78 79 public abstract void addDefinition(IPackage def); 80 81 protected Enumeration getDefinitions() { 82 Vector allElements = new Vector (); 83 84 allElements.addAll(elements.values()); 85 allElements.addAll(labels.values()); 86 allElements.addAll(classes.values()); 87 88 return allElements.elements(); 89 } 90 91 protected Iterator getClasses() { 92 return classes.values().iterator(); 93 } 94 95 public abstract IMethod getMethodDefinition(String name, ISignature signature); 96 public abstract IVariable getVariableDefinition(String name); 97 public abstract LabelDef getLabelDefinition(String name); 98 public abstract IClass getClassDefinition(String name); 99 100 public Iterator getReferencesIn() { 101 return referencesInScope.iterator(); 102 } 103 104 public Reference getSymbol(String name, Occurrence location) { 105 Reference result = null; 106 107 for (Iterator it = getReferencesIn(); it.hasNext(); ) { 108 Reference reference = (Reference)it.next(); 109 if (reference.getLine() == location.getLine() && 111 reference.getColumn() == location.getColumn()) { 112 result = reference; 113 break; 114 } 115 } 117 return result; 118 } 119 120 public void addReferenceInScope( Reference reference ) { 121 referencesInScope.add( reference ); 122 } 123 124 } 125 | Popular Tags |