Software Testing & Validation - Expected Output You are given this to build from
ID: 3754796 • Letter: S
Question
Software Testing & Validation - Expected Output
You are given this to build from.
1 3 import org.objectweb.asm.Label; 4 import org.objectweb.asm.MethodVisitor; 5 import org.objectweb.asm.Opcodes; 7 8 Eclass MethodTransformVisitor extends MethodVisitor implements Opcodes f 10 String mName; int line; 12 13 public MethodTransformVisitor(final MethodVisitor mv, String name) super (ASM5, mv); this.mName-name; 15 16 17 18 19 20 21 // method coverage collection @Override public void visitCode() :mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out""Ljava/io/PrintStream;") mv.visitLdcInsn (mName+" executed") mv.visitMethodInsn (INVOKEVIRTUAL, "java/io/PrintStream", "println" (Ljava/lang/String;)V", false); super.visitCode); 23 24 25 26 27Explanation / Answer
import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; class MethodTransformVisitor extends MethodVisitor implements Opcodes { String mName, className; int line = 0; //int line, executedline; public MethodTransformVisitor(final MethodVisitor mv, String className, String name) { super(ASM5, mv); this.mName = name; this.className = className; } @Override public void visitLineNumber(int line, Label start) { this.line = line; //--------- mv.visitLdcInsn(className.replace('/', '.') + ":" + line); mv.visitMethodInsn(INVOKESTATIC, "edu/utdallas/util/Helper", "addExecutedLine", "(Ljava/lang/String;)V", false); //--------- super.visitLineNumber(line, start); } @Override public void visitLabel(Label label) { mv.visitLdcInsn(className.replace('/', '.') + ":" + this.line); mv.visitMethodInsn(INVOKESTATIC, "edu/utdallas/util/Helper", "addExecutedLine", "(Ljava/lang/String;)V", false); super.visitLabel(label); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.