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:
@ -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);
|
||||
}
|
||||
}
|
35
pmd/src/net/sourceforge/pmd/symboltable/ScopeCreator.java
Normal file
35
pmd/src/net/sourceforge/pmd/symboltable/ScopeCreator.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user