1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package net.sourceforge.pmd.symboltable; 5 6 import net.sourceforge.pmd.ast.ASTFormalParameter; 7 import net.sourceforge.pmd.ast.ASTVariableDeclaratorId; 8 import net.sourceforge.pmd.ast.AccessNode; 9 10 public class VariableNameDeclaration extends AbstractNameDeclaration implements NameDeclaration { 11 12 public VariableNameDeclaration(ASTVariableDeclaratorId node) { 13 super(node); 14 } 15 16 public Scope getScope() { 17 return node.getScope().getEnclosingClassScope(); 18 } 19 20 public boolean isArray() { 21 return ((ASTVariableDeclaratorId)node).getTypeNode().isArray(); 22 } 23 24 public boolean isExceptionBlockParameter() { 25 return ((ASTVariableDeclaratorId) node).isExceptionBlockParameter(); 26 } 27 28 public AccessNode getAccessNodeParent() { 29 if (node.jjtGetParent() instanceof ASTFormalParameter) { 30 return (AccessNode)node.jjtGetParent(); 31 } 32 return (AccessNode) node.jjtGetParent().jjtGetParent(); 33 } 34 35 public ASTVariableDeclaratorId getDeclaratorId() { 36 return (ASTVariableDeclaratorId) node; 37 } 38 39 public boolean equals(Object o) { 40 VariableNameDeclaration n = (VariableNameDeclaration) o; 41 return n.node.getImage().equals(node.getImage()); 42 } 43 44 public int hashCode() { 45 return node.getImage().hashCode(); 46 } 47 48 public String toString() { 49 return "Variable symbol " + node.getImage() + " line " + node.getBeginLine(); 50 } 51 }