-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAOD1Mutator.java
More file actions
103 lines (92 loc) · 3.21 KB
/
Copy pathAOD1Mutator.java
File metadata and controls
103 lines (92 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package org.pitest.rv;
import org.pitest.reloc.asm.MethodVisitor;
import org.pitest.reloc.asm.Opcodes;
import org.pitest.bytecode.ASMVersion;
import org.pitest.mutationtest.engine.MutationIdentifier;
import org.pitest.mutationtest.engine.gregor.MethodInfo;
import org.pitest.mutationtest.engine.gregor.MethodMutatorFactory;
import org.pitest.mutationtest.engine.gregor.MutationContext;
/**
* Mutator that replaces (a+b) by a;
* Does the same for the operators (*,/,%,-).
*/
public enum AOD1Mutator implements MethodMutatorFactory {
AOD1;
public MethodVisitor create(final MutationContext context,
final MethodInfo methodInfo, final MethodVisitor methodVisitor) {
return new AODMethodVisitor1(this, context, methodVisitor);
}
public String getGloballyUniqueId() {
return this.getClass().getName();
}
public String getName() {
return name();
}
}
class AODMethodVisitor1 extends MethodVisitor {
private final MethodMutatorFactory factory;
private final MutationContext context;
AODMethodVisitor1(final MethodMutatorFactory factory,
final MutationContext context, final MethodVisitor delegateMethodVisitor) {
super(ASMVersion.ASM_VERSION, delegateMethodVisitor);
this.factory = factory;
this.context = context;
}
private boolean shouldMutate(String expression) {
final MutationIdentifier newId = this.context.registerMutation(
this.factory, "Replaced " + expression + " operation with first member");
return this.context.shouldMutate(newId);
}
@Override
public void visitInsn(int opcode) {
switch (opcode) {
case Opcodes.IADD:
case Opcodes.ISUB:
case Opcodes.IMUL:
case Opcodes.IDIV:
case Opcodes.IREM:
if (this.shouldMutate("integer")) {
mv.visitInsn(Opcodes.POP);
} else {
mv.visitInsn(opcode);
}
break;
case Opcodes.FADD:
case Opcodes.FSUB:
case Opcodes.FMUL:
case Opcodes.FDIV:
case Opcodes.FREM:
if (this.shouldMutate("float")) {
mv.visitInsn(Opcodes.POP);
} else {
mv.visitInsn(opcode);
}
break;
case Opcodes.LADD:
case Opcodes.LSUB:
case Opcodes.LMUL:
case Opcodes.LDIV:
case Opcodes.LREM:
if (this.shouldMutate("long")) {
mv.visitInsn(Opcodes.POP2);
} else {
mv.visitInsn(opcode);
}
break;
case Opcodes.DADD:
case Opcodes.DSUB:
case Opcodes.DMUL:
case Opcodes.DDIV:
case Opcodes.DREM:
if (this.shouldMutate("double")) {
mv.visitInsn(Opcodes.POP2);
} else {
mv.visitInsn(opcode);
}
break;
default:
mv.visitInsn(opcode);
break;
}
}
}