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