1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd.symboltable; |
5 |
| |
6 |
| import net.sourceforge.pmd.ast.ASTFormalParameter; |
7 |
| import net.sourceforge.pmd.ast.ASTFormalParameters; |
8 |
| import net.sourceforge.pmd.ast.ASTMethodDeclarator; |
9 |
| import net.sourceforge.pmd.ast.ASTPrimitiveType; |
10 |
| import net.sourceforge.pmd.ast.SimpleNode; |
11 |
| |
12 |
| public class MethodNameDeclaration extends AbstractNameDeclaration { |
13 |
| |
14 |
1090
| public MethodNameDeclaration(ASTMethodDeclarator node) {
|
15 |
1090
| super(node);
|
16 |
| } |
17 |
| |
18 |
291
| public int getParameterCount() {
|
19 |
291
| return ((ASTMethodDeclarator) node).getParameterCount();
|
20 |
| } |
21 |
| |
22 |
14
| public ASTMethodDeclarator getMethodNameDeclaratorNode() {
|
23 |
14
| return (ASTMethodDeclarator) node;
|
24 |
| } |
25 |
| |
26 |
7
| public String getParameterDisplaySignature() {
|
27 |
7
| StringBuffer sb = new StringBuffer("(");
|
28 |
7
| ASTFormalParameters params = (ASTFormalParameters) node.jjtGetChild(0);
|
29 |
| |
30 |
| |
31 |
7
| for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
|
32 |
4
| ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i);
|
33 |
4
| sb.append(p.getTypeNode().getTypeImage());
|
34 |
4
| sb.append(',');
|
35 |
| } |
36 |
7
| if (sb.charAt(sb.length() - 1) == ',') {
|
37 |
3
| sb.deleteCharAt(sb.length() - 1);
|
38 |
| } |
39 |
7
| sb.append(')');
|
40 |
7
| return sb.toString();
|
41 |
| } |
42 |
| |
43 |
5
| public boolean equals(Object o) {
|
44 |
5
| MethodNameDeclaration other = (MethodNameDeclaration) o;
|
45 |
| |
46 |
| |
47 |
5
| if (!other.node.getImage().equals(node.getImage())) {
|
48 |
0
| return false;
|
49 |
| } |
50 |
| |
51 |
| |
52 |
5
| if (((ASTMethodDeclarator) (other.node)).getParameterCount() != ((ASTMethodDeclarator) node).getParameterCount()) {
|
53 |
0
| return false;
|
54 |
| } |
55 |
| |
56 |
| |
57 |
5
| ASTFormalParameters myParams = (ASTFormalParameters) node.jjtGetChild(0);
|
58 |
5
| ASTFormalParameters otherParams = (ASTFormalParameters) other.node.jjtGetChild(0);
|
59 |
5
| for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
|
60 |
3
| ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
|
61 |
3
| ASTFormalParameter otherParam = (ASTFormalParameter) otherParams.jjtGetChild(i);
|
62 |
| |
63 |
3
| SimpleNode myTypeNode = (SimpleNode) myParam.getTypeNode().jjtGetChild(0);
|
64 |
3
| SimpleNode otherTypeNode = (SimpleNode) otherParam.getTypeNode().jjtGetChild(0);
|
65 |
| |
66 |
| |
67 |
3
| if (myTypeNode.getClass() != otherTypeNode.getClass()) {
|
68 |
0
| return false;
|
69 |
| } |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
3
| String myTypeImg;
|
76 |
3
| String otherTypeImg;
|
77 |
3
| if (myTypeNode instanceof ASTPrimitiveType) {
|
78 |
0
| myTypeImg = myTypeNode.getImage();
|
79 |
0
| otherTypeImg = otherTypeNode.getImage();
|
80 |
| } else { |
81 |
3
| myTypeImg = ((SimpleNode) (myTypeNode.jjtGetChild(0))).getImage();
|
82 |
3
| otherTypeImg = ((SimpleNode) (otherTypeNode.jjtGetChild(0))).getImage();
|
83 |
| } |
84 |
| |
85 |
3
| if (!myTypeImg.equals(otherTypeImg)) {
|
86 |
2
| return false;
|
87 |
| } |
88 |
| |
89 |
| |
90 |
| } |
91 |
3
| return true;
|
92 |
| } |
93 |
| |
94 |
1240
| public int hashCode() {
|
95 |
1240
| return node.getImage().hashCode() + ((ASTMethodDeclarator) node).getParameterCount();
|
96 |
| } |
97 |
| |
98 |
0
| public String toString() {
|
99 |
0
| return "Method " + node.getImage() + ", line " + node.getBeginLine() + ", params = " + ((ASTMethodDeclarator) node).getParameterCount();
|
100 |
| } |
101 |
| } |