package com.trade.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.ibatis.io.ResolverUtil;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

/**
 * 包下的类扫描工具类
 */
public class PackageScanUtil {

    /**
     * 获取packageName下继承superType的Class List
     * 
     * @param packageName 包绝对路径名称,支持以"."或者"/"分割
     * @param superType 父类Class
     * @return
     */
    public static List<Class<?>> getClassFromSuperClass(String packageName, Class<?> superType) {
        List<Class<?>> list = new ArrayList<>();
        ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
        resolverUtil.find(new ResolverUtil.IsA(superType), packageName);
        Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
        if (CollectionUtils.isNotEmpty(mapperSet)) {
            list.addAll(mapperSet);
        }
        return list;
    }
}
