01: package org.acm.seguin.pmd.symboltable;
02:
03: import net.sourceforge.jrefactory.ast.ASTFormalParameter;
04: import net.sourceforge.jrefactory.ast.ASTFormalParameters;
05: import net.sourceforge.jrefactory.ast.ASTMethodDeclarator;
06: import net.sourceforge.jrefactory.ast.SimpleNode;
07:
08: public class MethodNameDeclaration extends AbstractNameDeclaration
09: implements NameDeclaration {
10:
11: public MethodNameDeclaration(ASTMethodDeclarator node) {
12: super (node);
13: }
14:
15: public boolean equals(Object o) {
16: MethodNameDeclaration otherMethodDecl = (MethodNameDeclaration) o;
17:
18: // compare method name
19: if (!otherMethodDecl.node.getImage().equals(node.getImage())) {
20: return false;
21: }
22:
23: // compare parameter count - this catches the case where there are no params, too
24: if (((ASTMethodDeclarator) (otherMethodDecl.node))
25: .getParameterCount() != ((ASTMethodDeclarator) node)
26: .getParameterCount()) {
27: return false;
28: }
29:
30: // compare parameter types
31: ASTFormalParameters myParams = (ASTFormalParameters) node
32: .jjtGetFirstChild();
33: ASTFormalParameters otherParams = (ASTFormalParameters) otherMethodDecl.node
34: .jjtGetFirstChild();
35: for (int i = 0; i < ((ASTMethodDeclarator) node)
36: .getParameterCount(); i++) {
37: ASTFormalParameter myParam = (ASTFormalParameter) myParams
38: .jjtGetChild(i);
39: ASTFormalParameter otherParam = (ASTFormalParameter) otherParams
40: .jjtGetChild(i);
41: int myChildNo = myParam.skipAnnotations();
42: int otherChildNo = otherParam.skipAnnotations();
43: SimpleNode myTypeNode = (SimpleNode) myParam.jjtGetChild(
44: myChildNo).jjtGetFirstChild();
45: SimpleNode otherTypeNode = (SimpleNode) otherParam
46: .jjtGetChild(otherChildNo).jjtGetFirstChild();
47:
48: // simple comparison of type images
49: // this can be fooled by one method using "String"
50: // and the other method using "java.lang.String"
51: // once we get real types in here that should get fixed
52: if (!myTypeNode.getImage().equals(otherTypeNode.getImage())) {
53: return false;
54: }
55:
56: // if type is ASTPrimitiveType and is an array, make sure the other one is also
57: }
58: return true;
59: }
60:
61: public int hashCode() {
62: return node.getImage().hashCode()
63: + ((ASTMethodDeclarator) node).getParameterCount();
64: }
65:
66: public String toString() {
67: return "Method " + node.getImage() + ":" + node.getBeginLine();
68: }
69: }
|