View Javadoc

    1   package net.sourceforge.pmd.symboltable;
    2
    3   import net.sourceforge.pmd.ast.ASTPrimaryExpression;
    4   import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
    5
    6   import java.util.List;
    7
    8   public class OccurrenceFinder extends JavaParserVisitorAdapter {
    9
    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  }