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.ast.Node;
10 import net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter;
11 import net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameters;
12 import net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclarator;
13 import net.sourceforge.pmd.lang.plsql.ast.ASTTriggerTimingPointSection;
14 import net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode;
15 import net.sourceforge.pmd.lang.symboltable.AbstractNameDeclaration;
16
17 public class MethodNameDeclaration extends AbstractNameDeclaration {
18 private final static Logger LOGGER = Logger.getLogger(MethodNameDeclaration.class.getName());
19
20 public MethodNameDeclaration(ASTMethodDeclarator node) {
21 super(node);
22 }
23
24
25
26
27
28
29
30 public MethodNameDeclaration(ASTTriggerTimingPointSection node) {
31 super(node);
32 }
33
34 public int getParameterCount() {
35 return ((ASTMethodDeclarator) node).getParameterCount();
36 }
37
38
39
40
41
42
43 public boolean isVarargs() {
44 return false;
45 }
46
47 public ASTMethodDeclarator getMethodNameDeclaratorNode() {
48 return (ASTMethodDeclarator) node;
49 }
50
51 public String getParameterDisplaySignature() {
52 StringBuilder sb = new StringBuilder("(");
53 ASTFormalParameters params = (ASTFormalParameters) node.jjtGetChild(0);
54
55
56 for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
57 ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i);
58 sb.append(p.getTypeNode().getTypeImage());
59
60
61
62 sb.append(',');
63 }
64 if (sb.charAt(sb.length() - 1) == ',') {
65 sb.deleteCharAt(sb.length() - 1);
66 }
67 sb.append(')');
68 return sb.toString();
69 }
70
71 @Override
72 public boolean equals(Object o) {
73 if (!(o instanceof MethodNameDeclaration)) {
74 return false;
75 }
76
77 MethodNameDeclaration other = (MethodNameDeclaration) o;
78
79
80 if (!other.node.getImage().equals(node.getImage())) {
81 return false;
82 }
83
84
85
86 if (((ASTMethodDeclarator) other.node).getParameterCount() != ((ASTMethodDeclarator) node).getParameterCount()) {
87 return false;
88 }
89
90
91
92
93
94
95 ASTFormalParameters myParams = node.getFirstDescendantOfType(ASTFormalParameters.class);
96 ASTFormalParameters otherParams = other.node.getFirstDescendantOfType(ASTFormalParameters.class);
97 for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
98 ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
99 ASTFormalParameter otherParam = (ASTFormalParameter) otherParams.jjtGetChild(i);
100
101
102
103
104
105
106 Node myTypeNode = myParam.getTypeNode().jjtGetChild(0);
107 Node otherTypeNode = otherParam.getTypeNode().jjtGetChild(0);
108
109
110 if (myTypeNode.getClass() != otherTypeNode.getClass()) {
111 return false;
112 }
113
114
115
116
117
118 String myTypeImg;
119 String otherTypeImg;
120
121
122
123
124 myTypeImg = ((AbstractPLSQLNode) myTypeNode.jjtGetChild(0)).getImage();
125 otherTypeImg = ((AbstractPLSQLNode) otherTypeNode.jjtGetChild(0)).getImage();
126
127
128 if (!myTypeImg.equals(otherTypeImg)) {
129 return false;
130 }
131
132
133
134 }
135 return true;
136 }
137
138 @Override
139 public int hashCode() {
140 try {
141 return node.hashCode();
142
143
144 } catch (Exception e) {
145 if (LOGGER.isLoggable(Level.FINEST)) {
146 LOGGER.finest("MethodNameDeclaration problem for " + node + " of class "
147 + node.getClass().getCanonicalName() + " => " + node.getBeginLine() + "/"
148 + node.getBeginColumn());
149 }
150
151 return 0;
152 }
153 }
154
155 @Override
156 public String toString() {
157
158
159
160 return node.toString();
161 }
162 }