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

com.jparams.junit4.reflection.Reflection Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package com.jparams.junit4.reflection;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Reflection {
    private Reflection() {
    }

    public static MethodParameter[] getMethodParameters(Method method) {
        Class[] parameterTypes = method.getParameterTypes();
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();

        MethodParameter[] methodParameters = new MethodParameter[parameterTypes.length];

        for (int i = 0; i < parameterTypes.length; i++) {
            methodParameters[i] = new MethodParameter(parameterTypes[i], parameterAnnotations[i]);
        }

        return methodParameters;
    }

    public static  T createInstance(Class clazz) {
        try {
            return clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new InstanceCreationException("Error instantiating class " + clazz.getSimpleName(), e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy