org.sfm.reflect.meta.MethodPropertyMeta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.reflect.meta;
import org.sfm.reflect.Getter;
import org.sfm.reflect.ReflectionService;
import org.sfm.reflect.Setter;
import org.sfm.reflect.SetterHelper;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
public class MethodPropertyMeta extends PropertyMeta {
private final Method setter;
private final Method getter;
private final Type type;
public MethodPropertyMeta(String name, ReflectionService reflectService, Method method, Type type) {
super(name, reflectService);
this.setter = method;
this.type = type;
this.getter = null;
}
public MethodPropertyMeta(String name, ReflectionService reflectService, Method setter, Method getter, Type type) {
super(name, reflectService);
this.setter = setter;
this.getter = getter;
this.type = type;
}
@Override
protected Setter newSetter() {
return reflectService.getObjectSetterFactory().getMethodSetter(setter);
}
@SuppressWarnings("unchecked")
@Override
protected Getter newGetter() {
if (getter == null) {
return reflectService.getObjectGetterFactory().getGetter((Class super T>) setter.getDeclaringClass(), SetterHelper.getPropertyNameFromMethodName(setter.getName()));
} else {
return reflectService.getObjectGetterFactory().getMethodGetter(getter);
}
}
@Override
public Type getType() {
return type;
}
@Override
public String getPath() {
return getName();
}
@Override
public String toString() {
return "MethodPropertyMeta{" +
"setter=" + setter +
", getter=" + getter +
", type=" + type +
'}';
}
}