1 package net.sourceforge.pmd.symboltable;
2
3 import net.sourceforge.pmd.ast.ASTCompilationUnit;
4 import net.sourceforge.pmd.ast.ASTPrimaryExpression;
5 import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
6
7 import java.util.Iterator;
8
9 public class SymbolFacade extends JavaParserVisitorAdapter {
10
11 public void initializeWith(ASTCompilationUnit node) {
12 // first, traverse the AST and create all the scopes
13 BasicScopeCreationVisitor sc = new BasicScopeCreationVisitor(new BasicScopeFactory());
14 node.jjtAccept(sc, null);
15
16 // traverse the AST and pick up all the declarations
17 DeclarationFinder df = new DeclarationFinder();
18 node.jjtAccept(df, null);
19
20 // finally, traverse the AST and pick up all the name occurrences
21 node.jjtAccept(this, null);
22 }
23
24 public Object visit(ASTPrimaryExpression node, Object data) {
25 NameOccurrences qualifiedNames = new NameOccurrences(node);
26 NameDeclaration decl = null;
27 for (Iterator i = qualifiedNames.iterator(); i.hasNext();) {
28 NameOccurrence occ = (NameOccurrence) i.next();
29 Search search = new Search(occ);
30 if (decl == null) {
31 // doing the first name lookup
32 search.execute();
33 decl = search.getResult();
34 if (decl == null) {
35 // we can't find it, so just give up
36 // when we decide searches across compilation units like a compiler would, we'll
37 // force this to either find a symbol or throw a "cannot resolve symbol" Exception
38 break;
39 }
40 } else {
41 // now we've got a scope we're starting with, so work from there
42 search.execute(decl.getScope());
43 decl = search.getResult();
44 }
45 }
46 return super.visit(node, data);
47 }
48
49 }
This page was automatically generated by Maven