package com.hdkj.lt.utils.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

/**
 * @Description
 * @Author wenhao
 * @Date 2023/3/23 20:14
 * @Version 1.0
 */
public class ReflectUtils {

    private ReflectUtils() {
    }

    /**
     * 根据指定类获取Fields
     *
     * @param clazz
     * @param list
     */
    public static void getClassFields(Class<?> clazz, List<Field> list) {
        if (clazz != Object.class) {
            list.addAll(Arrays.asList(clazz.getDeclaredFields()));
            Class<?> superclass = clazz.getSuperclass();
            getClassFields(superclass, list);
        }
    }

    /**
     * 根据指定类获取所有方法
     *
     * @param clazz
     * @param list
     */
    public static void getClassMethods(Class<?> clazz, List<Method> list) {
        if (clazz != Object.class) {
            list.addAll(Arrays.asList(clazz.getMethods()));
            Class<?> superclass = clazz.getSuperclass();
            getClassMethods(superclass, list);
        }
    }

}
