1 package xdoclet.retest.util; 2 3 import xdoclet.XDocletException; 4 import xdoclet.retest.XDocletRetestMessages; 5 6 import java.lang.reflect.Method ; 7 8 13 public class MethodComparator 14 extends AbstractComparator 15 { 16 protected Method one; 17 protected Method two; 18 protected ComparisonResultSet resultSet; 19 20 public MethodComparator(Method one,Method 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 [] {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 [] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())}); 39 return resultSet; 40 } 41 Class [] onePs = one.getParameterTypes(); 42 Class [] twoPs = two.getParameterTypes(); 43 if (onePs.length != twoPs.length) 44 { 45 resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_NUMBER_OF_PARAM,new String [] {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 [] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())}); 52 return resultSet; 53 } 54 } 55 Class [] oneEs = one.getExceptionTypes(); 56 Class [] twoEs = two.getExceptionTypes(); 57 if (oneEs.length != twoEs.length) 58 { 59 resultSet.addError(XDocletRetestMessages.METHOD_DOES_NOT_HAVE_SAME_NUMBER_OF_EXCEPTIONS,new String [] {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 [] {one.getName(),shortClassName(one.getDeclaringClass()),shortClassName(two.getDeclaringClass())}); 66 return resultSet; 67 } 68 } 69 70 return resultSet; 71 } 72 73 74 } | Popular Tags |