use of org.simpleflatmapper.reflect.getter.BiFunctionGetter in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilder method constructorInjections.
@SuppressWarnings("unchecked")
private ConstructorInjections constructorInjections() {
final Map<Parameter, BiFunction<? super S, ? super MappingContext<? super S>, ?>> injections = new HashMap<Parameter, BiFunction<? super S, ? super MappingContext<? super S>, ?>>();
final List<FieldMapper<S, T>> fieldMappers = new ArrayList<FieldMapper<S, T>>();
propertyMappingsBuilder.forEachConstructorProperties(new ForEachCallBack<PropertyMapping<T, ?, K, FieldMapperColumnDefinition<K>>>() {
@SuppressWarnings("unchecked")
@Override
public void handle(PropertyMapping<T, ?, K, FieldMapperColumnDefinition<K>> propertyMapping) {
if (!isTargetForMapperFieldMapper(propertyMapping)) {
PropertyMeta<T, ?> pm = propertyMapping.getPropertyMeta();
ConstructorPropertyMeta<T, ?> cProp = (ConstructorPropertyMeta<T, ?>) pm;
Parameter parameter = cProp.getParameter();
Getter<? super S, ?> getter = fieldMapperFactory.getGetterFromSource(propertyMapping.getColumnKey(), pm.getPropertyType(), propertyMapping.getColumnDefinition(), pm.getPropertyClassMetaSupplier());
if (NullGetter.isNull(getter)) {
mapperConfig.mapperBuilderErrorHandler().accessorNotFound("Could not find getter for " + propertyMapping.getColumnKey() + " type " + propertyMapping.getPropertyMeta().getPropertyType() + " path " + propertyMapping.getPropertyMeta().getPath() + " See " + ErrorDoc.toUrl("FMMB_GETTER_NOT_FOUND"));
} else {
injections.put(parameter, new BiFunctionGetter<S, MappingContext<? super S>, Object>(getter));
}
if (!NullSetter.isNull(cProp.getSetter())) {
fieldMappers.add(fieldMapperFactory.newFieldMapper(propertyMapping, mappingContextFactoryBuilder, mapperConfig.mapperBuilderErrorHandler()));
}
}
}
});
for (PropertyPerOwner e : getSubPropertyPerOwner()) {
if (e.owner.isConstructorProperty()) {
final List<PropertyMapping<T, ?, K, FieldMapperColumnDefinition<K>>> properties = e.propertyMappings;
final MappingContextFactoryBuilder currentBuilder = getMapperContextFactoryBuilder(e.owner, properties);
final Mapper<S, ?> mapper;
if (properties.size() == 1 && JoinUtils.isArrayElement(properties.get(0).getPropertyMeta())) {
mapper = getterPropertyMapper(e.owner, properties.get(0));
} else {
mapper = subPropertyMapper(e.owner, properties, currentBuilder);
}
ConstructorPropertyMeta<T, ?> meta = (ConstructorPropertyMeta<T, ?>) e.owner;
injections.put(meta.getParameter(), newMapperGetterAdapter(mapper, currentBuilder));
fieldMappers.add(newMapperFieldMapper(properties, meta, mapper, currentBuilder));
}
}
return new ConstructorInjections(injections, fieldMappers.toArray(new FieldMapper[0]));
}
use of org.simpleflatmapper.reflect.getter.BiFunctionGetter in project SimpleFlatMapper by arnaudroger.
the class BiInstantiatorBuilder method getFunctionCall.
private static InjectionPoint getFunctionCall(Parameter parameter, BiFunction biFunction) {
if (biFunction.getClass().equals(BiFunctionGetter.class)) {
Getter getter = ((BiFunctionGetter) biFunction).getGetter();
Class<?> getterClass = getter.getClass();
if (TypeHelper.isPrimitive(parameter.getType())) {
Class<?> primitiveGetter = getPrimitiveGetter(parameter.getType());
if (primitiveGetter == null) {
throw new IllegalStateException("No primitive getter for primitive " + parameter.getType());
}
Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, primitiveGetter);
if (publicGetterClass != null) {
return new InjectionPoint(parameter, biFunction, true, "get" + getPrimitiveMethodSuffix(parameter.getType()), publicGetterClass, true);
}
}
Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, Getter.class);
return new InjectionPoint(parameter, biFunction, true, "get", publicGetterClass, false);
} else {
return new InjectionPoint(parameter, biFunction, false, "apply", biFunction.getClass(), false);
}
}
Aggregations