Example usage for org.objectweb.asm Opcodes ICONST_1

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

Introduction

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

Prototype

int ICONST_1

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

Click Source Link

Usage

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  w  ww.j a  v  a 2  s  .  co  m*/
            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;
            }/*  w ww .  j a va2 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 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 {/*from ww  w  . j av a 2 s . c o 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   w ww  .  j ava2s  .  c  o m*/
        }
        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 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);/*from   w  w  w  . j av a 2 s  .c  om*/
            // 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;
            }//from  ww w  . j  ava2 s  . co 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);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator4.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] 

            mv.visitInsn(Opcodes.DUP2);//  w  w w .j a va2 s  .  c o m
            // stack = [array] [index] [array] [index]

            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            // 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("Decremented (--a) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitInsn(Opcodes.DUP_X2);
            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.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitInsn(Opcodes.DUP2_X2);
            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.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitInsn(Opcodes.DUP2_X2);
            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.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2B);
            mv.visitInsn(Opcodes.DUP_X2);
            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.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            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.UOIMutator4.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")) {
                // 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.ISUB);
                // 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;
            }/*from   w  ww.ja  v  a2  s. co m*/
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (--a) float field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (--a) long field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (--a) double field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (--a) double field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (--a) short field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                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("Decremented (--a) static integer field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (--a) static float field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (--a) static long field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (--a) static double field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (--a) static byte field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (--a) static short field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator.java

License:Apache License

private static ZeroOperandMutation ireturnMutation() {
    return new ZeroOperandMutation() {

        public void apply(final int opCode, final MethodVisitor mv) {
            final Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l1);
            mv.visitInsn(Opcodes.ICONST_0);
            mv.visitInsn(Opcodes.IRETURN);
            mv.visitLabel(l1);/*from w  w  w  .  jav a2s.  c  om*/
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IRETURN);
        }

        public String decribe(final int opCode, final MethodInfo methodInfo) {
            return "replaced return of integer sized value with (x == 0 ? 1 : 0)";
        }

    };
}

From source file:org.sonar.java.bytecode.cfg.BytecodeCFGBuilderTest.java

License:Open Source License

@Test
public void visited_label_should_be_assigned_to_true_successor() throws Exception {
    Label label0 = new Label();
    Label label1 = new Label();
    BytecodeCFG cfg = new Instructions().visitVarInsn(Opcodes.ALOAD, 0).visitJumpInsn(Opcodes.IFNULL, label0)
            .visitJumpInsn(Opcodes.IFEQ, label0).visitInsn(Opcodes.ICONST_0).visitJumpInsn(Opcodes.GOTO, label1)
            .visitLabel(label0).visitInsn(Opcodes.ICONST_1).visitLabel(label1).visitInsn(Opcodes.IRETURN).cfg();

    BytecodeCFG.Block block3 = cfg.blocks.get(3);
    assertThat(block3.terminator.opcode).isEqualTo(Opcodes.IFEQ);
    assertThat(block3.falseSuccessor()).isNotNull().isSameAs(cfg.blocks.get(4));
    assertThat(block3.trueSuccessor()).isNotNull().isSameAs(cfg.blocks.get(2));
    assertThat(block3.successors).hasSize(2);
    assertThat(block3.successors()).hasSize(2);
}