use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class InstantiatorFactory method getInstantiator.
@SuppressWarnings("unchecked")
public <S, T> Instantiator<S, T> getInstantiator(InstantiatorDefinition instantiatorDefinition, Class<S> source, Map<Parameter, Getter<? super S, ?>> injections, boolean useAsmIfEnabled, boolean builderIgnoresNullValues) {
checkParameters(instantiatorDefinition, injections.keySet());
if (asmFactory != null && useAsmIfEnabled) {
if (instantiatorDefinition instanceof ExecutableInstantiatorDefinition) {
ExecutableInstantiatorDefinition executableInstantiatorDefinition = (ExecutableInstantiatorDefinition) instantiatorDefinition;
Member executable = executableInstantiatorDefinition.getExecutable();
if (Modifier.isPublic(executable.getModifiers())) {
try {
return asmFactory.createInstantiator(source, executableInstantiatorDefinition, injections, builderIgnoresNullValues);
} catch (Exception e) {
// fall back on reflection
if (failOnAsmError)
ErrorHelper.rethrow(e);
}
}
} else {
try {
return asmFactory.createInstantiator(source, (BuilderInstantiatorDefinition) instantiatorDefinition, injections, builderIgnoresNullValues);
} catch (Exception e) {
// fall back on reflection
if (failOnAsmError)
ErrorHelper.rethrow(e);
}
}
}
switch(instantiatorDefinition.getType()) {
case CONSTRUCTOR:
return constructorInstantiator((ExecutableInstantiatorDefinition) instantiatorDefinition, injections);
case METHOD:
return methodInstantiator((ExecutableInstantiatorDefinition) instantiatorDefinition, injections);
case BUILDER:
return builderInstantiator((BuilderInstantiatorDefinition) instantiatorDefinition, injections, useAsmIfEnabled, builderIgnoresNullValues);
default:
throw new IllegalArgumentException("Unsupported executable type " + instantiatorDefinition);
}
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class ReflectionInstantiatorDefinitionFactory method extractDefinitions.
@SuppressWarnings("unchecked")
private static List<InstantiatorDefinition> extractDefinitions(Type target, ParameterBuilder parameterBuilder) {
Class<?> clazz = TypeHelper.toClass(target);
List<InstantiatorDefinition> instantiatorDefinitions = new ArrayList<InstantiatorDefinition>();
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
if (Modifier.isPublic(constructor.getModifiers())) {
InstantiatorDefinition definition = new ExecutableInstantiatorDefinition(constructor, parameterBuilder.getParameters(constructor, target));
instantiatorDefinitions.add(definition);
}
}
for (Method m : clazz.getDeclaredMethods()) {
if (Modifier.isPublic(m.getModifiers()) && Modifier.isStatic(m.getModifiers()) && clazz.isAssignableFrom(m.getReturnType())) {
InstantiatorDefinition definition = new ExecutableInstantiatorDefinition(m, parameterBuilder.getParameters(m, target));
instantiatorDefinitions.add(definition);
}
}
return instantiatorDefinitions;
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class BuilderInstantiatorDefinitionFactory method getDefinitionForBuilder.
public static BuilderInstantiatorDefinition getDefinitionForBuilder(Member e, Type target) {
ExecutableInstantiatorDefinition def = new ExecutableInstantiatorDefinition(e);
Type builderType;
if (e instanceof Constructor) {
builderType = ((Constructor) e).getDeclaringClass();
} else {
builderType = ((Method) e).getGenericReturnType();
}
return getDefinitionForBuilder(def, builderType, target);
}
Aggregations