KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > retest > util > MethodComparator


1 package xdoclet.retest.util;
2
3 import xdoclet.XDocletException;
4 import xdoclet.retest.XDocletRetestMessages;
5
6 import java.lang.reflect.Method JavaDoc;
7
8 /**
9  * @author Vincent Harcq (vincent.harcq@hubmethods.com)
10  * @created Mars 5, 2002
11  * @version $Revision: 1.3 $
12  */

13 public class MethodComparator
14 extends AbstractComparator
15 {
16     protected Method JavaDoc one;
17     protected Method JavaDoc two;
18     protected ComparisonResultSet resultSet;
19
20     public MethodComparator(Method JavaDoc one,Method JavaDoc two)
21     {
22         super();
23         this.one = one;
24         this.two = two;
25         resultSet = new ComparisonResultSet();
26     }
27
28     public ComparisonResultSet compare()
29     throws XDocletException
30     {
31         if ( ! one.getName().equals(two.getName()))
32         {
33             resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_NAME,new String JavaDoc[] {one.getName(),two.getName()});
34             return resultSet;
35         }
36         if ( ! shortClassName(one.getReturnType()).equals(shortClassName(two.getReturnType())))
37         {
38             resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_RETURN_TYPE,new String JavaDoc[] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())});
39             return resultSet;
40         }
41         Class JavaDoc[] onePs = one.getParameterTypes();
42         Class JavaDoc[] twoPs = two.getParameterTypes();
43         if (onePs.length != twoPs.length)
44         {
45             resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_NUMBER_OF_PARAM,new String JavaDoc[] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())});
46             return resultSet;
47         }
48         for (int i=0; i<onePs.length; i++)
49         {
50             if ( ! shortClassName(onePs[i]).equals(shortClassName(twoPs[i]))){
51                 resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_TYPE_OF_PARAM,new String JavaDoc[] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())});
52                 return resultSet;
53             }
54         }
55         Class JavaDoc[] oneEs = one.getExceptionTypes();
56         Class JavaDoc[] twoEs = two.getExceptionTypes();
57         if (oneEs.length != twoEs.length)
58         {
59             resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_NUMBER_OF_EXCEPTIONS,new String JavaDoc[] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())});
60             return resultSet;
61         }
62         for (int i=0; i<oneEs.length; i++)
63         {
64             if ( ! shortClassName(oneEs[i]).equals(shortClassName(twoEs[i]))){
65                 resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_TYPE_OF_EXCEPTIONS,new String JavaDoc[] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())});
66                 return resultSet;
67             }
68         }
69
70         return resultSet;
71     }
72
73
74 }
Popular Tags