1 package net.sourceforge.pmd.symboltable;
2
3 import net.sourceforge.pmd.ast.ASTFormalParameter;
4 import net.sourceforge.pmd.ast.ASTFormalParameters;
5 import net.sourceforge.pmd.ast.ASTMethodDeclarator;
6 import net.sourceforge.pmd.ast.SimpleNode;
7
8 public class MethodNameDeclaration extends AbstractNameDeclaration implements NameDeclaration {
9
10 public MethodNameDeclaration(ASTMethodDeclarator node) {
11 super(node);
12 }
13
14 public boolean equals(Object o) {
15 MethodNameDeclaration otherMethodDecl = (MethodNameDeclaration) o;
16
17 // compare method name
18 if (!otherMethodDecl.node.getImage().equals(node.getImage())) {
19 return false;
20 }
21
22 // compare parameter count - this catches the case where there are no params, too
23 if (((ASTMethodDeclarator) (otherMethodDecl.node)).getParameterCount() != ((ASTMethodDeclarator) node).getParameterCount()) {
24 return false;
25 }
26
27 // compare parameter types
28 ASTFormalParameters myParams = (ASTFormalParameters) node.jjtGetChild(0);
29 ASTFormalParameters otherParams = (ASTFormalParameters) otherMethodDecl.node.jjtGetChild(0);
30 for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
31 ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
32 ASTFormalParameter otherParam = (ASTFormalParameter) otherParams.jjtGetChild(i);
33 SimpleNode myTypeNode = (SimpleNode) myParam.jjtGetChild(0).jjtGetChild(0);
34 SimpleNode otherTypeNode = (SimpleNode) otherParam.jjtGetChild(0).jjtGetChild(0);
35
36 // simple comparison of type images
37 // this can be fooled by one method using "String"
38 // and the other method using "java.lang.String"
39 // once we get real types in here that should get fixed
40 if (!myTypeNode.getImage().equals(otherTypeNode.getImage())) {
41 return false;
42 }
43
44 // if type is ASTPrimitiveType and is an array, make sure the other one is also
45 }
46 return true;
47 }
48
49 public int hashCode() {
50 return node.getImage().hashCode() + ((ASTMethodDeclarator) node).getParameterCount();
51 }
52
53 public String toString() {
54 return "Method " + node.getImage() + ":" + node.getBeginLine();
55 }
56 }
This page was automatically generated by Maven