ftl.$$ReflectionsTemplateftl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxmicro-annotation-processor-common Show documentation
Show all versions of rxmicro-annotation-processor-common Show documentation
The RxMicro Annotation Processor internal module that contains common components for other generators.
<#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>
<#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>
<#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());
}
}
#if>
private ${CLASS_NAME}() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy