protected String getCommonSuperClass()

in bytekit-core/src/main/java/com/alibaba/bytekit/asm/ClassMetaClassWriter.java [41:71]


    protected String getCommonSuperClass(String type1, String type2) {
        byte[] type1Bytes = ClassLoaderUtils.readBytecodeByName(classLoader, type1);
        if (type1Bytes == null) {
            return super.getCommonSuperClass(type1, type2);
        }
        byte[] type2Bytes = ClassLoaderUtils.readBytecodeByName(classLoader, type2);
        if (type2Bytes == null) {
            return super.getCommonSuperClass(type1, type2);
        }
        ClassMeta classMeta1 = ClassMeta.fromByteCode(type1Bytes, classLoader);
        ClassMeta classMeta2 = ClassMeta.fromByteCode(type2Bytes, classLoader);

        if (classMeta1.isAssignableFrom(classMeta2)) {
            return type1;
        }
        if (classMeta2.isAssignableFrom(classMeta1)) {
            return type2;
        }
        if (classMeta1.isInterface() || classMeta2.isInterface()) {
            return "java/lang/Object";
        } else {
            do {
                classMeta1 = classMeta1.getSuperclass();
                if (classMeta1 == null) {
                    // TODO 是直接返回 "java/lang/Object",还是尝试用指定 classLoader 查找
                    return getCommonSuperClass(type1, type2);
                }
            } while (!classMeta1.isAssignableFrom(classMeta2));
            return classMeta1.getInternalClassName();
        }
    }