KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > java > MethodMatchCriteria


1 package org.incava.java;
2
3 import java.util.*;
4 import net.sourceforge.pmd.ast.*;
5
6
7 /**
8  * A criterion (some criteria) for matching nodes.
9  */

10 public class MethodMatchCriteria extends MatchCriteria
11 {
12     private ASTMethodDeclaration meth;
13
14     private String JavaDoc name = null;
15
16     private ASTFormalParameters params = null;
17     
18     public MethodMatchCriteria(ASTMethodDeclaration m)
19     {
20         meth = m;
21     }
22
23     public double compare(MatchCriteria other)
24     {
25         if (other instanceof MethodMatchCriteria) {
26             MethodMatchCriteria mmother = (MethodMatchCriteria)other;
27             
28             // System.out.println("comparing " + hashCode() + " <=> " + other.hashCode());
29

30             String JavaDoc aName = getName();
31             String JavaDoc bName = mmother.getName();
32
33             double score = 0.0;
34
35             if (aName.equals(bName)) {
36                 ASTFormalParameters afp = getParameters();
37                 ASTFormalParameters bfp = mmother.getParameters();
38
39                 score = ParameterUtil.getMatchScore(afp, bfp);
40             }
41             else {
42                 // this could eventually find methods renamed, if we compare based
43
// on parameters and method contents
44
}
45
46             return score;
47
48         }
49         else {
50             return super.compare(other);
51         }
52     }
53
54     protected String JavaDoc getName()
55     {
56         if (name == null) {
57             name = MethodUtil.getName(meth).image;
58         }
59         return name;
60     }
61
62     protected ASTFormalParameters getParameters()
63     {
64         if (params == null) {
65             params = MethodUtil.getParameters(meth);
66         }
67         return params;
68     }
69
70 }
71
Popular Tags