1 package xdoclet.retest.util; 2 3 import xdoclet.XDocletException; 4 import xdoclet.retest.XDocletRetestMessages; 5 6 import java.util.List ; 7 import java.util.ArrayList ; 8 import java.lang.reflect.Method ; 9 10 15 public abstract class AbstractClassAndInterfaceComparator 16 extends AbstractComparator 17 { 18 19 protected Class one; 20 protected Class two; 21 22 24 public AbstractClassAndInterfaceComparator(Class one, Class two) 25 { 26 super(); 27 this.one = one; 28 this.two = two; 29 resultSet = new ComparisonResultSet(); 30 } 31 32 34 public ComparisonResultSet compareClassSignature() 35 throws XDocletException 36 { 37 compareInterfaces(); 38 compareClass(); 39 return resultSet; 40 } 41 42 public ComparisonResultSet compareClassMethodsSignature() 43 throws XDocletException 44 { 45 Method [] oneMs = one.getDeclaredMethods(); 46 Method [] twoMs = two.getDeclaredMethods(); 47 compareMethodSignatureOneByOne(oneMs,twoMs); 48 compareMethodSignatureOneByOne(twoMs,oneMs); 49 return resultSet; 50 } 51 52 54 private void compareInterfaces() 55 throws XDocletException 56 { 57 Class [] oneIFs = one.getInterfaces(); 58 Class [] twoIFs = two.getInterfaces(); 59 if (oneIFs.length != twoIFs.length) 60 { 61 resultSet.addError(XDocletRetestMessages.MISMATCH_NUMBER_INTERFACE,new String [] {one.getName(),two.getName()}); 62 } 63 compareInterfacesOneByOne(oneIFs,twoIFs); 64 compareInterfacesOneByOne(twoIFs,oneIFs); 65 } 66 67 private void compareInterfacesOneByOne(Class [] oneIFs,Class [] twoIFs) 68 throws XDocletException 69 { 70 for (int i = 0; i<oneIFs.length; i++){ 71 boolean found = false; 72 for (int j = 0; j<twoIFs.length; j++){ 73 if (oneIFs[i].getName().equals(twoIFs[j].getName())){ 74 found = true; 75 break; 76 } 77 } 78 if ( ! found ){ 79 resultSet.addError(XDocletRetestMessages.INTERFACE_DEFINED_ONLY_IN,new String [] {oneIFs[i].getName(),two.getName()}); 80 } 81 } 82 } 83 84 private void compareClass(){ 85 if (one.isInterface() && two.isInterface()) 86 return; 87 } 89 90 private void compareMethodSignatureOneByOne(Method [] oneMs,Method [] twoMs) 91 throws XDocletException 92 { 93 for (int i = 0 ; i < oneMs.length; i++) 94 { 95 boolean found = false; 96 for (int j=0;j<twoMs.length;j++) 97 { 98 MethodComparator comp = new MethodComparator(oneMs[i],twoMs[j]); 99 ComparisonResultSet resultSet = comp.compare(); 100 if ( ! resultSet.error()) 101 { 102 found = true; 103 break; 104 } 105 } 106 if ( ! found ) 107 { 108 resultSet.addError(XDocletRetestMessages.METHOD_DEFINED_ONLY_IN,new String [] {shortMethodName(oneMs[i]),two.getName()}); 109 } 110 } 111 } 112 113 } 114 | Popular Tags |