1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.util.Hashtable ; 32 import java.util.Vector ; 33 34 35 36 37 41 public class ScopeIndex { 42 43 private Hashtable indexOfFiles = new Hashtable (); 46 47 public Hashtable getIndex() { 48 return indexOfFiles; 49 } 50 51 58 public Scope lookup(Occurrence occ) { 59 String key = occ.getFile().getAbsolutePath(); 60 Vector scopeList = getFileVector(key); 61 62 Scope result = findScope(scopeList, occ); 63 64 return result; 65 } 66 67 76 public Scope findScope(Vector scopeList, Occurrence occ) { 77 int i = 0; 78 79 Scope bestSoFar = (Scope) scopeList.elementAt(i); 80 81 while (!bestSoFar 82 .getTreeNode() 83 .getSpan() 84 .contains(occ.getLine(), occ.getColumn())) { 85 i++; 86 bestSoFar = (Scope) scopeList.elementAt(i); 87 } 88 89 for (; i < scopeList.size(); i++) { 90 Scope currentScope = (Scope) scopeList.elementAt(i); 91 92 if (currentScope 93 .getTreeNode() 94 .getSpan() 95 .contains(occ.getLine(), occ.getColumn())) { 96 if (bestSoFar 97 .getTreeNode() 98 .getSpan() 99 .contains(currentScope.getTreeNode().getSpan())) { 100 bestSoFar = currentScope; 101 } 102 } 103 } 104 105 return bestSoFar; 106 } 107 108 113 public void addScope(Scope scope) { 114 115 final SymTabAST SymTabAST = scope.getTreeNode(); 116 SymTabAST.getFile(); 117 Vector fileVector = 118 getFileVector(scope.getTreeNode().getFile().getAbsolutePath()); 119 120 fileVector.addElement(scope); 121 } 122 123 130 private Vector getFileVector(String fileName) { 131 Vector result = (Vector ) indexOfFiles.get(fileName); 132 133 if (result == null) { 134 result = new Vector (); 135 indexOfFiles.put(fileName, result); 136 } 137 138 return result; 139 } 140 } | Popular Tags |