View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.java.symboltable;
5   
6   import java.util.HashMap;
7   import java.util.List;
8   import java.util.Map;
9   
10  import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
11  import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
12  import net.sourceforge.pmd.util.UnaryFunction;
13  
14  public class VariableUsageFinderFunction implements UnaryFunction<NameDeclaration> {
15      
16      private Map<NameDeclaration, List<NameOccurrence>> results = new HashMap<>();
17  
18      private Map<NameDeclaration, List<NameOccurrence>> decls;
19  
20      public VariableUsageFinderFunction(Map<NameDeclaration, List<NameOccurrence>> decls) {
21          this.decls = decls;
22      }
23  
24      public void applyTo(NameDeclaration o) {
25          results.put(o, decls.get(o));
26      }
27  
28      public Map<NameDeclaration, List<NameOccurrence>> getUsed() {
29          return results;
30      }
31  }