From cf55ee08afaed77a7eee0b8f73d80795d8d861da Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Thu, 3 Oct 2002 15:36:03 +0000 Subject: [PATCH] more stuff gets winnowed away as the Scope hierarchy grows git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1056 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/symboltable/SymbolFacade.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/symboltable/SymbolFacade.java b/pmd/src/net/sourceforge/pmd/symboltable/SymbolFacade.java index b986b33926..3706cf4da8 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/SymbolFacade.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/SymbolFacade.java @@ -16,6 +16,8 @@ public class SymbolFacade extends JavaParserVisitorAdapter { private Set localScopeTriggers = new HashSet(); private Set classScopeTriggers = new HashSet(); + private Set globalScopeTriggers = new HashSet(); + private ContextManager contextManager; private LookupController lookupController; @@ -24,7 +26,6 @@ public class SymbolFacade extends JavaParserVisitorAdapter { SymbolTable symbolTable = new SymbolTable(); contextManager = new ContextManagerImpl(symbolTable); lookupController = new LookupController(symbolTable); - contextManager.openScope(new GlobalScope()); } private void initScopeTriggers() { @@ -37,12 +38,15 @@ public class SymbolFacade extends JavaParserVisitorAdapter { localScopeTriggers.add(ASTIfStatement.class); classScopeTriggers.add(ASTClassBody.class); + + globalScopeTriggers.add(ASTCompilationUnit.class); } public void initializeWith(ASTCompilationUnit node) { node.jjtAccept(this, null); } + public Object visit(ASTCompilationUnit node, Object data){openScope(node);return data;} public Object visit(ASTClassBody node, Object data){openScope(node);return data;} public Object visit(ASTBlock node, Object data){openScope(node);return data;} public Object visit(ASTConstructorDeclaration node, Object data){openScope(node);return data;} @@ -52,10 +56,6 @@ public class SymbolFacade extends JavaParserVisitorAdapter { public Object visit(ASTForStatement node, Object data){openScope(node);return data;} public Object visit(ASTIfStatement node, Object data){openScope(node);return data;} - /** - * Note the current scope is responsible for figuring out what kind of - * NameDeclaration this is - */ public Object visit(ASTVariableDeclaratorId node, Object data) { node.setScope(contextManager.getCurrentScope()); contextManager.getCurrentScope().addDeclaration(new NameDeclaration(node)); @@ -81,6 +81,10 @@ public class SymbolFacade extends JavaParserVisitorAdapter { contextManager.openScope(new ClassScope()); super.visit(node, null); contextManager.leaveScope(); + } else if (globalScopeTriggers.contains(node.getClass())) { + contextManager.openScope(new GlobalScope()); + super.visit(node, null); + contextManager.leaveScope(); } else { super.visit(node, null); }