Search in sources :

Example 31 with InstantiatorDefinition

use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.

the class InstantiatorDefinitions method lookForCompatibleOneArgument.

public static InstantiatorDefinition lookForCompatibleOneArgument(Collection<InstantiatorDefinition> col, CompatibilityScorer scorer) {
    InstantiatorDefinition current = null;
    int currentScore = -1;
    for (InstantiatorDefinition id : col) {
        if (id.getParameters().length == 1) {
            int score = scorer.score(id);
            if (score > currentScore) {
                current = id;
                currentScore = score;
            }
        }
    }
    return current;
}
Also used : InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition)

Example 32 with InstantiatorDefinition

use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.

the class ObjectClassMeta method listConstructorProperties.

private List<ConstructorPropertyMeta<T, ?>> listConstructorProperties(List<InstantiatorDefinition> instantiatorDefinitions, boolean builderIgnoresNullValues) {
    if (instantiatorDefinitions == null)
        return null;
    List<ConstructorPropertyMeta<T, ?>> constructorProperties = new ArrayList<ConstructorPropertyMeta<T, ?>>();
    ParamNameDeductor<T> paramNameDeductor = null;
    for (InstantiatorDefinition cd : instantiatorDefinitions) {
        for (org.simpleflatmapper.reflect.Parameter param : cd.getParameters()) {
            String paramName = param.getName();
            if (paramName == null) {
                if (paramNameDeductor == null) {
                    paramNameDeductor = new ParamNameDeductor<T>(TypeHelper.<T>toClass(target));
                }
                paramName = paramNameDeductor.findParamName(cd, param, builderIgnoresNullValues);
            }
            constructorProperties.add(constructorMeta(param, paramName, cd));
        }
    }
    return constructorProperties;
}
Also used : InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition) java.lang.reflect(java.lang.reflect) org.simpleflatmapper.reflect(org.simpleflatmapper.reflect)

Aggregations

InstantiatorDefinition (org.simpleflatmapper.reflect.InstantiatorDefinition)32 Test (org.junit.Test)20 ExecutableInstantiatorDefinition (org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition)20 Parameter (org.simpleflatmapper.reflect.Parameter)17 HashMap (java.util.HashMap)13 BiFunction (org.simpleflatmapper.util.BiFunction)11 BuilderInstantiatorDefinition (org.simpleflatmapper.reflect.BuilderInstantiatorDefinition)10 InstantiatorFactory (org.simpleflatmapper.reflect.InstantiatorFactory)10 ConstantBiFunction (org.simpleflatmapper.util.ConstantBiFunction)9 BuilderBiInstantiator (org.simpleflatmapper.reflect.impl.BuilderBiInstantiator)6 Type (java.lang.reflect.Type)4 AsmFactory (org.simpleflatmapper.reflect.asm.AsmFactory)4 ConstantGetter (org.simpleflatmapper.reflect.getter.ConstantGetter)3 InstantiatorDefinitions (org.simpleflatmapper.reflect.instantiator.InstantiatorDefinitions)3 ArrayList (java.util.ArrayList)2 DbFinalPrimitiveObject (org.simpleflatmapper.test.beans.DbFinalPrimitiveObject)2 Tuple2 (org.simpleflatmapper.tuple.Tuple2)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 java.lang.reflect (java.lang.reflect)1