01: package org.acm.seguin.pmd.symboltable;
02:
03: import org.acm.seguin.pmd.util.UnaryFunction;
04:
05: import java.util.HashMap;
06: import java.util.List;
07: import java.util.Map;
08:
09: public class VariableUsageFinderFunction implements UnaryFunction {
10: private Map results = new HashMap();
11: private Map decls;
12: private boolean lookingForUsed;
13:
14: public VariableUsageFinderFunction(Map decls, boolean lookingForUsed) {
15: //System.err.println("VariableUsageFinderFunction("+decls+", "+lookingForUsed+")");
16: this .decls = decls;
17: this .lookingForUsed = lookingForUsed;
18: }
19:
20: public void applyTo(Object o) {
21: NameDeclaration decl = (NameDeclaration) o;
22: //System.err.print("VariableUsageFinderFunction.applyTo("+decl+")");
23: List usages = (List) decls.get(decl);
24: if (!usages.isEmpty()) {
25: //System.err.println(" usages is not empty");
26: if (lookingForUsed) {
27: //System.err.println(" add "+usages+"to usages for "+decl);
28: results.put(decl, usages);
29: }
30: } else {
31: if (!lookingForUsed) {
32: //System.err.println(" add "+usages+"to usages for "+decl);
33: results.put(decl, usages);
34: }
35: }
36: }
37:
38: public Map getUsed() {
39: return results;
40: }
41: }
|