use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class TupleClassMetaTest method testRespecify.
@Test
public void testRespecify() throws ClassNotFoundException, MalformedURLException {
ClassLoader cl = new URLClassLoader(new URL[] { LibrarySetsClassLoader.findUrl(Tuple2.class, getClass().getClassLoader()) }, null) {
@Override
public InputStream getResourceAsStream(String name) {
return null;
}
};
ReflectionService reflectionService = new ReflectionService(null) {
};
Class<?> tuple2Class = cl.loadClass(Tuple2.class.getName());
TupleClassMeta classMeta = new TupleClassMeta(tuple2Class, reflectionService);
List<InstantiatorDefinition> instantiatorDefinitions = classMeta.getInstantiatorDefinitions();
assertEquals(1, instantiatorDefinitions.size());
assertEquals("element0", instantiatorDefinitions.get(0).getParameters()[0].getName());
}
use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class TupleClassMetaTest method testFindPropertyNoAsm.
@Test
public void testFindPropertyNoAsm() {
Type type = new TypeReference<Tuple2<String, String>>() {
}.getType();
ClassMeta<Tuple2<String, String>> classMeta = ReflectionService.disableAsm().getClassMeta(type);
InstantiatorDefinition instantiatorDefinition = classMeta.getInstantiatorDefinitions().get(0);
assertEquals("element0", instantiatorDefinition.getParameters()[0].getName());
assertEquals("element1", instantiatorDefinition.getParameters()[1].getName());
assertEquals(2, instantiatorDefinition.getParameters().length);
}
use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class ArrayClassMetaTest method instantiate.
private Object instantiate(ClassMeta<?> classMeta) throws Exception {
InstantiatorDefinition instantiatorDefinition = classMeta.getInstantiatorDefinitions().get(0);
InstantiatorFactory instantiatorFactory = new InstantiatorFactory(null);
Instantiator instantiator = instantiatorFactory.getInstantiator(instantiatorDefinition, (Class) Object.class, new HashMap(), false, true);
return instantiator.newInstance(null);
}
use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class BuilderBiInstantiatorDefinitionFactoryTest method testBuilderFromMethodAsmBoxing.
@Test
public void testBuilderFromMethodAsmBoxing() throws Exception {
final List<InstantiatorDefinition> instantiatorDefinitions = BuilderInstantiatorDefinitionFactory.extractDefinitions(ClassBuilderWithMethod.class);
assertEquals(1, instantiatorDefinitions.size());
BuilderInstantiatorDefinition b = (BuilderInstantiatorDefinition) instantiatorDefinitions.get(0);
final Parameter[] parameters = b.getParameters();
Arrays.sort(parameters, new Comparator<Parameter>() {
@Override
public int compare(Parameter o1, Parameter o2) {
return o1.getName().compareTo(o2.getName());
}
});
Map<Parameter, BiFunction<? super Void, ? super Object, ?>> params = new HashMap<Parameter, BiFunction<? super Void, ? super Object, ?>>();
params.put(parameters[1], new ConstantBiFunction<Void, Object, String>("myname"));
params.put(parameters[0], new ConstantBiFunction<Void, Object, Integer>(3));
final InstantiatorFactory instantiatorFactory = new InstantiatorFactory(new AsmFactory(getClass().getClassLoader()), true);
final BiInstantiator<Void, Object, ClassBuilderWithMethod> instantiator = instantiatorFactory.<Void, Object, ClassBuilderWithMethod>getBiInstantiator(b, Void.class, Object.class, params, true, true);
final ClassBuilderWithMethod o = instantiator.newInstance(null, null);
assertFalse((instantiator instanceof BuilderBiInstantiator));
assertEquals("myname", o.getName());
assertEquals(3, o.getId());
}
use of org.simpleflatmapper.reflect.InstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class BuilderBiInstantiatorDefinitionFactoryTest method testBuilderFromMethodVoid.
@Test
public void testBuilderFromMethodVoid() throws Exception {
final List<InstantiatorDefinition> instantiatorDefinitions = BuilderInstantiatorDefinitionFactory.extractDefinitions(ClassBuilderWithMethod.class);
assertEquals(1, instantiatorDefinitions.size());
BuilderInstantiatorDefinition b = (BuilderInstantiatorDefinition) instantiatorDefinitions.get(0);
final Parameter[] parameters = b.getParameters();
Arrays.sort(parameters, new Comparator<Parameter>() {
@Override
public int compare(Parameter o1, Parameter o2) {
return o1.getName().compareTo(o2.getName());
}
});
Map<Parameter, BiFunction<? super Void, ? super Object, ?>> params = new HashMap<Parameter, BiFunction<? super Void, ? super Object, ?>>();
params.put(parameters[2], new ConstantBiFunction<Void, Object, String>("zrux"));
params.put(parameters[0], new ConstantBiFunction<Void, Object, Integer>(3));
final InstantiatorFactory instantiatorFactory = new InstantiatorFactory(new AsmFactory(getClass().getClassLoader()), true);
final BiInstantiator<Void, Object, ClassBuilderWithMethod> instantiator = instantiatorFactory.<Void, Object, ClassBuilderWithMethod>getBiInstantiator(b, Void.class, Object.class, params, true, true);
final ClassBuilderWithMethod o = instantiator.newInstance(null, null);
assertFalse((instantiator instanceof BuilderBiInstantiator));
assertEquals(3, o.getId());
assertEquals("zrux", o.getZrux());
}
Aggregations