All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dmgcodevil.jmspy.proxy.ReflectionUtils Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package com.github.dmgcodevil.jmspy.proxy;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Simple util class to perform operations related to java reflection framework.
 *
 * @author dmgcodevil
 */
public final class ReflectionUtils {

    private ReflectionUtils() {
    }

    public static List getAllFields(Class type) {
        List fields = new ArrayList<>();
        return getAllFields(fields, type);
    }

    public static List getAllFields(List fields, Class type) {
        fields.addAll(Arrays.asList(type.getDeclaredFields()));

        if (type.getSuperclass() != null) {
            fields = getAllFields(fields, type.getSuperclass());
        }

        return fields;
    }

    public static boolean hasDefaultConstructor(Class type) {
        return getDefaultConstructor(type) != null;
    }

    public static Constructor getDefaultConstructor(Class type) {
        try {
            return type.getDeclaredConstructor(new Class[]{});
        } catch (NoSuchMethodException e) {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy