01 package net.sourceforge.pmd.lang.java.symboltable;
02
03 import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
04 import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter;
05
06 import java.util.List;
07
08 public class OccurrenceFinder extends JavaParserVisitorAdapter {
09
10 public Object visit(ASTPrimaryExpression node, Object data) {
11 NameFinder nameFinder = new NameFinder(node);
12
13 // Maybe do some sort of State pattern thingy for when NameDeclaration
14 // is null/not null?
15 NameDeclaration decl = null;
16
17 List<NameOccurrence> names = nameFinder.getNames();
18 for (NameOccurrence occ: names) {
19 Search search = new Search(occ);
20 if (decl == null) {
21 // doing the first name lookup
22 search.execute();
23 decl = search.getResult();
24 if (decl == null) {
25 // we can't find it, so just give up
26 // when we decide to do full symbol resolution
27 // force this to either find a symbol or throw a SymbolNotFoundException
28 break;
29 }
30 } else {
31 // now we've got a scope we're starting with, so work from there
32 search.execute(decl.getScope());
33 decl = search.getResult();
34 }
35 }
36 return super.visit(node, data);
37 }
38
39 }
|