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

ftl.$$ReflectionsTemplateftl Maven / Gradle / Ivy

Go to download

The RxMicro Annotation Processor internal module that contains common components for other generators.

There is a newer version: 0.11
Show newest version
<#include "common-lib.javaftl">
<#-- -------------------------------------------------------------------------------------------------------- -->
public final class ${CLASS_NAME} {

    <#if GETTER_REQUIRED>
    public static Object getFieldValue(final Object model,
                                       final String fieldName) {
        final Field field = getField(model, fieldName, f -> {
            if (!f.canAccess(model)) {
                f.setAccessible(true);
            }
        });
        try {
            return field.get(model);
        } catch (final IllegalAccessException e) {
            throw new CheckedWrapperException(e);
        }
    }

    
    <#if SETTER_REQUIRED>
    public static void setFieldValue(final Object model,
                                     final String fieldName,
                                     final Object value) {
        final Field field = getField(model, fieldName, f -> {
            if (!f.canAccess(model)) {
                f.setAccessible(true);
            }
        });
        try {
            field.set(model, value);
        } catch (final IllegalAccessException e) {
            throw new CheckedWrapperException(e);
        }
    }

    
    <#if INVOKE_REQUIRED>
    public static Object invoke(final Object bean,
                                final String methodName,
                                final Object... args) {
        final Method method = getMethod(bean, methodName, stream(args).map(Object::getClass).collect(toList()), m -> {
            if (!m.canAccess(bean instanceof Class ? null : bean)) {
                m.setAccessible(true);
            }
        });
        try {
            return method.invoke(bean, args);
        } catch (final IllegalAccessException e) {
            throw new CheckedWrapperException(e);
        } catch (final InvocationTargetException e) {
            throw new CheckedWrapperException(e.getTargetException());
        }
    }

    
    private ${CLASS_NAME}() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy