Search in sources :

Example 6 with Parameter

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;
}
Also used : ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) Parameter(org.simpleflatmapper.reflect.Parameter)

Example 7 with Parameter

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);
}
Also used : Parameter(org.simpleflatmapper.reflect.Parameter)

Example 8 with Parameter

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;
}
Also used : HashMap(java.util.HashMap) ConstantGetter(org.simpleflatmapper.reflect.getter.ConstantGetter) Getter(org.simpleflatmapper.reflect.Getter) Parameter(org.simpleflatmapper.reflect.Parameter)

Example 9 with Parameter

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;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition) ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) Parameter(org.simpleflatmapper.reflect.Parameter)

Example 10 with Parameter

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]);
}
Also used : ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition) ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) Parameter(org.simpleflatmapper.reflect.Parameter) Test(org.junit.Test)

Aggregations

Parameter (org.simpleflatmapper.reflect.Parameter)37 Test (org.junit.Test)20 ExecutableInstantiatorDefinition (org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition)20 InstantiatorDefinition (org.simpleflatmapper.reflect.InstantiatorDefinition)17 HashMap (java.util.HashMap)16 BiFunction (org.simpleflatmapper.util.BiFunction)16 BuilderInstantiatorDefinition (org.simpleflatmapper.reflect.BuilderInstantiatorDefinition)10 InstantiatorFactory (org.simpleflatmapper.reflect.InstantiatorFactory)10 ConstantBiFunction (org.simpleflatmapper.util.ConstantBiFunction)9 Getter (org.simpleflatmapper.reflect.Getter)6 ConstantGetter (org.simpleflatmapper.reflect.getter.ConstantGetter)6 BuilderBiInstantiator (org.simpleflatmapper.reflect.impl.BuilderBiInstantiator)6 MethodVisitor (org.simpleflatmapper.ow2asm.MethodVisitor)5 Method (java.lang.reflect.Method)4 Type (java.lang.reflect.Type)4 AsmFactory (org.simpleflatmapper.reflect.asm.AsmFactory)4 DbFinalPrimitiveObject (org.simpleflatmapper.test.beans.DbFinalPrimitiveObject)4 InputStream (java.io.InputStream)3 Member (java.lang.reflect.Member)3 Constructor (java.lang.reflect.Constructor)2