refactoring to enable testing

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1098 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-10-10 12:21:05 +00:00
parent 0b442cd4e0
commit 171c943857
2 changed files with 51 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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();
}
}
}