(release 3.1)
The implementation of class CtMethod regards a seed and its redefinitions as equals. This can cause problems when their CtMethod objects are stored in a Collection or used as keys in a Map. It would be more useful if the implementation would (also) pass the following testcase :
import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import javassist.NotFoundException; import junit.framework.TestCase; public class CtMethodTest extends TestCase { public void testEquals() throws NotFoundException { ClassPool cp=ClassPool.getDefault(); CtClass object=cp.get("java.lang.Object"); CtClass string=cp.get("java.lang.String"); CtMethod seed=object.getDeclaredMethod("equals"); CtMethod redefinition=string.getDeclaredMethod("equals"); assertFalse("declaring class different", seed.getDeclaringClass().equals(redefinition.getDeclaringClass())); assertFalse("CtMethod object different", seed.equals(redefinition)); } }
final String getStringRep() { if (cachedStringRep == null) cachedStringRep = methodInfo.getName() + Descriptor.getParamDescriptor(methodInfo.getDescriptor()); return cachedStringRep; }
final String getStringRep() { if (cachedStringRep == null) cachedStringRep = this.getDeclaringClass().getName() + "#" + methodInfo.getName() + Descriptor.getParamDescriptor(methodInfo.getDescriptor()); return cachedStringRep; }