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