View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.plsql.symboltable;
5   
6   import java.util.logging.Logger;
7   
8   import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclaratorId;
9   import net.sourceforge.pmd.lang.symboltable.AbstractNameDeclaration;
10  import net.sourceforge.pmd.lang.symboltable.Scope;
11  
12  public class VariableNameDeclaration extends AbstractNameDeclaration {
13     private final static Logger LOGGER = Logger.getLogger(VariableNameDeclaration.class.getName()); 
14  
15      public VariableNameDeclaration(ASTVariableOrConstantDeclaratorId node) {
16  	super(node);
17      }
18  
19      @Override
20      public Scope getScope() {
21  	try {
22  	  return node.getScope().getEnclosingScope(ClassScope.class);
23  	}
24  	catch (Exception e)
25  	{
26  	  LOGGER.finest("This Node does not have an enclosing Class: "
27  		              + node.getBeginLine() + "/" + node.getBeginColumn()
28  		              + " => " + this.getImage()
29  		             );
30            return null; //@TODO SRT a cop-out 
31  	}
32      }
33  
34      public ASTVariableOrConstantDeclaratorId getDeclaratorId() {
35  	return (ASTVariableOrConstantDeclaratorId) node;
36      }
37  
38  
39      @Override
40      public boolean equals(Object o) {
41          if (!(o instanceof VariableNameDeclaration)) {
42              return false;
43          }
44  	VariableNameDeclaration n = (VariableNameDeclaration) o;
45  	try
46  	{
47  	return n.getImage().equals(this.getImage());
48  	}
49  	catch (Exception e)
50  	{
51  		e.printStackTrace(System.err);
52  		LOGGER.finest("n.node="+n.node);
53  		LOGGER.finest("n.getImage="+n.getImage());
54  		LOGGER.finest("node="+node);
55  		LOGGER.finest("this.getImage="+this.getImage());
56  		return false;
57  	}
58      }
59  
60      @Override
61      public int hashCode() {
62  	try
63  	{
64  	  return this.getImage().hashCode();
65  	}
66  	catch(Exception e)
67  	{
68  		LOGGER.finest("VariableNameDeclaration: node="
69  			           +node
70  			);
71  		LOGGER.finest("VariableNameDeclaration: node,getImage="
72  			           +this.getImage()
73  			);
74  		return 0;
75  	}
76      }
77  
78      @Override
79      public String toString() {
80  	return "Variable: image = '" + node.getImage() + "', line = " + node.getBeginLine();
81      }
82  }