use of org.simpleflatmapper.reflect.Parameter in project SimpleFlatMapper by arnaudroger.
the class TupleClassMeta method respecifyParameterNames.
@SuppressWarnings("unchecked")
private InstantiatorDefinition respecifyParameterNames(ExecutableInstantiatorDefinition definition) {
final Parameter[] parameters = definition.getParameters();
if (parameters.length > 0 && parameters[0].getName() == null) {
Parameter[] newParams = new Parameter[parameters.length];
final ElementNameGenerator nameGenerator = elementNameGenerator(definition.getExecutable().getDeclaringClass());
for (int i = 0; i < parameters.length; i++) {
newParams[i] = new Parameter(i, nameGenerator.name(i), parameters[i].getType(), parameters[i].getGenericType());
}
return new ExecutableInstantiatorDefinition((Constructor<? extends T>) definition.getExecutable(), newParams);
}
return definition;
}
use of org.simpleflatmapper.reflect.Parameter in project SimpleFlatMapper by arnaudroger.
the class TupleClassMeta method newConstructorPropertyMeta.
private static <T, E> ConstructorPropertyMeta<T, E> newConstructorPropertyMeta(InstantiatorDefinition instantiatorDefinition, int i, ReflectionService reflectionService, Type type) {
Class<T> tClass = TypeHelper.toClass(type);
final Parameter parameter = instantiatorDefinition.getParameters()[i];
Getter<T, E> getter = reflectionService.getObjectGetterFactory().getGetter(tClass, parameter.getName());
return new ConstructorPropertyMeta<T, E>("element" + i, type, reflectionService, parameter, ScoredGetter.<T, E>of(getter, Integer.MAX_VALUE), ScoredSetter.<T, E>nullSetter(), instantiatorDefinition, null);
}
use of org.simpleflatmapper.reflect.Parameter in project SimpleFlatMapper by arnaudroger.
the class ParamNameDeductor method parameters.
private Map<Parameter, Getter<? super Object, ?>> parameters(InstantiatorDefinition instantiatorDefinition, boolean allowNull, boolean builderIgnoresNullValues) throws Exception {
Map<Parameter, Getter<? super Object, ?>> parameterGetterMap = new HashMap<Parameter, Getter<? super Object, ?>>();
for (Parameter parameter : instantiatorDefinition.getParameters()) {
Object value = neutralValue(parameter.getGenericType(), allowNull, builderIgnoresNullValues);
parameterGetterMap.put(parameter, new ConstantGetter<Object, Object>(value));
}
return parameterGetterMap;
}
use of org.simpleflatmapper.reflect.Parameter in project SimpleFlatMapper by arnaudroger.
the class OptionalClassMeta method getInstantiatorDefinition.
private InstantiatorDefinition getInstantiatorDefinition(Type type) throws NoSuchMethodException {
ParameterizedType pt = (ParameterizedType) type;
InstantiatorDefinition id = new ExecutableInstantiatorDefinition(Optional.class.getMethod("ofNullable", Object.class), new Parameter(0, "value", Object.class, pt.getActualTypeArguments()[0]));
return id;
}
use of org.simpleflatmapper.reflect.Parameter in project SimpleFlatMapper by arnaudroger.
the class ReflectionInstantiatorDefinitionFactoryTest method testExtractStaticFactoryMethod.
@Test
public void testExtractStaticFactoryMethod() throws NoSuchMethodException {
List<InstantiatorDefinition> factoryMethod = ReflectionInstantiatorDefinitionFactory.extractDefinitions(ObjectWithFactoryMethod.class);
assertEquals(1, factoryMethod.size());
ExecutableInstantiatorDefinition id = (ExecutableInstantiatorDefinition) factoryMethod.get(0);
assertEquals(ObjectWithFactoryMethod.class.getMethod("valueOf", String.class), id.getExecutable());
assertEquals(1, id.getParameters().length);
Assert.assertEquals(new Parameter(0, null, String.class), id.getParameters()[0]);
}
Aggregations