From 171c94385768ec118c4f8a8c870ff19a1abed85f Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Thu, 10 Oct 2002 12:21:05 +0000 Subject: [PATCH] refactoring to enable testing git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1098 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/symboltable/DeclarationFinder.java | 16 +++++++++ .../pmd/symboltable/ScopeCreator.java | 35 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pmd/src/net/sourceforge/pmd/symboltable/DeclarationFinder.java create mode 100644 pmd/src/net/sourceforge/pmd/symboltable/ScopeCreator.java diff --git a/pmd/src/net/sourceforge/pmd/symboltable/DeclarationFinder.java b/pmd/src/net/sourceforge/pmd/symboltable/DeclarationFinder.java new file mode 100644 index 0000000000..1203711061 --- /dev/null +++ b/pmd/src/net/sourceforge/pmd/symboltable/DeclarationFinder.java @@ -0,0 +1,16 @@ +/* + * User: tom + * Date: Oct 10, 2002 + * Time: 8:02:39 AM + */ +package net.sourceforge.pmd.symboltable; + +import net.sourceforge.pmd.ast.JavaParserVisitorAdapter; +import net.sourceforge.pmd.ast.ASTVariableDeclaratorId; + +public class DeclarationFinder extends JavaParserVisitorAdapter { + public Object visit(ASTVariableDeclaratorId node, Object data) { + node.getScope().addDeclaration(new NameDeclaration(node)); + return super.visit(node, data); + } +} diff --git a/pmd/src/net/sourceforge/pmd/symboltable/ScopeCreator.java b/pmd/src/net/sourceforge/pmd/symboltable/ScopeCreator.java new file mode 100644 index 0000000000..cc92d2af65 --- /dev/null +++ b/pmd/src/net/sourceforge/pmd/symboltable/ScopeCreator.java @@ -0,0 +1,35 @@ +/* + * User: tom + * Date: Oct 10, 2002 + * Time: 8:03:36 AM + */ +package net.sourceforge.pmd.symboltable; + +import net.sourceforge.pmd.ast.*; + +public class ScopeCreator extends JavaParserVisitorAdapter { + + private SymbolTable table = new SymbolTable(); + private ScopeFactory sf = new ScopeFactory(); + + public Object visit(ASTCompilationUnit node, Object data){openScope(node);return data;} + public Object visit(ASTUnmodifiedClassDeclaration 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;} + public Object visit(ASTMethodDeclaration node, Object data){openScope(node);return data;} + public Object visit(ASTTryStatement node, Object data){openScope(node);return data;} + public Object visit(ASTForStatement node, Object data){openScope(node);return data;} + public Object visit(ASTIfStatement node, Object data){openScope(node);return data;} + + private void openScope(SimpleNode node) { + Scope scope = sf.createScope(node); + if (scope instanceof NullScope) { + super.visit(node, null); + } else { + table.push(scope); + node.setScope(table.peek()); + super.visit(node, null); + table.pop(); + } + } +}