List of usage examples for org.objectweb.asm Opcodes GETSTATIC
int GETSTATIC
To view the source code for org.objectweb.asm Opcodes GETSTATIC.
Click Source Link
From source file:org.kohsuke.accmod.impl.Checker.java
License:Open Source License
/** * Inspects a class for the restriction violations. *///from w ww . ja v a 2 s .c om 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.lambdamatic.analyzer.ast.LambdaExpressionReader.java
License:Open Source License
/** * Reads the bytecode from the given {@link InsnCursor}'s <strong>current position</strong>, until * there is no further instruction to proceed. It is the responsability of the caller to set the * cursor position.//from w w w. j av a 2 s. c o m * * @param insnCursor the instruction cursor used to read the bytecode. * @param expressionStack the expression stack to put on or pop from. * @param localVariables the local variables * @return a {@link List} of {@link Statement} containing the {@link Statement} */ private List<Statement> readStatements(final InsnCursor insnCursor, final Stack<Expression> expressionStack, final List<CapturedArgument> capturedArguments, final LocalVariables localVariables) { final List<Statement> statements = new ArrayList<>(); while (insnCursor.hasCurrent()) { final AbstractInsnNode currentInstruction = insnCursor.getCurrent(); switch (currentInstruction.getType()) { case AbstractInsnNode.VAR_INSN: final VarInsnNode varInstruction = (VarInsnNode) currentInstruction; switch (currentInstruction.getOpcode()) { // load a reference onto the stack from a local variable case Opcodes.ALOAD: case Opcodes.ILOAD: // load an int value from a local variable // Note: The 'var' operand is the index of a local variable // all captured arguments come before the local variable in the method signature, // which means that the local variables table is empty on the first slots which are // "allocated" // for the captured arguments. if (varInstruction.var < capturedArguments.size()) { // if the variable index matches a captured argument // note: not using actual captured argument but rather, use a _reference_ to it. final Object capturedArgumentValue = capturedArguments.get(varInstruction.var).getValue(); final Class<?> capturedArgumentValueType = capturedArgumentValue != null ? capturedArgumentValue.getClass() : Object.class; final CapturedArgumentRef capturedArgumentRef = new CapturedArgumentRef(varInstruction.var, capturedArgumentValueType); expressionStack.add(capturedArgumentRef); } else { // the variable index matches a local variable final LocalVariableNode var = localVariables.load(varInstruction.var); expressionStack.add(new LocalVariable(var.index, var.name, readSignature(var.desc))); } break; case Opcodes.ASTORE: // store a reference into a local variable localVariables.store(varInstruction.var); break; default: throw new AnalyzeException( "Unexpected Variable instruction code: " + varInstruction.getOpcode()); } break; case AbstractInsnNode.LDC_INSN: // let's move this instruction on top of the stack until it // is used as an argument during a method call final LdcInsnNode ldcInsnNode = (LdcInsnNode) currentInstruction; final Expression constant = ExpressionFactory.getExpression(ldcInsnNode.cst); LOGGER.trace("Stacking constant {}", constant); expressionStack.add(constant); break; case AbstractInsnNode.FIELD_INSN: final FieldInsnNode fieldInsnNode = (FieldInsnNode) currentInstruction; switch (fieldInsnNode.getOpcode()) { case Opcodes.GETSTATIC: final Type ownerType = Type.getType(fieldInsnNode.desc); final FieldAccess staticFieldAccess = new FieldAccess(new ClassLiteral(getType(ownerType)), fieldInsnNode.name); expressionStack.add(staticFieldAccess); break; case Opcodes.GETFIELD: final Expression fieldAccessParent = expressionStack.pop(); final FieldAccess fieldAccess = new FieldAccess(fieldAccessParent, fieldInsnNode.name); expressionStack.add(fieldAccess); break; case Opcodes.PUTFIELD: final Expression fieldAssignationValue = expressionStack.pop(); final Expression parentSource = expressionStack.pop(); final FieldAccess source = new FieldAccess(parentSource, fieldInsnNode.name); final Assignment assignmentExpression = new Assignment(source, fieldAssignationValue); statements.add(new ExpressionStatement(assignmentExpression)); break; default: throw new AnalyzeException("Unexpected field instruction type: " + fieldInsnNode.getOpcode()); } break; case AbstractInsnNode.METHOD_INSN: final MethodInsnNode methodInsnNode = (MethodInsnNode) currentInstruction; final Type[] argumentTypes = Type.getArgumentTypes(methodInsnNode.desc); final List<Expression> args = new ArrayList<>(); final List<Class<?>> parameterTypes = new ArrayList<>(); Stream.of(argumentTypes).forEach(argumentType -> { final Expression arg = expressionStack.pop(); final String argumentClassName = argumentType.getClassName(); args.add(castOperand(arg, argumentClassName)); try { parameterTypes.add(ClassUtils.getClass(argumentClassName)); } catch (Exception e) { throw new AnalyzeException("Failed to find class '" + argumentClassName + "'", e); } }); // arguments appear in reverse order in the bytecode Collections.reverse(args); switch (methodInsnNode.getOpcode()) { case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKESPECIAL: // object instantiation if (methodInsnNode.name.equals("<init>")) { final ObjectInstanciation objectVariable = (ObjectInstanciation) expressionStack.pop(); objectVariable.setInitArguments(args); } else { final Expression sourceExpression = expressionStack.pop(); final Method javaMethod = ReflectionUtils.findJavaMethod(sourceExpression.getJavaType(), methodInsnNode.name, parameterTypes); final Class<?> returnType = findReturnType(insnCursor, javaMethod); final MethodInvocation invokedMethod = new MethodInvocation(sourceExpression, javaMethod, returnType, args); expressionStack.add(invokedMethod); } break; case Opcodes.INVOKESTATIC: final Type type = Type.getObjectType(methodInsnNode.owner); try { final Class<?> sourceClass = Class.forName(type.getClassName()); final Method javaMethod = ReflectionUtils.findJavaMethod(sourceClass, methodInsnNode.name, parameterTypes); final Class<?> returnType = findReturnType(insnCursor, javaMethod); final MethodInvocation invokedStaticMethod = new MethodInvocation( new ClassLiteral(sourceClass), javaMethod, returnType, args); expressionStack.add(invokedStaticMethod); } catch (ClassNotFoundException e) { throw new AnalyzeException("Failed to retrieve class for " + methodInsnNode.owner, e); } break; default: throw new AnalyzeException("Unexpected method invocation type: " + methodInsnNode.getOpcode()); } break; case AbstractInsnNode.INVOKE_DYNAMIC_INSN: final InvokeDynamicInsnNode invokeDynamicInsnNode = (InvokeDynamicInsnNode) currentInstruction; final Handle handle = (Handle) invokeDynamicInsnNode.bsmArgs[1]; final int argNumber = Type.getArgumentTypes(invokeDynamicInsnNode.desc).length; final List<CapturedArgumentRef> lambdaArgs = new ArrayList<>(); for (int i = 0; i < argNumber; i++) { final Expression expr = expressionStack.pop(); if (expr.getExpressionType() != ExpressionType.CAPTURED_ARGUMENT_REF) { throw new AnalyzeException("Unexpected argument type when following InvokeDynamic call: " + expr.getExpressionType()); } lambdaArgs.add((CapturedArgumentRef) expr); // , expr.getValue() } Collections.reverse(lambdaArgs); final EmbeddedSerializedLambdaInfo lambdaInfo = new EmbeddedSerializedLambdaInfo(handle.getOwner(), handle.getName(), handle.getDesc(), lambdaArgs, capturedArguments); final LambdaExpression lambdaExpression = LambdaExpressionAnalyzer.getInstance() .analyzeExpression(lambdaInfo); expressionStack.add(lambdaExpression); break; case AbstractInsnNode.JUMP_INSN: statements.addAll( readJumpInstruction(insnCursor, expressionStack, capturedArguments, localVariables)); return statements; case AbstractInsnNode.INT_INSN: readIntInstruction((IntInsnNode) currentInstruction, expressionStack, localVariables); break; case AbstractInsnNode.INSN: final List<Statement> instructionStatement = readInstruction(insnCursor, expressionStack, capturedArguments, localVariables); statements.addAll(instructionStatement); break; case AbstractInsnNode.TYPE_INSN: readTypeInstruction((TypeInsnNode) currentInstruction, expressionStack, localVariables); break; default: throw new AnalyzeException( "This is embarrassing... We've reached an unexpected instruction operator: " + currentInstruction.getType()); } insnCursor.next(); } return statements; }
From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java
License:Apache License
/** * load the constant on the operand stack. primitives auto-boxed. *//*from w w w .ja va 2 s . com*/ void loadConstant(Object value, MethodVisitor mv) { if (value == null) { mv.visitInsn(Opcodes.ACONST_NULL); } else if (value instanceof String) { mv.visitLdcInsn(value); } else if (value instanceof Character) { String className = "java/lang/Character"; mv.visitTypeInsn(Opcodes.NEW, className); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(value); String methodType = "(C)V"; mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", methodType); } else if (value instanceof Number) { /** todo it would be more efficient to generate class constants */ Number n = (Number) value; String className = BytecodeHelper.getClassInternalName(value.getClass().getName()); mv.visitTypeInsn(Opcodes.NEW, className); mv.visitInsn(Opcodes.DUP); String methodType; if (n instanceof Integer) { //pushConstant(n.intValue()); mv.visitLdcInsn(n); methodType = "(I)V"; } else if (n instanceof Double) { mv.visitLdcInsn(n); methodType = "(D)V"; } else if (n instanceof Float) { mv.visitLdcInsn(n); methodType = "(F)V"; } else if (n instanceof Long) { mv.visitLdcInsn(n); methodType = "(J)V"; } else if (n instanceof BigDecimal) { mv.visitLdcInsn(n.toString()); methodType = "(Ljava/lang/String;)V"; } else if (n instanceof BigInteger) { mv.visitLdcInsn(n.toString()); methodType = "(Ljava/lang/String;)V"; } else if (n instanceof Short) { mv.visitLdcInsn(n); methodType = "(S)V"; } else if (n instanceof Byte) { mv.visitLdcInsn(n); methodType = "(B)V"; } else { throw new ClassGeneratorException("Cannot generate bytecode for constant: " + value + " of type: " + value.getClass().getName() + ". Numeric constant type not supported."); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", methodType); } else if (value instanceof Boolean) { Boolean bool = (Boolean) value; String text = (bool.booleanValue()) ? "TRUE" : "FALSE"; mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", text, "Ljava/lang/Boolean;"); } else if (value instanceof Class) { Class vc = (Class) value; if (vc.getName().equals("java.lang.Void")) { // load nothing here for void } else { throw new ClassGeneratorException("Cannot generate bytecode for constant: " + value + " of type: " + value.getClass().getName()); } } else { throw new ClassGeneratorException( "Cannot generate bytecode for constant: " + value + " of type: " + value.getClass().getName()); } }
From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java
License:Apache License
/** * convert boolean to Boolean//from w w w. j a va 2 s . co m * @param mv */ public void boxBoolean(MethodVisitor mv) { Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, l0); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "TRUE", "Ljava/lang/Boolean;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l1); mv.visitLabel(l0); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "FALSE", "Ljava/lang/Boolean;"); mv.visitLabel(l1); }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * Creates the code that references a Java field within an expression. * @param javaField the java field /*w w w. j a v a2 s . com*/ * @param context * @return JavaTypeName the type of the javaField argument. * @throws JavaGenerationException */ private static JavaTypeName encodeJavaFieldExpr(JavaField javaField, GenerationContext context) throws JavaGenerationException { if (javaField instanceof JavaField.This) { //the special 'this' field. return encodeThis(context); } MethodVisitor mv = context.getMethodVisitor(); if (javaField instanceof JavaField.Instance) { JavaField.Instance javaInstanceField = (JavaField.Instance) javaField; 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); } JavaTypeName fieldType = javaField.getFieldType(); mv.visitFieldInsn(Opcodes.GETFIELD, instanceType.getJVMInternalName(), javaField.getFieldName(), fieldType.getJVMDescriptor()); return fieldType; } if (javaField instanceof JavaField.Static) { JavaField.Static javaStaticField = (JavaField.Static) javaField; JavaTypeName fieldType = javaField.getFieldType(); mv.visitFieldInsn(Opcodes.GETSTATIC, javaStaticField.getInvocationClass().getJVMInternalName(), javaField.getFieldName(), fieldType.getJVMDescriptor()); return fieldType; } throw new IllegalStateException(); }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * Creates the Java code for a given class literal expression, pushing the result onto the operand stack. * @param classLiteral the class literal expression. * @param context the generation context. * @return the type of the result on the operand stack. *//*from w w w . j a v a 2 s.c om*/ private static JavaTypeName encodeClassLiteralExpr(ClassLiteral classLiteral, GenerationContext context) { final JavaTypeName referentType = classLiteral.getReferentType(); final MethodVisitor methodVisitor = context.getMethodVisitor(); switch (referentType.getTag()) { // The primitive types (and void) are handled specially by javac - it generates code to access the static TYPE field // in the corresponding boxed type. case JavaTypeName.VOID_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.VOID_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.BOOLEAN_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.BOOLEAN_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.BYTE_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.BYTE_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.SHORT_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.SHORT_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.CHAR_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.CHARACTER_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.INT_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.INTEGER_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.LONG_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.LONG_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.DOUBLE_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.DOUBLE_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.FLOAT_TAG: methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, JavaTypeName.FLOAT_OBJECT.getJVMInternalName(), "TYPE", JavaTypeName.CLASS.getJVMDescriptor()); break; case JavaTypeName.ARRAY_TAG: case JavaTypeName.OBJECT_TAG: // For array and reference types, we generate the Class constant via Java 5's upgraded ldc opcode methodVisitor.visitLdcInsn(Type.getType(referentType.getJVMDescriptor())); break; default: throw new IllegalArgumentException("Unrecognized java type: " + referentType); } return JavaTypeName.CLASS; }
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 ww . ja v a 2 s . c om } 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; }/*w w w .j a va 2 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.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; }/* w w w . ja v a 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 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 av a 2 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); }