1
2
3
4 package net.sourceforge.pmd.lang.java.symboltable;
5
6 import java.util.List;
7
8 import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
9 import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter;
10 import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
11
12 public class OccurrenceFinder extends JavaParserVisitorAdapter {
13
14 public Object visit(ASTPrimaryExpression node, Object data) {
15 NameFinder nameFinder = new NameFinder(node);
16
17
18
19 NameDeclaration decl = null;
20
21 List<JavaNameOccurrence> names = nameFinder.getNames();
22 for (JavaNameOccurrence occ: names) {
23 Search search = new Search(occ);
24 if (decl == null) {
25
26 search.execute();
27 decl = search.getResult();
28 if (decl == null) {
29
30
31
32 break;
33 }
34 } else {
35
36 search.execute(decl.getScope());
37 decl = search.getResult();
38
39 if (decl == null) {
40
41
42
43
44
45
46
47
48
49 break;
50 }
51 }
52 }
53 return super.visit(node, data);
54 }
55
56 }