Example usage for org.objectweb.asm MethodVisitor visitJumpInsn

List of usage examples for org.objectweb.asm MethodVisitor visitJumpInsn

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitJumpInsn.

Prototype

public void visitJumpInsn(final int opcode, final Label label) 

Source Link

Document

Visits a jump instruction.

Usage

From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java

License:Open Source License

public static void firstContext(FirstContext firstContext, boolean asPair, Class type, int param, int event,
        MethodVisitor visitor) {
    Label returnLabel = new Label();
    Label continueLabel = new Label();

    visitor.visitVarInsn(ALOAD, event);/*ww w. j a v a  2s .co  m*/
    visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(),
            "context", BytecodeEventListenerGeneration.eventContextMethod.getDescriptor(), true);
    visitor.visitLdcInsn(Type.getType(type));
    if (asPair) {
        visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(),
                "first", BytecodeEventListenerGeneration.contextFirstMethod.getDescriptor(), false);
    } else {
        visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(),
                "firstSimple", BytecodeEventListenerGeneration.contextSimpleFirstMethod.getDescriptor(), false);
    }
    visitor.visitInsn(DUP);
    visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(),
            "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false);
    visitor.visitJumpInsn(IFEQ, returnLabel);
    visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(),
            "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false);
    BytecodeEventListenerGeneration.checkCast(asPair ? Type.getType(Pair.class) : Type.getType(type), visitor);
    visitor.visitVarInsn(ASTORE, param);
    visitor.visitJumpInsn(GOTO, continueLabel);
    visitor.visitLabel(returnLabel);
    visitor.visitInsn(RETURN);
    visitor.visitLabel(continueLabel);
}

From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java

License:Open Source License

public static void lastContext(LastContext lastContext, boolean asPair, Class type, int param, int event,
        MethodVisitor visitor) {
    Label returnLabel = new Label();
    Label continueLabel = new Label();

    visitor.visitVarInsn(ALOAD, event);//from   www  .  j  a  v a 2 s.c  o m
    visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(),
            "context", BytecodeEventListenerGeneration.eventContextMethod.getDescriptor(), true);
    visitor.visitLdcInsn(Type.getType(type));
    if (asPair) {
        visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(),
                "last", BytecodeEventListenerGeneration.contextLastMethod.getDescriptor(), false);
    } else {
        visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(),
                "lastSimple", BytecodeEventListenerGeneration.contextSimpleLastMethod.getDescriptor(), false);
    }
    visitor.visitInsn(DUP);
    visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(),
            "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false);
    visitor.visitJumpInsn(IFEQ, returnLabel);
    visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(),
            "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false);
    BytecodeEventListenerGeneration.checkCast(asPair ? Type.getType(Pair.class) : Type.getType(type), visitor);
    visitor.visitVarInsn(ASTORE, param);
    visitor.visitJumpInsn(GOTO, continueLabel);
    visitor.visitLabel(returnLabel);
    visitor.visitInsn(RETURN);
    visitor.visitLabel(continueLabel);
}

From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java

License:Open Source License

public static void get(Get get, Parameter parameter, Class eventClass, int param, int event,
        MethodVisitor visitor) {
    try {/*from   w ww  . j  ava 2s . c  o  m*/
        String name = EventListenerWrapper.name(get, parameter, eventClass).get();
        Type eventType = Type.getType(eventClass);
        Method rMethod = eventClass.getMethod(name);
        Type method = Type.getType(rMethod);
        Type type = Type.getType(parameter.getType());
        visitor.visitVarInsn(ALOAD, event);
        if (eventClass.isInterface()) {
            visitor.visitMethodInsn(INVOKEINTERFACE, eventType.getInternalName(), name, method.getDescriptor(),
                    true);
        } else {
            visitor.visitMethodInsn(INVOKEVIRTUAL, eventType.getInternalName(), name, method.getDescriptor(),
                    false);
        }
        if (get.nonnull() && method.getReturnType().getDescriptor().startsWith("L")) {
            Label continueLabel = new Label();
            visitor.visitInsn(DUP);
            visitor.visitJumpInsn(IFNONNULL, continueLabel);
            visitor.visitInsn(RETURN);
            visitor.visitLabel(continueLabel);
            visitor.visitVarInsn(ASTORE, param);
        } else {
            if (!method.getReturnType().getDescriptor().startsWith("L")) {
                Type boxing = Type.getType(Reflections.boxingType(rMethod.getReturnType()));
                visitor.visitTypeInsn(NEW, boxing.getInternalName());
                visitor.visitInsn(DUP_X1);
                visitor.visitInsn(SWAP);
                visitor.visitMethodInsn(INVOKESPECIAL, boxing.getInternalName(), "<init>",
                        Type.getMethodDescriptor(Type.VOID_TYPE, method.getReturnType()), false);
            }
            visitor.visitVarInsn(ASTORE, param);
        }
    } catch (NoSuchMethodException e) {
        //Meh
    }
}

From source file:com.gmail.socraticphoenix.occurence.wrappers.BytecodeEventListenerGeneration.java

License:Open Source License

public static void get(Get get, Parameter parameter, Class eventClass, int param, int event,
        MethodVisitor visitor) {
    try {//from w  ww .java 2  s  .c  o m
        String name = EventListenerWrapper.name(get, parameter, eventClass).get();
        Type eventType = Type.getType(eventClass);
        Method rMethod = eventClass.getMethod(name);
        Type method = Type.getType(rMethod);
        visitor.visitVarInsn(ALOAD, event);
        if (eventClass.isInterface()) {
            visitor.visitMethodInsn(INVOKEINTERFACE, eventType.getInternalName(), name, method.getDescriptor(),
                    true);
        } else {
            visitor.visitMethodInsn(INVOKEVIRTUAL, eventType.getInternalName(), name, method.getDescriptor(),
                    false);
        }
        if (get.nonnull() && method.getReturnType().getDescriptor().startsWith("L")) {
            Label continueLabel = new Label();
            visitor.visitInsn(DUP);
            visitor.visitJumpInsn(IFNONNULL, continueLabel);
            visitor.visitInsn(RETURN);
            visitor.visitLabel(continueLabel);
            visitor.visitVarInsn(ASTORE, param);
        } else {
            if (!method.getReturnType().getDescriptor().startsWith("L")) {
                Type boxing = Type.getType(Reflections.boxingType(rMethod.getReturnType()));
                visitor.visitTypeInsn(NEW, boxing.getInternalName());
                visitor.visitInsn(DUP_X1);
                visitor.visitInsn(SWAP);
                visitor.visitMethodInsn(INVOKESPECIAL, boxing.getInternalName(), "<init>",
                        Type.getMethodDescriptor(Type.VOID_TYPE, method.getReturnType()), false);
            }
            visitor.visitVarInsn(ASTORE, param);
        }
    } catch (NoSuchMethodException e) {
        //Meh
    }
}

From source file:com.google.devtools.build.android.desugar.Bug62060793TestDataGenerator.java

License:Open Source License

private static byte[] createClass() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    MethodVisitor mv;
    cw.visit(V1_8, ACC_PUBLIC | ACC_SUPER, CLASS_NAME, null, "java/lang/Object", null);

    cw.visitInnerClass(INTERFACE_TYPE_NAME, CLASS_NAME, "Interface",
            ACC_PUBLIC | ACC_STATIC | ACC_ABSTRACT | ACC_INTERFACE);

    cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
            ACC_PUBLIC | ACC_FINAL | ACC_STATIC);

    {/*from  www  .  ja  v  a 2s  .  co m*/
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "method", "(Ljava/lang/String;)Ljava/lang/String;", null,
                null);
        mv.visitParameter("str", 0);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ARETURN);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "method",
                "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", null,
                null);
        mv.visitParameter("bool", 0);
        mv.visitParameter("c", 0);
        mv.visitParameter("b", 0);
        mv.visitParameter("f", 0);
        mv.visitParameter("d", 0);
        mv.visitParameter("l", 0);
        mv.visitParameter("i", 0);
        mv.visitParameter("s", 0);
        mv.visitParameter("o", 0);
        mv.visitParameter("array", 0);
        mv.visitParameter("str", 0);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 10);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf",
                "(Ljava/lang/Object;)Ljava/lang/String;", false);
        mv.visitVarInsn(ASTORE, 13);
        mv.visitVarInsn(ALOAD, 11);
        Label l0 = new Label();
        mv.visitJumpInsn(IFNONNULL, l0);
        mv.visitInsn(ICONST_1);
        Label l1 = new Label();
        mv.visitJumpInsn(GOTO, l1);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/String" }, 0, null);
        mv.visitInsn(ICONST_0);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
        mv.visitVarInsn(ISTORE, 14);
        mv.visitIntInsn(BIPUSH, 91);
        mv.visitVarInsn(ALOAD, 12);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf",
                "(Ljava/lang/Object;)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
        mv.visitInsn(IADD);
        mv.visitVarInsn(ALOAD, 13);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf",
                "(Ljava/lang/Object;)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
        mv.visitInsn(IADD);
        mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
        mv.visitInsn(DUP_X1);
        mv.visitInsn(SWAP);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(I)V", false);
        mv.visitVarInsn(ALOAD, 12);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitVarInsn(ILOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(FLOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(F)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(DLOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(D)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(LLOAD, 6);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(J)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 8);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 9);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ALOAD, 13);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitVarInsn(ILOAD, 14);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;",
                false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "lambdaWithConstantArguments",
                "()L" + INTERFACE_TYPE_NAME + ";", null, null);
        mv.visitCode();
        mv.visitInsn(ICONST_0);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(ICONST_2);
        mv.visitInsn(FCONST_0);
        mv.visitInsn(DCONST_0);
        mv.visitInsn(LCONST_0);
        mv.visitInsn(ICONST_4);
        mv.visitIntInsn(SIPUSH, 9);
        mv.visitInsn(ACONST_NULL);
        mv.visitInsn(ACONST_NULL);
        mv.visitInvokeDynamicInsn("call",
                "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;)L" + INTERFACE_TYPE_NAME + ";",
                new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
                        "(Ljava/lang/invoke/MethodHandles$Lookup;"
                                + "Ljava/lang/String;Ljava/lang/invoke/MethodType;"
                                + "Ljava/lang/invoke/MethodType;" + "Ljava/lang/invoke/MethodHandle;"
                                + "Ljava/lang/invoke/MethodType;" + ")Ljava/lang/invoke/CallSite;",
                        false),
                new Object[] { Type.getType("(Ljava/lang/String;)Ljava/lang/String;"),
                        new Handle(Opcodes.H_INVOKESTATIC, CLASS_NAME, "method",
                                "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;Ljava/lang/String;"
                                        + ")Ljava/lang/String;",
                                false),
                        Type.getType("(Ljava/lang/String;)Ljava/lang/String;") });
        mv.visitInsn(ARETURN);
        mv.visitEnd();
    }

    cw.visitEnd();

    return cw.toByteArray();
}

From source file:com.google.devtools.build.android.desugar.CoreLibrarySupport.java

License:Open Source License

private void makeDispatchHelperMethod(ClassVisitor helper, EmulatedMethod method,
        ImmutableList<Class<?>> typechecks) {
    checkArgument(method.owner().isInterface());
    String owner = method.owner().getName().replace('.', '/');
    Type methodType = Type.getMethodType(method.descriptor());
    String companionDesc = InterfaceDesugaring.companionDefaultMethodDescriptor(owner, method.descriptor());
    MethodVisitor dispatchMethod = helper.visitMethod(method.access() | Opcodes.ACC_STATIC, method.name(),
            companionDesc, /*signature=*/ null, // signature is invalid due to extra "receiver" argument
            method.exceptions().toArray(EMPTY_LIST));

    dispatchMethod.visitCode();//from  w  w  w .ja  va  2s .c om
    {
        // See if the receiver might come with its own implementation of the method, and call it.
        // We do this by testing for the interface type created by EmulatedInterfaceRewriter
        Label fallthrough = new Label();
        String emulationInterface = renameCoreLibrary(owner);
        dispatchMethod.visitVarInsn(Opcodes.ALOAD, 0); // load "receiver"
        dispatchMethod.visitTypeInsn(Opcodes.INSTANCEOF, emulationInterface);
        dispatchMethod.visitJumpInsn(Opcodes.IFEQ, fallthrough);
        dispatchMethod.visitVarInsn(Opcodes.ALOAD, 0); // load "receiver"
        dispatchMethod.visitTypeInsn(Opcodes.CHECKCAST, emulationInterface);

        visitLoadArgs(dispatchMethod, methodType, 1 /* receiver already loaded above */);
        dispatchMethod.visitMethodInsn(Opcodes.INVOKEINTERFACE, emulationInterface, method.name(),
                method.descriptor(), /*itf=*/ true);
        dispatchMethod.visitInsn(methodType.getReturnType().getOpcode(Opcodes.IRETURN));

        dispatchMethod.visitLabel(fallthrough);
        // Trivial frame for the branch target: same empty stack as before
        dispatchMethod.visitFrame(Opcodes.F_SAME, 0, EMPTY_FRAME, 0, EMPTY_FRAME);
    }

    // Next, check for subtypes with specialized implementations and call them
    for (Class<?> tested : typechecks) {
        Label fallthrough = new Label();
        String testedName = tested.getName().replace('.', '/');
        // In case of a class this must be a member move; for interfaces use the companion.
        String target = tested.isInterface() ? InterfaceDesugaring.getCompanionClassName(testedName)
                : checkNotNull(memberMoves.get(rewriter.unprefix(testedName) + '#' + method.name()));
        dispatchMethod.visitVarInsn(Opcodes.ALOAD, 0); // load "receiver"
        dispatchMethod.visitTypeInsn(Opcodes.INSTANCEOF, testedName);
        dispatchMethod.visitJumpInsn(Opcodes.IFEQ, fallthrough);
        dispatchMethod.visitVarInsn(Opcodes.ALOAD, 0); // load "receiver"
        dispatchMethod.visitTypeInsn(Opcodes.CHECKCAST, testedName); // make verifier happy

        visitLoadArgs(dispatchMethod, methodType, 1 /* receiver already loaded above */);
        dispatchMethod.visitMethodInsn(Opcodes.INVOKESTATIC, target, method.name(),
                InterfaceDesugaring.companionDefaultMethodDescriptor(testedName, method.descriptor()),
                /*itf=*/ false);
        dispatchMethod.visitInsn(methodType.getReturnType().getOpcode(Opcodes.IRETURN));

        dispatchMethod.visitLabel(fallthrough);
        // Trivial frame for the branch target: same empty stack as before
        dispatchMethod.visitFrame(Opcodes.F_SAME, 0, EMPTY_FRAME, 0, EMPTY_FRAME);
    }

    // Call static type's default implementation in companion class
    dispatchMethod.visitVarInsn(Opcodes.ALOAD, 0); // load "receiver"
    visitLoadArgs(dispatchMethod, methodType, 1 /* receiver already loaded above */);
    dispatchMethod.visitMethodInsn(Opcodes.INVOKESTATIC, InterfaceDesugaring.getCompanionClassName(owner),
            method.name(), companionDesc, /*itf=*/ false);
    dispatchMethod.visitInsn(methodType.getReturnType().getOpcode(Opcodes.IRETURN));

    dispatchMethod.visitMaxs(0, 0);
    dispatchMethod.visitEnd();
}

From source file:com.google.devtools.build.lib.syntax.compiler.Jump.java

License:Open Source License

@Override
public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
    methodVisitor.visitJumpInsn(opCode, target);
    return stackSizeChange;
}

From source file:com.google.gag.agent.ThisHadBetterGenerator.java

License:Apache License

/**
 * The given Property needs to be either {@link Property#THE_BLUE_PILL} or
 * {@link Property#THE_RED_PILL}.// www .j av  a 2  s.co m
 */
private static void visitPill(MethodVisitor mv, boolean be, Property property, LocalVarInfo param, Label okay) {

    if (param.getType().getSort() != Type.OBJECT) {
        throw new AnnotationStateError("Unsupported type: " + param.getType());
    }

    // TODO: Also handle if parameter is null.

    Label notOkay = new Label();

    // See if the param type matches a Pill type
    mv.visitVarInsn(ALOAD, param.getIndex());
    mv.visitMethodInsn(INVOKEVIRTUAL, param.getType().getInternalName(), "getClass", "()Ljava/lang/Class;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;");
    mv.visitLdcInsn("Pill|ThePill|.*[\\.$]Pill|.*[\\.$]ThePill");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "matches", "(Ljava/lang/String;)Z");

    if (be) {
        // If the param type does not match a Pill type, that's not okay, go to exception.
        mv.visitJumpInsn(FALSE, notOkay);
    } else {
        // If the param type does not match a Pill type, then that's okay, skip exception.
        mv.visitJumpInsn(FALSE, okay);
    }

    // At this point, the param type matches a Pill type.
    // So check if the param type is an enum type.
    mv.visitVarInsn(ALOAD, param.getIndex());
    mv.visitTypeInsn(INSTANCEOF, "java/lang/Enum");

    if (be) {
        // If the param type is not an enum, that's not okay, go to exception.
        mv.visitJumpInsn(FALSE, notOkay);
    } else {
        // If the param type is not an enum, that's okay, skip exception.
        mv.visitJumpInsn(FALSE, okay);
    }

    // Check that the Pill type has the property specified in the annotation.
    // First try to match on "BLUE" (or "RED").
    mv.visitVarInsn(ALOAD, param.getIndex());
    mv.visitTypeInsn(CHECKCAST, "java/lang/Enum");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Enum", "name", "()Ljava/lang/String;");
    mv.visitLdcInsn(property == Property.THE_BLUE_PILL ? "BLUE" : "RED");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
    mv.visitJumpInsn(TRUE, be ? okay : notOkay);

    // Then try to see if the value ends with "BLUE_PILL" (or "RED_PILL").
    mv.visitVarInsn(ALOAD, param.getIndex());
    mv.visitTypeInsn(CHECKCAST, "java/lang/Enum");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Enum", "name", "()Ljava/lang/String;");
    mv.visitLdcInsn(property == Property.THE_BLUE_PILL ? "BLUE_PILL" : "RED_PILL");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "endsWith", "(Ljava/lang/String;)Z");
    mv.visitJumpInsn(be ? TRUE : FALSE, okay);

    mv.visitLabel(notOkay);
}

From source file:com.google.gwtorm.jdbc.AccessGen.java

License:Apache License

private void doBindOne(final MethodVisitor mv, final CodeGenSupport cgs, final ColumnModel field) {
    if (field.isNested() && field.isNotNull()) {
        for (final ColumnModel c : field.getAllLeafColumns()) {
            doBindOne(mv, cgs, c);//from  w ww .j a  va2 s  .c om
        }

    } else if (field.isNested()) {
        final int colIdx = cgs.getColumnIndex();
        final Label isnull = new Label();
        final Label end = new Label();

        cgs.setFieldReference(field);
        cgs.pushFieldValue();
        mv.visitJumpInsn(IFNULL, isnull);
        cgs.resetColumnIndex(colIdx);
        for (final ColumnModel c : field.getNestedColumns()) {
            doBindOne(mv, cgs, c);
        }
        mv.visitJumpInsn(GOTO, end);

        mv.visitLabel(isnull);
        cgs.resetColumnIndex(colIdx);
        for (final ColumnModel c : field.getAllLeafColumns()) {
            cgs.setFieldReference(c);
            dialect.getSqlTypeInfo(c).generatePreparedStatementNull(cgs);
        }

        mv.visitLabel(end);
    } else {
        cgs.setFieldReference(field);
        dialect.getSqlTypeInfo(field).generatePreparedStatementSet(cgs);
    }
}

From source file:com.google.gwtorm.jdbc.AccessGen.java

License:Apache License

private void doFetchOne(final MethodVisitor mv, final CodeGenSupport cgs, final ColumnModel field,
        final int reportLiveInto) {
    if (field.isNested()) {
        int oldIdx = cgs.getColumnIndex();
        final Type vType = CodeGenSupport.toType(field);
        final int livecnt;

        if (field.isNotNull()) {
            livecnt = -1;/*from  w  ww  .j  a v  a2  s  .com*/
        } else {
            livecnt = cgs.newLocal();
            cgs.push(0);
            mv.visitVarInsn(ISTORE, livecnt);
        }

        cgs.setFieldReference(field);
        cgs.fieldSetBegin();
        mv.visitTypeInsn(NEW, vType.getInternalName());
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, vType.getInternalName(), "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
        cgs.fieldSetEnd();

        cgs.resetColumnIndex(oldIdx);
        for (final ColumnModel c : field.getNestedColumns()) {
            doFetchOne(mv, cgs, c, livecnt);
        }

        if (livecnt >= 0) {
            oldIdx = cgs.getColumnIndex();

            final Label islive = new Label();
            mv.visitVarInsn(ILOAD, livecnt);
            mv.visitJumpInsn(IFNE, islive);
            cgs.setFieldReference(field);
            cgs.fieldSetBegin();
            mv.visitInsn(ACONST_NULL);
            cgs.fieldSetEnd();

            if (reportLiveInto >= 0) {
                final Label end = new Label();
                mv.visitJumpInsn(GOTO, end);
                mv.visitLabel(islive);
                mv.visitIincInsn(reportLiveInto, 1);
                mv.visitLabel(end);
            } else {
                mv.visitLabel(islive);
            }

            cgs.resetColumnIndex(oldIdx);
            cgs.freeLocal(livecnt);
        }

    } else {
        final int dupTo;
        if (reportLiveInto >= 0 && CodeGenSupport.toType(field).getSort() == Type.OBJECT) {
            dupTo = cgs.newLocal();
        } else {
            dupTo = -1;
        }

        cgs.setFieldReference(field);
        cgs.setDupOnFieldSetEnd(dupTo);
        dialect.getSqlTypeInfo(field).generateResultSetGet(cgs);

        if (reportLiveInto >= 0) {
            final Label wasnull = new Label();
            if (dupTo >= 0) {
                mv.visitVarInsn(ALOAD, dupTo);
                mv.visitJumpInsn(IFNULL, wasnull);
                cgs.freeLocal(dupTo);
            } else {
                cgs.pushSqlHandle();
                mv.visitMethodInsn(INVOKEINTERFACE, Type.getType(ResultSet.class).getInternalName(), "wasNull",
                        Type.getMethodDescriptor(Type.BOOLEAN_TYPE, new Type[] {}));
                mv.visitJumpInsn(IFNE, wasnull);
            }
            mv.visitIincInsn(reportLiveInto, 1);
            mv.visitLabel(wasnull);
        }
    }
}