List of usage examples for org.objectweb.asm Opcodes PUTSTATIC
int PUTSTATIC
To view the source code for org.objectweb.asm Opcodes PUTSTATIC.
Click Source Link
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
/** * Generates the instruction to store the top stack value in a static field. * * @param owner the class in which the field is defined. * @param name the name of the field./*from w w w. ja v a 2s.c om*/ * @param type the type of the field. */ public void putStatic(final Type owner, final String name, final Type type) { fieldInsn(Opcodes.PUTSTATIC, owner, name, type); }
From source file:org.jboss.byteman.rule.expression.StaticExpression.java
License:Open Source License
@Override public void compileAssign(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); int currentStack = compileContext.getStackCount(); int size = (type.getNBytes() > 4 ? 2 : 1); // copy the value so we leave a result // increases stack height by size words if (size == 1) { mv.visitInsn(Opcodes.DUP);//from w ww . jav a 2s . co m } else { mv.visitInsn(Opcodes.DUP2); } compileContext.addStackCount(size); // compile a static field update if (isPublicField) { String ownerType = Type.internalName(field.getDeclaringClass()); String fieldName = field.getName(); String fieldType = Type.internalName(field.getType(), true); compileContext.addStackCount(-size); mv.visitFieldInsn(Opcodes.PUTSTATIC, ownerType, fieldName, fieldType); } else { // since this is a private field we need to do the update using reflection // box the value to an object if necessary // [.. val(s) val(s) ==> val(s) valObj] if (type.isPrimitive()) { compileBox(Type.boxType(type), mv, compileContext); } // stack the helper and then swap it so it goes under the value // [.. val(s) valObj ==> val(s) valObj helper ==> val(s) helper valObj] mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.SWAP); // stack a null owner then swap it so it goes under the value // [val(s) helper valObj ==> val(s) helper valObj null ==> val(s) helper null valObj] mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.SWAP); // now stack the field index // [.. val(s) helper null valObj ==> val(s) helper null valObj index ] mv.visitLdcInsn(fieldIndex); // we added three more words compileContext.addStackCount(3); // use the HelperAdapter method setAccessibleField to set the field value mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.internalName(HelperAdapter.class), "setAccessibleField", "(Ljava/lang/Object;Ljava/lang/Object;I)V"); // we popped four args compileContext.addStackCount(-4); } if (compileContext.getStackCount() != currentStack) { throw new CompileException("StaticExpression.compileAssign : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack); } }
From source file:org.kohsuke.accmod.impl.Checker.java
License:Open Source License
/** * Inspects a class for the restriction violations. *//* w w w . j a va2 s. c o m*/ public void checkClass(File clazz) throws IOException { FileInputStream in = new FileInputStream(clazz); try { ClassReader cr = new ClassReader(in); cr.accept(new ClassVisitor(Opcodes.ASM5) { private String className; private String methodName, methodDesc; private int line; @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { this.className = name; if (superName != null) getRestrictions(superName).usedAsSuperType(currentLocation, errorListener); if (interfaces != null) { for (String intf : interfaces) getRestrictions(intf).usedAsInterface(currentLocation, errorListener); } } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { this.methodName = name; this.methodDesc = desc; return new MethodVisitor(Opcodes.ASM5) { @Override public void visitLineNumber(int _line, Label start) { line = _line; } public void visitTypeInsn(int opcode, String type) { switch (opcode) { case Opcodes.NEW: getRestrictions(type).instantiated(currentLocation, errorListener); } } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { getRestrictions(owner + '.' + name + desc).invoked(currentLocation, errorListener); } @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { Restrictions r = getRestrictions(owner + '.' + name); switch (opcode) { case Opcodes.GETSTATIC: case Opcodes.GETFIELD: r.read(currentLocation, errorListener); break; case Opcodes.PUTSTATIC: case Opcodes.PUTFIELD: r.written(currentLocation, errorListener); break; } super.visitFieldInsn(opcode, owner, name, desc); } }; } /** * Constant that represents the current location. */ private final Location currentLocation = new Location() { public String getClassName() { return className.replace('/', '.'); } public String getMethodName() { return methodName; } public String getMethodDescriptor() { return methodDesc; } public int getLineNumber() { return line; } public String toString() { return className + ':' + line; } public ClassLoader getDependencyClassLoader() { return dependencies; } public boolean isInTheSameModuleAs(RestrictedElement e) { // TODO throw new UnsupportedOperationException(); } }; }, SKIP_FRAMES); } finally { in.close(); } }
From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnFinder.java
License:Apache License
private static boolean isPutstaticInstruction(final AbstractInsnNode insn) { return Opcodes.PUTSTATIC == insn.getOpcode(); }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * Add the <clinit> method. This initializes the static fields that have initializers. * @param classRep// w ww . ja v a2 s. c om * @param cv * @param initializeForAsserts * @throws JavaGenerationException */ private static void encodeClassInitializer(JavaClassRep classRep, ClassVisitor cv, boolean initializeForAsserts) throws JavaGenerationException { // Add initializers for the statically-initialized fields. final int nFields = classRep.getNFieldDeclarations(); if (!classRep.hasInitializedStaticField() && !initializeForAsserts) { //we don't need to bother adding a static initializer if there are no static fields to initialize. //note that javac also has this optimization. return; } MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); // Start the method's code. mv.visitCode(); final JavaTypeName classRepTypeName = classRep.getClassName(); /* * If this class contains assert statements we need to initialize the static final synthetic boolean field * '$assertionsDisabled'. * This is done by loading the Class constant for the top level class. The method 'desiredAssertionStatus()' * is then invoked on this Class object and the returned value is used to initialize $assertionsDisabled. */ if (initializeForAsserts) { // Get the fully-qualified internal class name. final String className = classRepTypeName.getJVMInternalName(); // Get the top level class name. String topLevelClassName = getTopLevelClassJVMInternalName(className); // Load the Class constant for the top level class mv.visitLdcInsn(Type.getType("L" + topLevelClassName + ";")); // Now that we have the Class constant for the top level class we invoke the method // desiredAssertionStatus on it and use the resulting value to initialize the static field $assertionsDisabled in this class. mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "desiredAssertionStatus", "()Z"); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IFNE, l0); mv.visitInsn(Opcodes.ICONST_1); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l1); mv.visitLabel(l0); mv.visitInsn(Opcodes.ICONST_0); mv.visitLabel(l1); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, "$assertionsDisabled", "Z"); } for (int i = 0; i < nFields; ++i) { JavaFieldDeclaration fieldDecl = classRep.getFieldDeclaration(i); JavaExpression initializer = fieldDecl.getInitializer(); if (initializer != null && Modifier.isStatic(fieldDecl.getModifiers())) { GenerationContext context = new GenerationContext(new HashMap<String, JavaTypeName>(), new HashMap<String, Integer>(), 0, mv, classRepTypeName); //evaluate the initializer encodeExpr(initializer, context); //do the assignment mv.visitFieldInsn(Opcodes.PUTSTATIC, classRep.getClassName().getJVMInternalName(), fieldDecl.getFieldName(), fieldDecl.getFieldType().getJVMDescriptor()); } } // return. mv.visitInsn(Opcodes.RETURN); //mark the end of the method with a call to visitMaxs mv.visitMaxs(0, 0); // End the method. mv.visitEnd(); }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * @param assignment//from w w w. j a va2s . c o m * @param context * @param retainValue whether to leave on the stack the result of evaluating the expression. This is an optimization. * The normal case for an assignment expression is with retainValue = true. However, often assignments are used in * statement form in which case the resulting value is immediately popped off the stack. Hence there is no point to * push it onto the stack in the first place. * @return the type of the result on the operand stack (assuming retainValue is true). * @throws JavaGenerationException */ private static JavaTypeName encodeAssignmentExpr(JavaExpression.Assignment assignment, GenerationContext context, boolean retainValue) throws JavaGenerationException { MethodVisitor mv = context.getMethodVisitor(); JavaExpression.Nameable lhs = assignment.getLeftHandSide(); if (lhs instanceof LocalName) { // Determine what type of creature this name represents. // Note that because of the order of lookups, this takes scoping into account. LocalName localName = (LocalName) lhs; String varName = localName.getName(); if (context.getLocalVarIndex(varName) != -1) { lhs = new LocalVariable(varName, localName.getTypeName()); } else if (context.getMethodVarIndex(varName) != -1) { lhs = new MethodVariable(varName); } else { lhs = new JavaField.Instance(null, varName, localName.getTypeName()); } } // assign the value if (lhs instanceof JavaField.Instance) { JavaField.Instance javaInstanceField = (JavaField.Instance) lhs; //push the reference to the Java field itself. We can't just call encodeJavaField because we need the type of the instance object. JavaExpression instance = javaInstanceField.getInstance(); JavaTypeName instanceType; if (instance == null) { //use 'this' as the instance expression, so if the field is 'foo', then it is 'this.foo'. instanceType = encodeThis(context); } else { instanceType = encodeExpr(instance, context); } //push the rhs expression // the type of the assignment takes on the type of the value (not the assigned variable). JavaTypeName returnType = encodeExpr(assignment.getValue(), context); if (retainValue) { //duplicate the value so that a copy will be left over after assignment //field, value ---> //value, field, value mv.visitInsn(getDupX1OpCode(returnType)); } //do the assignment mv.visitFieldInsn(Opcodes.PUTFIELD, instanceType.getJVMInternalName(), javaInstanceField.getFieldName(), javaInstanceField.getFieldType().getJVMDescriptor()); return returnType; } else if (lhs instanceof JavaField.Static) { JavaField.Static javaStaticField = (JavaField.Static) lhs; //push the rhs expression // the type of the assignment takes on the type of the value (not the assigned variable). JavaTypeName returnType = encodeExpr(assignment.getValue(), context); if (retainValue) { //duplicate the value so that a copy will be left over after assignment //value ---> //value, value mv.visitInsn(getDupOpCode(returnType)); } //do the assignment mv.visitFieldInsn(Opcodes.PUTSTATIC, javaStaticField.getInvocationClass().getJVMInternalName(), javaStaticField.getFieldName(), javaStaticField.getFieldType().getJVMDescriptor()); return returnType; } else if (lhs instanceof LocalVariable) { LocalVariable localVariable = (LocalVariable) lhs; int localVarIndex = context.getLocalVarIndex(localVariable.getName()); //push the rhs expression JavaTypeName returnType = encodeExpr(assignment.getValue(), context); if (retainValue) { //duplicate the value so that a copy will be left over after assignment //value ---> //value, value mv.visitInsn(getDupOpCode(returnType)); } //encode the store instruction mv.visitVarInsn(getStoreOpCode(localVariable.getTypeName()), localVarIndex); return returnType; } else if (lhs instanceof MethodVariable) { MethodVariable methodVariable = (MethodVariable) lhs; String varName = methodVariable.getName(); int methodVarIndex = context.getMethodVarIndex(varName); JavaTypeName methodVarType = context.getMethodVarType(varName); //push the rhs expression JavaTypeName returnType = encodeExpr(assignment.getValue(), context); if (retainValue) { //duplicate the value so that a copy will be left over after assignment //value ---> //value, value mv.visitInsn(getDupOpCode(returnType)); } //encode the store instruction mv.visitVarInsn(getStoreOpCode(methodVarType), methodVarIndex); return returnType; } else if (lhs instanceof ArrayAccess) { ArrayAccess arrayAccess = (ArrayAccess) lhs; // Add the instructions to get the array ref. encodeExpr(arrayAccess.getArrayReference(), context); // Add the instructions to evaluate the array index. encodeExpr(arrayAccess.getArrayIndex(), context); // add the instructions to evaluate the expression to assign. JavaTypeName returnType = encodeExpr(assignment.getValue(), context); if (retainValue) { //duplicate the value so that a copy will be left over after assignment //arrayRef index value ---> //value arrayRef index value mv.visitInsn(getDupX2OpCode(returnType)); } //encode the store array element instruction mv.visitInsn(getArrayStoreOpCode(returnType)); return returnType; } throw new JavaGenerationException("Cannot assign to this type of expression: " + lhs); }
From source file:org.pitest.mutationtest.engine.gregor.AvoidAssertsMethodAdapter.java
License:Apache License
@Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { if ("$assertionsDisabled".equals(name)) { if (opcode == Opcodes.GETSTATIC) { this.context.disableMutations(DISABLE_REASON); this.assertBlockStarted = true; } else if (opcode == Opcodes.PUTSTATIC) { this.context.enableMutatations(DISABLE_REASON); }//from w w w . j a va 2 s .c o m } super.visitFieldInsn(opcode, owner, name, desc); }
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; }/*from w ww .ja v a 2s . 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 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 w w.ja va 2s .com*/ } 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 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 w w w .ja v a 2s.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.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); }