Example usage for org.objectweb.asm Opcodes LCONST_1

List of usage examples for org.objectweb.asm Opcodes LCONST_1

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes LCONST_1.

Prototype

int LCONST_1

To view the source code for org.objectweb.asm Opcodes LCONST_1.

Click Source Link

Usage

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

/**
 * Encodes instructions to push a long value onto the operand stack.
 * @param value to be pushed//  w ww  .  j  ava  2s  .  c o m
 * @param context
 * @return JavaTypeName the type of the result on the operand stack.      
 */
private static JavaTypeName encodePushLongValue(Long value, GenerationContext context) {

    MethodVisitor mv = context.getMethodVisitor();

    long v = value.longValue();

    if (v == 0) {
        mv.visitInsn(Opcodes.LCONST_0);

    } else if (v == 1) {
        mv.visitInsn(Opcodes.LCONST_1);

    } else {
        // Create a Constant pool entry
        mv.visitLdcInsn(value);
    }

    return JavaTypeName.LONG;
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator1.java

License:Apache License

@Override
public void visitVarInsn(int opcode, int var) {
    mv.visitVarInsn(opcode, var);

    switch (opcode) {
    case Opcodes.ILOAD:
        if (this.shouldMutate("Incremented (a++) integer local variable number " + var)) {
            mv.visitIincInsn(var, 1);
        }/*  w  ww.  ja va  2 s .c  o m*/
        break;
    case Opcodes.FLOAD:
        if (this.shouldMutate("Incremented (a++) float local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitVarInsn(Opcodes.FSTORE, var);
        }
        break;
    case Opcodes.LLOAD:
        if (this.shouldMutate("Incremented (a++) long local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LADD);
            mv.visitVarInsn(Opcodes.LSTORE, var);
        }
        break;
    case Opcodes.DLOAD:
        if (this.shouldMutate("Incremented (a++) double local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DADD);
            mv.visitVarInsn(Opcodes.DSTORE, var);
        }
        break;

    default:
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator1.java

License:Apache License

@Override
public void visitInsn(final int opcode) {
    // I F L D + BS
    switch (opcode) {
    case Opcodes.IALOAD:
        if (this.shouldMutate("Incremented (a++) integer array field")) {
            mv.visitInsn(Opcodes.DUP2); // Array and its index on stack, times two
            mv.visitInsn(opcode); // IALOAD
            mv.visitInsn(Opcodes.DUP_X2); // put the result of array[index] under [array ref] [index] [array[index]]
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);//from  www  . j a va2  s .  c  om
            mv.visitInsn(Opcodes.IASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FALOAD:
        if (this.shouldMutate("Incremented (a++) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LALOAD:
        if (this.shouldMutate("Incremented (a++) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LADD);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DALOAD:
        if (this.shouldMutate("Incremented (a++) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DADD);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.BALOAD:
        if (this.shouldMutate("Incremented (a++) byte array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            mv.visitInsn(Opcodes.I2B);
            mv.visitInsn(Opcodes.BASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.SALOAD:
        if (this.shouldMutate("Incremented (a++) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            mv.visitInsn(Opcodes.I2S);
            mv.visitInsn(Opcodes.SASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator1.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (a++) integer field " + name)) {
                // Assuming we have the reference to [this] on the stack
                mv.visitInsn(Opcodes.DUP); // dup [this]
                mv.visitFieldInsn(opcode, owner, name, desc); // stack = [this] [this.field]
                mv.visitInsn(Opcodes.DUP_X1); // stack = [this.field] [this] [this.field]
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD); // stack = [this.field] [this] [this.field +1]
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }//ww  w.  j  ava 2  s . com
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (a++) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (a++) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (a++) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (a++) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (a++) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (a++) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (a++) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (a++) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (a++) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (a++) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (a++) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitVarInsn(int opcode, int var) {
    mv.visitVarInsn(opcode, var);
    switch (opcode) {
    case Opcodes.ILOAD:
        if (this.shouldMutate("Decremented (a--) integer local variable number " + var)) {
            mv.visitIincInsn(var, -1);
        }//  www .jav a  2 s . c  o  m
        break;
    case Opcodes.FLOAD:
        if (this.shouldMutate("Decremented (a--) float local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitVarInsn(Opcodes.FSTORE, var);
        }
        break;
    case Opcodes.LLOAD:
        if (this.shouldMutate("Decremented (a--) long local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitVarInsn(Opcodes.LSTORE, var);
        }
        break;
    case Opcodes.DLOAD:
        if (this.shouldMutate("Decremented (a--) double local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitVarInsn(Opcodes.DSTORE, var);
        }
        break;
    default:
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitInsn(final int opcode) {
    // I F L D + BS
    switch (opcode) {
    case Opcodes.IALOAD:
        if (this.shouldMutate("Decremented (a--) integer array field")) {
            // stack = [array] [index] , wanted to perform an IALOAD
            mv.visitInsn(Opcodes.DUP2); // stack = [array] [index] [array] [index]
            mv.visitInsn(opcode); // stack = [array] [index] [array(index)]
            mv.visitInsn(Opcodes.DUP_X2); // stack = [array(index)] [array] [index] [array(index)]
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB); // stack = [array(index)] [array] [index] [array(index)-1]
            mv.visitInsn(Opcodes.IASTORE);
        } else {/*ww  w . ja  va  2  s  .  co  m*/
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FALOAD:
        if (this.shouldMutate("Decremented (a--) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LALOAD:
        if (this.shouldMutate("Decremented (a--) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DALOAD:
        if (this.shouldMutate("Decremented (a--) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.BALOAD:
        if (this.shouldMutate("Decremented (a--) byte array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2B);
            mv.visitInsn(Opcodes.BASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.SALOAD:
        if (this.shouldMutate("Decremented (a--) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2S);
            mv.visitInsn(Opcodes.SASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (a--) integer field " + name)) {
                // stack  = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field] [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }//from  ww  w . j  ava  2 s  . c om
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (a--) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (a--) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (a--) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (a--) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (a--) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (a--) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this.sfield]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this.sfield] [this.sfield]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                // stack = [this.sfield] [this.sfield -1]

                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (a--) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (a--) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (a--) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (a--) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (a--) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator3.java

License:Apache License

@Override
public void visitVarInsn(int opcode, int var) {
    switch (opcode) {
    case Opcodes.ILOAD:
        if (this.shouldMutate("Incremented (++a) integer local variable number " + var)) {
            mv.visitIincInsn(var, 1);
        }//from  www.j a v  a  2s .c  om
        mv.visitVarInsn(opcode, var);
        break;
    case Opcodes.FLOAD:
        if (this.shouldMutate("Incremented (++a) float local variable number " + var)) {
            mv.visitVarInsn(opcode, var);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitVarInsn(Opcodes.FSTORE, var);
        }
        mv.visitVarInsn(opcode, var);
        break;
    case Opcodes.LLOAD:
        if (this.shouldMutate("Incremented (++a) long local variable number " + var)) {
            mv.visitVarInsn(opcode, var);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LADD);
            mv.visitVarInsn(Opcodes.LSTORE, var);
        }
        mv.visitVarInsn(opcode, var);
        break;
    case Opcodes.DLOAD:
        if (this.shouldMutate("Incremented (++a) double local variable number " + var)) {
            mv.visitVarInsn(opcode, var);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DADD);
            mv.visitVarInsn(Opcodes.DSTORE, var);
        }
        mv.visitVarInsn(opcode, var);
        break;
    default:
        mv.visitVarInsn(opcode, var);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator3.java

License:Apache License

@Override
public void visitInsn(final int opcode) {
    // I F L D + BS
    switch (opcode) {
    case Opcodes.IALOAD:
        if (this.shouldMutate("Incremented (++a) integer array field")) {
            // stack = [array] [index]

            mv.visitInsn(Opcodes.DUP2);// w w w.j  av  a  2 s . co  m
            // stack = [array] [index] [array] [index]

            mv.visitInsn(opcode);
            // stack = [array] [index] [array(index)]

            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            // stack = [array] [index] [array(index)+1]

            mv.visitInsn(Opcodes.DUP_X2);
            // stack = [array(index)+1] [array] [index] [array(index)+1]

            mv.visitInsn(Opcodes.IASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FALOAD:
        if (this.shouldMutate("Incremented (++a) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LALOAD:
        if (this.shouldMutate("Incremented (++a) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LADD);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DALOAD:
        if (this.shouldMutate("Incremented (++a) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DADD);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.BALOAD:
        if (this.shouldMutate("Incremented (++a) byte array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            mv.visitInsn(Opcodes.I2B);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.BASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.SALOAD:
        if (this.shouldMutate("Incremented (++a) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            mv.visitInsn(Opcodes.I2S);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.SASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator3.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (++a) integer field " + name)) {
                // stack = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                // stack = [this] [this.field +1]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field +1] [this] [this.field +1]

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }/* www .  ja v a 2  s .  c  o  m*/
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (++a) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (++a) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (++a) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (++a) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (++a) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (++a) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (++a) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (++a) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (++a) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (++a) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (++a) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}