View Javadoc
1 package net.sourceforge.pmd.symboltable; 2 3 public class Search { 4 private static final boolean TRACE = false; 5 6 private NameOccurrence occ; 7 private NameDeclaration decl; 8 9 public Search(NameOccurrence occ) { 10 if (TRACE) 11 System.out.println("new search for " + occ); 12 this.occ = occ; 13 } 14 15 public void execute() { 16 decl = searchUpward(occ, occ.getScope()); 17 if (TRACE) 18 System.out.println("found " + decl); 19 } 20 21 public void execute(Scope startingScope) { 22 decl = searchUpward(occ, startingScope); 23 if (TRACE) 24 System.out.println("found " + decl); 25 } 26 27 public NameDeclaration getResult() { 28 return decl; 29 } 30 31 private NameDeclaration searchUpward(NameOccurrence nameOccurrence, Scope scope) { 32 if (!scope.contains(nameOccurrence) && scope.getParent() != null) { 33 if (TRACE) 34 System.out.println("moving up fm " + scope + " to " + scope.getParent()); 35 return searchUpward(nameOccurrence, scope.getParent()); 36 } 37 if (scope.contains(nameOccurrence)) { 38 return scope.addVariableNameOccurrence(nameOccurrence); 39 } 40 return null; 41 } 42 }

This page was automatically generated by Maven