01: package org.incava.java;
02:
03: import java.util.*;
04: import net.sourceforge.pmd.ast.*;
05:
06: /**
07: * A criterion (some criteria) for matching nodes.
08: */
09: public class MethodMatchCriteria extends MatchCriteria {
10: private ASTMethodDeclaration meth;
11:
12: private String name = null;
13:
14: private ASTFormalParameters params = null;
15:
16: public MethodMatchCriteria(ASTMethodDeclaration m) {
17: meth = m;
18: }
19:
20: public double compare(MatchCriteria other) {
21: if (other instanceof MethodMatchCriteria) {
22: MethodMatchCriteria mmother = (MethodMatchCriteria) other;
23:
24: // System.out.println("comparing " + hashCode() + " <=> " + other.hashCode());
25:
26: String aName = getName();
27: String bName = mmother.getName();
28:
29: double score = 0.0;
30:
31: if (aName.equals(bName)) {
32: ASTFormalParameters afp = getParameters();
33: ASTFormalParameters bfp = mmother.getParameters();
34:
35: score = ParameterUtil.getMatchScore(afp, bfp);
36: } else {
37: // this could eventually find methods renamed, if we compare based
38: // on parameters and method contents
39: }
40:
41: return score;
42:
43: } else {
44: return super .compare(other);
45: }
46: }
47:
48: protected String getName() {
49: if (name == null) {
50: name = MethodUtil.getName(meth).image;
51: }
52: return name;
53: }
54:
55: protected ASTFormalParameters getParameters() {
56: if (params == null) {
57: params = MethodUtil.getParameters(meth);
58: }
59: return params;
60: }
61:
62: }
|