use of org.simpleflatmapper.ow2asm.FieldVisitor in project SimpleFlatMapper by arnaudroger.
the class BiInstantiatorBuilder method appendFunctionsField.
private static <S1, S2> void appendFunctionsField(List<InjectionPoint> injections, ClassWriter cw) {
for (InjectionPoint injectionPoint : injections) {
FieldVisitor fv = cw.visitField(ACC_FINAL, getBiFunctionFieldName(injectionPoint.parameter), AsmUtils.toTargetTypeDeclaration(injectionPoint.functionType), null, null);
fv.visitEnd();
}
}
use of org.simpleflatmapper.ow2asm.FieldVisitor in project SimpleFlatMapper by arnaudroger.
the class InstantiatorBuilder method createInstantiator.
public static <S> byte[] createInstantiator(final String className, final Class<?> sourceClass, final BuilderInstantiatorDefinition instantiatorDefinition, final Map<Parameter, Getter<? super S, ?>> injections, boolean ignoreNullValues) throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
Class<?> targetClass = TypeHelper.toClass(BiInstantiatorBuilder.getTargetType(instantiatorDefinition));
String targetType = AsmUtils.toAsmType(targetClass);
String sourceType = AsmUtils.toWrapperType(sourceClass);
String classType = AsmUtils.toAsmType(className);
String instantiatorType = AsmUtils.toAsmType(Instantiator.class);
cw.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, classType, "Ljava/lang/Object;L" + instantiatorType + "<L" + targetType + ";>;", "java/lang/Object", new String[] { instantiatorType });
{
FieldVisitor fv = cw.visitField(ACC_FINAL, "builderInstantiator", "L" + AsmUtils.toAsmType(Instantiator.class) + ";", "L" + AsmUtils.toAsmType(Instantiator.class) + "<Ljava/lang/Void;L" + AsmUtils.toAsmType(BiInstantiatorBuilder.getTargetType(instantiatorDefinition.getBuilderInstantiator())) + ";>;", null);
fv.visitEnd();
}
appendGetters(injections, cw);
appendInitBuilder(injections, cw, sourceType, classType, instantiatorDefinition);
appendNewInstanceBuilderOnBuilder(sourceClass, instantiatorDefinition, injections, cw, targetType, sourceType, classType, instantiatorDefinition.getSetters(), ignoreNullValues);
appendBridgeMethod(cw, targetType, sourceType, classType);
appendToString(injections, cw, instantiatorDefinition.getParameters());
cw.visitEnd();
return AsmUtils.writeClassToFile(className, cw.toByteArray());
}
use of org.simpleflatmapper.ow2asm.FieldVisitor in project SimpleFlatMapper by arnaudroger.
the class MapperAsmBuilder method declareConstructorMapperFields.
private static <S, T> void declareConstructorMapperFields(ClassWriter cw, FieldMapper<S, T> mapper, int index) {
if (mapper == null)
return;
FieldVisitor fv;
Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class);
fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "constructorMapper" + index, toTargetTypeDeclaration(AsmUtils.toAsmType(mapperClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(mapperClass)), null);
fv.visitEnd();
}
use of org.simpleflatmapper.ow2asm.FieldVisitor in project SimpleFlatMapper by arnaudroger.
the class CsvMapperCellHandlerBuilder method createTargetSetterClass.
public static <T> byte[] createTargetSetterClass(String className, DelayedCellSetterFactory<T, ?>[] delayedCellSetters, CellSetter<T>[] setters, Type type, boolean ignoreException, int maxMethodSize) throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
FieldVisitor fv;
MethodVisitor mv;
final String targetType = AsmUtils.toAsmType(type);
final String classType = AsmUtils.toAsmType(className);
cw.visit(Opcodes.V1_6, Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classType, "L" + CSV_CELL_MAPPER_TYPE + "<L" + targetType + ";>;", CSV_CELL_MAPPER_TYPE, null);
// declare fields
for (int i = 0; i < delayedCellSetters.length; i++) {
if (delayedCellSetters[i] != null) {
fv = cw.visitField(Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL, "delayedCellSetter" + i, AsmUtils.toTargetTypeDeclaration(DELAYED_CELL_SETTER_TYPE), "L" + DELAYED_CELL_SETTER_TYPE + "<L" + targetType + ";*>;", null);
fv.visitEnd();
}
}
for (int i = 0; i < setters.length; i++) {
if (setters[i] != null) {
fv = cw.visitField(Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL, "setter" + i, AsmUtils.toTargetTypeDeclaration(CELL_SETTER_TYPE), "L" + CELL_SETTER_TYPE + "<L" + targetType + ";>;", null);
fv.visitEnd();
}
}
appendInit(delayedCellSetters, setters, cw, targetType, classType, maxMethodSize);
appendDelayedCellValue(delayedCellSetters, ignoreException, cw, classType);
append_delayedCellValue(delayedCellSetters, cw, classType, maxMethodSize);
appendCellValue(setters, ignoreException, cw, classType);
append_cellValue(delayedCellSetters, setters, cw, classType, maxMethodSize);
appendApplyDelayedSetter(delayedCellSetters, ignoreException, cw, classType, maxMethodSize);
appendApplyDelayedCellSetterN(delayedCellSetters, cw, classType);
appendGetDelayedCellSetter(delayedCellSetters, cw, targetType, classType, maxMethodSize);
appendPeekDelayedCellSetterValue(delayedCellSetters, cw, classType, maxMethodSize);
cw.visitEnd();
return AsmUtils.writeClassToFile(className, cw.toByteArray());
}
use of org.simpleflatmapper.ow2asm.FieldVisitor in project SimpleFlatMapper by arnaudroger.
the class BiInstantiatorBuilder method createInstantiator.
public static <S1, S2> byte[] createInstantiator(final String className, final Class<?> s1, final Class<?> s2, final Instantiator<Void, ?> builderInstantiator, final BuilderInstantiatorDefinition instantiatorDefinition, final Map<Parameter, BiFunction<? super S1, ? super S2, ?>> injectionsMap, boolean ignoreNullValues) throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
Class<?> targetClass = TypeHelper.toClass(getTargetType(instantiatorDefinition));
String targetType = AsmUtils.toAsmType(targetClass);
String s1Type = AsmUtils.toWrapperType(s1);
String s2Type = AsmUtils.toWrapperType(s2);
String classType = AsmUtils.toAsmType(className);
String instantiatorType = AsmUtils.toAsmType(BI_INSTANTIATOR_CLASS);
List<InjectionPoint> injections = toInjections(injectionsMap);
cw.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, classType, "Ljava/lang/Object;L" + instantiatorType + "<L" + targetType + ";>;", "java/lang/Object", new String[] { instantiatorType });
{
FieldVisitor fv = cw.visitField(ACC_FINAL, "builderInstantiator", "L" + AsmUtils.toAsmType(INSTANTIATOR_CLASS) + ";", "L" + AsmUtils.toAsmType(INSTANTIATOR_CLASS) + "<Ljava/lang/Void;L" + AsmUtils.toAsmType(getTargetType(instantiatorDefinition.getBuilderInstantiator())) + ";>;", null);
fv.visitEnd();
}
appendFunctionsField(injections, cw);
appendInitBuilder(injections, cw, s1Type, s2Type, classType, instantiatorDefinition);
appendNewInstanceBuilder(s1, s2, instantiatorDefinition, injections, cw, targetType, s1Type, s2Type, classType, instantiatorDefinition.getSetters(), ignoreNullValues);
appendBridgeMethod(cw, targetType, s1Type, s2Type, classType);
appendToString(injections, cw, instantiatorDefinition.getParameters());
cw.visitEnd();
return AsmUtils.writeClassToFile(className, cw.toByteArray());
}
Aggregations