Search in sources :

Example 6 with Label

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);
        }
    }
}
Also used : Label(org.simpleflatmapper.ow2asm.Label) Method(java.lang.reflect.Method)

Example 7 with Label

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);
        }
    }
}
Also used : Label(org.simpleflatmapper.ow2asm.Label) Method(java.lang.reflect.Method)

Aggregations

Label (org.simpleflatmapper.ow2asm.Label)7 MethodVisitor (org.simpleflatmapper.ow2asm.MethodVisitor)4 Method (java.lang.reflect.Method)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Member (java.lang.reflect.Member)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CsvColumnKey (org.simpleflatmapper.csv.CsvColumnKey)1 ClassReader (org.simpleflatmapper.ow2asm.ClassReader)1 ClassVisitor (org.simpleflatmapper.ow2asm.ClassVisitor)1 InstantiatorDefinition (org.simpleflatmapper.reflect.InstantiatorDefinition)1 Parameter (org.simpleflatmapper.reflect.Parameter)1 ExecutableInstantiatorDefinition (org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition)1