refactoring
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1078 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -27,6 +27,9 @@ public class NameDeclarationTest extends TestCase {
|
||||
assertEquals(10, decl.getLine());
|
||||
assertEquals("foo", decl.getImage());
|
||||
assertEquals(decl, new NameDeclaration(node));
|
||||
assertTrue(!decl.isExceptionBlockParameter());
|
||||
decl.setExceptionBlockParameter(true);
|
||||
assertTrue(decl.isExceptionBlockParameter());
|
||||
}
|
||||
|
||||
public void testConstructor() {
|
||||
|
@ -42,10 +42,9 @@ public class SimpleNode implements Node {
|
||||
if (scope == null) {
|
||||
throw new RuntimeException("No scope set on " + this);
|
||||
}
|
||||
return this.scope;
|
||||
return scope;
|
||||
}
|
||||
|
||||
|
||||
public void jjtClose() {
|
||||
if ((children == null) || (children.length == 0)){
|
||||
beginLine = parser.token.beginLine;
|
||||
|
@ -14,8 +14,9 @@ public class LocalScope extends AbstractScope implements Scope {
|
||||
private Map names = new HashMap();
|
||||
|
||||
public void addDeclaration(NameDeclaration nameDecl) {
|
||||
// this declaration needs to go somewhere... should this be delegated to a higher scope?
|
||||
if (nameDecl.getNode().jjtGetParent() instanceof ASTFormalParameter) {
|
||||
if (nameDecl.isExceptionBlockParameter()) {
|
||||
// this declaration needs to go somewhere... should this be delegated to the next
|
||||
// highest LocalScope?
|
||||
return;
|
||||
}
|
||||
if (names.containsKey(nameDecl)) {
|
||||
|
@ -10,13 +10,18 @@ import net.sourceforge.pmd.ast.SimpleNode;
|
||||
public class NameDeclaration {
|
||||
|
||||
private SimpleNode node;
|
||||
private boolean isExceptionBlockParameter;
|
||||
|
||||
public NameDeclaration(SimpleNode node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public SimpleNode getNode() {
|
||||
return node;
|
||||
public void setExceptionBlockParameter(boolean isExceptionBlockParameter) {
|
||||
this.isExceptionBlockParameter = isExceptionBlockParameter;
|
||||
}
|
||||
|
||||
public boolean isExceptionBlockParameter() {
|
||||
return isExceptionBlockParameter;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
|
@ -36,7 +36,9 @@ public class SymbolFacade extends JavaParserVisitorAdapter {
|
||||
|
||||
public Object visit(ASTVariableDeclaratorId node, Object data) {
|
||||
node.setScope(contextManager.getCurrentScope());
|
||||
contextManager.getCurrentScope().addDeclaration(new NameDeclaration(node));
|
||||
NameDeclaration nameDeclaration = new NameDeclaration(node);
|
||||
nameDeclaration.setExceptionBlockParameter(node.jjtGetParent().jjtGetParent() instanceof ASTTryStatement);
|
||||
contextManager.getCurrentScope().addDeclaration(nameDeclaration);
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user