use of org.simpleflatmapper.ow2asm.Label in project SimpleFlatMapper by arnaudroger.
the class BiInstantiatorBuilder method invokeBiFunction.
private static <S1, S2> void invokeBiFunction(InjectionPoint injectionPoint, String classType, Class<?> s1, Class<?> s2, MethodVisitor mv, Consumer<MethodVisitor> consumer, boolean ignoreNullValues) throws NoSuchMethodException {
String s1Type = AsmUtils.toAsmType(s1.equals(Void.class) || s1.equals(void.class) ? Object.class : s1);
String s2Type = AsmUtils.toAsmType(s2.equals(Void.class) || s2.equals(void.class) ? Object.class : s2);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, classType, getBiFunctionFieldName(injectionPoint.parameter), AsmUtils.toTargetTypeDeclaration(injectionPoint.functionType));
mv.visitVarInsn(ALOAD, 1);
if (!injectionPoint.isGetter) {
mv.visitVarInsn(ALOAD, 2);
}
Method getterMethod = injectionPoint.getMethod();
AsmUtils.invoke(mv, injectionPoint.functionType, getterMethod);
if (!injectionPoint.isPrimitive) {
// IF NULL
Class<?> wrapperClass = AsmUtils.toWrapperClass(injectionPoint.parameter.getType());
if (!wrapperClass.isAssignableFrom(getterMethod.getReturnType())) {
mv.visitTypeInsn(CHECKCAST, AsmUtils.toAsmType(wrapperClass));
}
Label label = new Label();
if (ignoreNullValues) {
mv.visitVarInsn(ASTORE, 3);
mv.visitVarInsn(ALOAD, 3);
mv.visitJumpInsn(IFNULL, label);
}
changeToPrimitiveIfNeeded(injectionPoint, mv, wrapperClass, ignoreNullValues);
if (consumer != null) {
consumer.accept(mv);
}
if (ignoreNullValues) {
mv.visitLabel(label);
}
// iframe?
} else {
if (consumer != null) {
consumer.accept(mv);
}
}
}
use of org.simpleflatmapper.ow2asm.Label in project SimpleFlatMapper by arnaudroger.
the class InstantiatorBuilder method invokeGetter.
private static <S> void invokeGetter(Parameter p, Getter<? super S, ?> getter, String classType, Class<?> sourceClass, MethodVisitor mv, Consumer<MethodVisitor> consumer, boolean ignoreNullValues) throws NoSuchMethodException {
GetterCall getterCall = getGetterCall(p.getType(), getter.getClass());
String getterType = AsmUtils.toAsmType(getterCall.getterType);
String sourceType = AsmUtils.toAsmType(sourceClass.equals(Void.class) || sourceClass.equals(void.class) ? Object.class : sourceClass);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, classType, "getter_" + p.getName(), AsmUtils.toTargetTypeDeclaration(getterType));
mv.visitVarInsn(ALOAD, 1);
if (getterCall.isPrimitive) {
AsmUtils.invoke(mv, getterCall.getterType, getterCall.methodName, "(" + AsmUtils.toTargetTypeDeclaration(sourceType) + ")" + AsmUtils.toAsmType(p.getType()));
if (consumer != null) {
consumer.accept(mv);
}
} else {
Class<?> wrapperClass = AsmUtils.toWrapperClass(p.getType());
Method getterMethod = BiInstantiatorBuilder.getMethod(TypeHelper.toClass(getterCall.getterType), "get", 1);
AsmUtils.invoke(mv, getterCall.getterType, getterMethod);
if (!wrapperClass.isAssignableFrom(getterMethod.getReturnType())) {
mv.visitTypeInsn(CHECKCAST, AsmUtils.toAsmType(wrapperClass));
}
Label label = new Label();
if (ignoreNullValues) {
mv.visitVarInsn(ASTORE, 3);
mv.visitVarInsn(ALOAD, 3);
mv.visitJumpInsn(IFNULL, label);
}
changeToPrimitiveIfNeeded(p, mv, wrapperClass, ignoreNullValues);
if (consumer != null) {
consumer.accept(mv);
}
if (ignoreNullValues) {
mv.visitLabel(label);
}
}
}
Aggregations