List of usage examples for org.objectweb.asm MethodVisitor visitLdcInsn
public void visitLdcInsn(final Object value)
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generatePropertyMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(property.writeAccessLevel + ACC_FINAL, property.propertyMethodName, "()" + property.propertyInterfaceSignature, property.propertyInterfaceSignatureGeneric != null ? "()" + property.propertyInterfaceSignatureGeneric : null,/* www .ja va 2 s.c o m*/ null); { AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";", true); av0.visit("writeable", Boolean.TRUE); av0.visit("name", property.propertyName); av0.visit("dataSignature", property.dataSignature); av0.visit("dataSignatureGeneric", property.dataSignatureGeneric != null ? property.dataSignatureGeneric : ""); av0.visit("humanReadableName", property.humanReadablePropertyName != null ? property.humanReadablePropertyName : ""); av0.visitEnd(); } mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); Label l1 = new Label(); mv.visitJumpInsn(IFNONNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, property.propertyDataType); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(property.propertyName); mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>", "(Ljava/lang/Object;Ljava/lang/String;)V"); mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitLabel(l1); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitTypeInsn(CHECKCAST, property.propertyInterfaceType); mv.visitInsn(ARETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); mv.visitMaxs(5, 1); mv.visitEnd(); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generateReadOnlyPropertyMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(property.readAccessLevel + ACC_FINAL, property.readOnlyPropertyMethodName, "()" + property.readOnlyPropertyInterfaceSignature, property.readOnlyPropertyInterfaceSignatureGeneric != null ? "()" + property.readOnlyPropertyInterfaceSignatureGeneric : null,/* ww w . j av a2s . c o m*/ null); { AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";", true); av0.visit("writeable", Boolean.FALSE); av0.visit("name", property.propertyName); av0.visit("dataSignature", property.dataSignature); av0.visit("dataSignatureGeneric", property.dataSignatureGeneric != null ? property.dataSignatureGeneric : ""); av0.visit("humanReadableName", property.humanReadablePropertyName != null ? property.humanReadablePropertyName : ""); av0.visitEnd(); } mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); Label l1 = new Label(); mv.visitJumpInsn(IFNONNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, property.propertyDataType); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(property.propertyName); mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>", "(Ljava/lang/Object;Ljava/lang/String;)V"); mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitLabel(l1); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyDataType, "getReadOnlyProperty", "()" + property.readOnlyPropertyInterfaceSignature); mv.visitTypeInsn(CHECKCAST, property.readOnlyPropertyInterfaceType); mv.visitInsn(ARETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); mv.visitMaxs(5, 1); mv.visitEnd(); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.BytecodeTasks.java
License:Open Source License
/** * Inserts a mutation. The inserted code is like this: * <code>if(System.getProperty(mutationID)){ * execute mutated code/* w w w . j a va 2 s . co m*/ * } * else{ * execute unmutated code * } * * @param mv * MethodVisitor where the code is inserted. * @param unMutated * code that should be used when no mutation is applied. * @param mutations * code that should be used when one of the mutations is applied. */ public static void insertIfElse(MethodVisitor mv, MutationCode unMutated, MutationCode[] mutations) { Label endLabel = new Label(); Label mutationStartLabel = new Label(); mutationStartLabel.info = new MutationMarker(true); mv.visitLabel(mutationStartLabel); for (MutationCode mutationCode : mutations) { Mutation mutation = mutationCode.getMutation(); mv.visitLdcInsn(mutation.getMutationVariable()); // mv.visitLdcInsn(mutation.getMutationType() + ""); // mv.visitInsn(Opcodes.POP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "getProperty", "(Ljava/lang/String;)Ljava/lang/String;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); // insertPrintStatements(mv, "Mutation touched: " + // mutation.getId()); insertMutationTouchedCode(mv, mutation); if (!DebugProperties.INSERT_ORIGINAL_INSTEAD_OF_MUTATION) { mutationCode.insertCodeBlock(mv); } else { logger.warn("Debug mode: not inserting mutated statement"); unMutated.insertCodeBlock(mv); } mv.visitJumpInsn(Opcodes.GOTO, endLabel); mv.visitLabel(l1); } Label mutationEndLabel = new Label(); mutationEndLabel.info = new MutationMarker(false); mv.visitLabel(mutationEndLabel); unMutated.insertCodeBlock(mv); mv.visitLabel(endLabel); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.BytecodeTasks.java
License:Open Source License
/** * Insert calls that signal whether the mutated code was executed. * /* ww w. j av a2 s . co m*/ * @param mv * the method visitor to add the statements * @param mutation * the mutation that is covered or not */ private static void insertMutationTouchedCode(MethodVisitor mv, Mutation mutation) { if (DebugProperties.MUTATION_PRINT_STATEMENTS_ENABLED) { BytecodeTasks.insertPrintStatements(mv, "Mutation " + mutation.getMutationVariable() + " - " + mutation.getMutationType() + " is enabled"); } mv.visitLdcInsn(mutation.getId()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "de/unisb/cs/st/javalanche/mutation/runtime/MutationObserver", "touch", "(J)V"); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.BytecodeTasks.java
License:Open Source License
/** * Inserts bytecode that prints the given message. * /*from w w w . j av a2 s.co m*/ * @param mv * The MethodVisitor for which the code is added. * @param message * The text to be printed to System.out . */ public static void insertPrintStatements(MethodVisitor mv, String message) { mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); mv.visitLdcInsn("[MUTATION] " + message); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceIntegerConstant.RicMethodAdapter.java
License:Open Source License
private void longConstant(final long longConstant) { List<Mutation> mutations = QueryManager.getMutations(className, methodName + desc, getLineNumber(), getPossibilityForLine(), MutationType.REPLACE_CONSTANT); addPossibilityForLine();//from w ww . j a v a 2 s . co m boolean insert = false; MutationCode unmutated = new MutationCode(null) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Long(longConstant)); } }; List<MutationCode> mutationCode = new ArrayList<MutationCode>(); for (final Mutation m : mutations) { if (mutationManager.shouldApplyMutation(m)) { insert = true; mutationCode.add(new MutationCode(m) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Long(m.getOperatorAddInfo())); } }); } } if (insert) { logger.debug("Applying mutations for line: " + getLineNumber()); BytecodeTasks.insertIfElse(mv, unmutated, mutationCode.toArray(new MutationCode[0])); } else { logger.debug("Applying no mutation for line: " + getLineNumber()); super.visitLdcInsn(new Long(longConstant)); } }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceIntegerConstant.RicMethodAdapter.java
License:Open Source License
private void floatConstant(final float floatConstant) { logger.debug("float constant for line: " + getLineNumber()); List<Mutation> mutations = QueryManager.getMutations(className, methodName + desc, getLineNumber(), getPossibilityForLine(), MutationType.REPLACE_CONSTANT); addPossibilityForLine();/*from w w w .j a v a 2s . c om*/ boolean insert = false; MutationCode unmutated = new MutationCode(null) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Float(floatConstant)); } }; List<MutationCode> mutationCode = new ArrayList<MutationCode>(); for (final Mutation m : mutations) { if (mutationManager.shouldApplyMutation(m)) { insert = true; mutationCode.add(new MutationCode(m) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Float(m.getOperatorAddInfo())); } }); } } if (insert) { logger.debug("Applying mutations for line: " + getLineNumber()); BytecodeTasks.insertIfElse(mv, unmutated, mutationCode.toArray(new MutationCode[0])); } else { logger.debug("Applying no mutation for line: " + getLineNumber()); super.visitLdcInsn(new Float(floatConstant)); } }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceIntegerConstant.RicMethodAdapter.java
License:Open Source License
private void doubleConstant(final double doubleConstant) { logger.debug("double constant for line: " + getLineNumber()); List<Mutation> mutations = QueryManager.getMutations(className, methodName + desc, getLineNumber(), getPossibilityForLine(), MutationType.REPLACE_CONSTANT); addPossibilityForLine();/*from w w w . j a va 2 s . c om*/ boolean insert = false; MutationCode unmutated = new MutationCode(null) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Double(doubleConstant)); } }; List<MutationCode> mutationCode = new ArrayList<MutationCode>(); for (final Mutation m : mutations) { if (mutationManager.shouldApplyMutation(m)) { insert = true; mutationCode.add(new MutationCode(m) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Double(m.getOperatorAddInfo())); } }); } } if (insert) { logger.debug("Applying mutations for line: " + getLineNumber()); BytecodeTasks.insertIfElse(mv, unmutated, mutationCode.toArray(new MutationCode[0])); } else { logger.debug("Applying no mutation for line: " + getLineNumber()); super.visitLdcInsn(new Double(doubleConstant)); } }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceIntegerConstant.RicMethodAdapter.java
License:Open Source License
private void intConstant(final int intConstant) { List<Mutation> mutations = QueryManager.getMutations(className, methodName + desc, getLineNumber(), getPossibilityForLine(), MutationType.REPLACE_CONSTANT); addPossibilityForLine();/*ww w. j ava2 s . c o m*/ boolean insert = false; MutationCode unmutated = new MutationCode(null) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(new Integer(intConstant)); } }; List<MutationCode> mutationCode = new ArrayList<MutationCode>(); for (final Mutation m : mutations) { if (mutationManager.shouldApplyMutation(m)) { insert = true; mutationCode.add(new MutationCode(m) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitLdcInsn(Integer.valueOf(m.getOperatorAddInfo())); } }); } } if (insert) { logger.debug("Applying mutations for line: " + getLineNumber()); BytecodeTasks.insertIfElse(mv, unmutated, mutationCode.toArray(new MutationCode[0])); } else { logger.debug("Applying no mutation for line: " + getLineNumber()); super.visitLdcInsn(new Integer(intConstant)); } }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.unaryOperatorInsertion.UnaryOperatorMethodAdapter.java
License:Open Source License
@Override protected void handleMutation(Mutation mutation, final Integer type) { MutationCode unMutated = new MutationCode(null) { @Override/*from ww w . ja v a 2 s . co m*/ public void insertCodeBlock(MethodVisitor mv) { } }; List<MutationCode> mutated = new ArrayList<MutationCode>(); mutation.setOperatorAddInfo(MINUS); if (mutationManager.shouldApplyMutation(mutation)) { Mutation dbMutation = QueryManager.getMutation(mutation); final int negOpcode = getOpcode(Opcodes.INEG, type); MutationCode mutateMinus = new MutationCode(dbMutation) { @Override public void insertCodeBlock(MethodVisitor mv) { mv.visitInsn(negOpcode); } }; mutated.add(mutateMinus); } mutation.setOperatorAddInfo(BITWISE_NEGATE); if (mutationManager.shouldApplyMutation(mutation)) { Mutation dbMutation = QueryManager.getMutation(mutation); MutationCode mutateNegate = new MutationCode(dbMutation) { @Override public void insertCodeBlock(MethodVisitor mv) { if (type == Opcodes.INTEGER) { mv.visitInsn(Opcodes.ICONST_M1); mv.visitInsn(Opcodes.IXOR); } else if (type == Opcodes.LONG) { mv.visitLdcInsn(Long.valueOf(-1l)); mv.visitInsn(Opcodes.LXOR); } } }; mutated.add(mutateNegate); } if (mutated.size() > 0) { BytecodeTasks.insertIfElse(mv, unMutated, mutated.toArray(new MutationCode[0])); } else { logger.debug("Not applying mutation"); } }