01: package org.acm.seguin.pmd.symboltable;
02:
03: import net.sourceforge.jrefactory.ast.SimpleNode;
04:
05: import java.util.HashSet;
06: import java.util.Iterator;
07: import java.util.Set;
08: import java.util.Stack;
09:
10: public class BasicScopeFactory implements ScopeFactory {
11:
12: private Set scopeEvaluators = new HashSet();
13:
14: public BasicScopeFactory() {
15: scopeEvaluators.add(new GlobalScopeEvaluator());
16: scopeEvaluators.add(new ClassScopeEvaluator());
17: scopeEvaluators.add(new MethodScopeEvaluator());
18: scopeEvaluators.add(new LocalScopeEvaluator());
19: }
20:
21: public void openScope(Stack scopes, SimpleNode node) {
22: for (Iterator i = scopeEvaluators.iterator(); i.hasNext();) {
23: ScopeEvaluator ev = (ScopeEvaluator) i.next();
24: if (ev.isScopeCreatedBy(node)) {
25: Scope scope = ev.getScopeFor(node);
26: if (!(scope instanceof GlobalScope)) {
27: scope.setParent((Scope) scopes.peek());
28: }
29: scopes.add(scope);
30: node
31: .setScope((net.sourceforge.jrefactory.ast.Scope) scopes
32: .peek());
33: break;
34: }
35: }
36: }
37:
38: }
|