private String fixTypes2( ArrayList<TypeVar> scc, HashSet<String> lowersSet, org.hotswap.agent.javassist.ClassPool cp) throws org.hotswap.agent.javassist.NotFoundException { Iterator<String> it = lowersSet.iterator(); if (lowersSet.size() == 0) { return null; // only NullType } else if (lowersSet.size() == 1) { return it.next(); } else { org.hotswap.agent.javassist.CtClass cc = cp.get(it.next()); while (it.hasNext()) { cc = commonSuperClassEx(cc, cp.get(it.next())); } if (cc.getSuperclass() == null || isObjectArray(cc)) { cc = fixByUppers(scc, cp, new HashSet<TypeVar>(), cc); } if (cc.isArray()) { return org.hotswap.agent.javassist.bytecode.Descriptor.toJvmName(cc); } else { return cc.getName(); } } }
/** * Finds the most specific common super class of the given classes. This method is a copy from * Type. */ public static org.hotswap.agent.javassist.CtClass commonSuperClass( org.hotswap.agent.javassist.CtClass one, org.hotswap.agent.javassist.CtClass two) throws org.hotswap.agent.javassist.NotFoundException { org.hotswap.agent.javassist.CtClass deep = one; org.hotswap.agent.javassist.CtClass shallow = two; org.hotswap.agent.javassist.CtClass backupShallow = shallow; org.hotswap.agent.javassist.CtClass backupDeep = deep; // Phase 1 - Find the deepest hierarchy, set deep and shallow correctly for (; ; ) { // In case we get lucky, and find a match early if (eq(deep, shallow) && deep.getSuperclass() != null) { return deep; } org.hotswap.agent.javassist.CtClass deepSuper = deep.getSuperclass(); org.hotswap.agent.javassist.CtClass shallowSuper = shallow.getSuperclass(); if (shallowSuper == null) { // right, now reset shallow shallow = backupShallow; break; } if (deepSuper == null) { // wrong, swap them, since deep is now useless, its our tmp // before we swap it deep = backupDeep; backupDeep = backupShallow; backupShallow = deep; deep = shallow; shallow = backupShallow; break; } deep = deepSuper; shallow = shallowSuper; } // Phase 2 - Move deepBackup up by (deep end - deep) for (; ; ) { deep = deep.getSuperclass(); if (deep == null) { break; } backupDeep = backupDeep.getSuperclass(); } deep = backupDeep; // Phase 3 - The hierarchy positions are now aligned // The common super class is easy to find now while (!eq(deep, shallow)) { deep = deep.getSuperclass(); shallow = shallow.getSuperclass(); } return deep; }