|
3 | 3 | import java.util.Arrays; |
4 | 4 | import java.util.List; |
5 | 5 |
|
| 6 | +import org.objectweb.asm.AnnotationVisitor; |
6 | 7 | import org.objectweb.asm.Handle; |
7 | 8 | import org.objectweb.asm.Label; |
8 | 9 | import org.objectweb.asm.MethodVisitor; |
|
15 | 16 | /** |
16 | 17 | * Creates "mutants" that contain no changes at all possible mutation |
17 | 18 | * points. |
18 | | - * |
| 19 | + * <p> |
19 | 20 | * Intended for testing purposes only. |
20 | | - * |
21 | 21 | */ |
22 | 22 | public class NullMutateEverything implements MethodMutatorFactory { |
23 | 23 |
|
24 | | - @Override |
25 | | - public MethodVisitor create(MutationContext context, MethodInfo methodInfo, |
26 | | - MethodVisitor methodVisitor) { |
27 | | - return new MutateEveryThing(this, context, methodVisitor); |
28 | | - } |
| 24 | + public static List<MethodMutatorFactory> asList() { |
| 25 | + return Arrays.asList(new NullMutateEverything()); |
| 26 | + } |
29 | 27 |
|
30 | | - @Override |
31 | | - public String getGloballyUniqueId() { |
32 | | - return "mutateallthethings"; |
33 | | - } |
| 28 | + @Override |
| 29 | + public MethodVisitor create(MutationContext context, MethodInfo methodInfo, |
| 30 | + MethodVisitor methodVisitor) { |
| 31 | + return new MutateEveryThing(this, context, methodVisitor); |
| 32 | + } |
34 | 33 |
|
35 | | - @Override |
36 | | - public String getName() { |
37 | | - return "mutateeverything"; |
38 | | - } |
| 34 | + @Override |
| 35 | + public String getGloballyUniqueId() { |
| 36 | + return "mutateallthethings"; |
| 37 | + } |
39 | 38 |
|
40 | | - public static List<MethodMutatorFactory> asList() { |
41 | | - return Arrays.asList(new NullMutateEverything()); |
42 | | - } |
| 39 | + @Override |
| 40 | + public String getName() { |
| 41 | + return "mutateeverything"; |
| 42 | + } |
43 | 43 |
|
44 | 44 | } |
45 | 45 |
|
46 | 46 | class MutateEveryThing extends MethodVisitor { |
47 | | - private final MethodMutatorFactory factory; |
48 | | - private final MutationContext context; |
49 | | - |
50 | | - MutateEveryThing(final MethodMutatorFactory factory, |
51 | | - final MutationContext context, |
52 | | - final MethodVisitor delegateMethodVisitor) { |
53 | | - super(ASMVersion.ASM_VERSION, delegateMethodVisitor); |
54 | | - this.factory = factory; |
55 | | - this.context = context; |
56 | | - } |
57 | | - |
58 | | - @Override |
59 | | - public void visitIincInsn(final int var, final int increment) { |
60 | | - mutate("visitIincInsn"); |
61 | | - super.visitIincInsn(var, increment); |
62 | | - } |
63 | | - |
64 | | - @Override |
65 | | - public void visitInsn(int opcode) { |
66 | | - if (opcode != Opcodes.RETURN) { |
67 | | - mutate("visitInsn", opcode); |
68 | | - } |
69 | | - super.visitInsn(opcode); |
70 | | - } |
71 | | - |
72 | | - @Override |
73 | | - public void visitIntInsn(int opcode, int operand) { |
74 | | - mutate("visitIntInsn", opcode); |
75 | | - super.visitIntInsn(opcode,operand); |
76 | | - } |
77 | | - |
78 | | - @Override |
79 | | - public void visitVarInsn(int opcode, int var) { |
80 | | - mutate("visitVarInsn", opcode); |
81 | | - super.visitVarInsn(opcode,var); |
82 | | - } |
83 | | - |
84 | | - @Override |
85 | | - public void visitTypeInsn(int opcode, String type) { |
86 | | - mutate("visitTypeInsn", opcode); |
87 | | - super.visitTypeInsn(opcode, type); |
88 | | - } |
89 | | - |
90 | | - @Override |
91 | | - public void visitFieldInsn(int opcode, String owner, String name, |
92 | | - String desc) { |
93 | | - mutate("visitFieldInsn", opcode); |
94 | | - super.visitFieldInsn(opcode, owner, name, desc); |
95 | | - } |
96 | | - |
97 | | - @Override |
98 | | - public void visitMethodInsn(int opcode, String owner, String name, |
99 | | - String desc, boolean itf) { |
100 | | - mutate("visitMethodInsn", opcode); |
101 | | - super.visitMethodInsn(opcode, owner, name, desc, itf); |
102 | | - } |
103 | | - |
104 | | - @Override |
105 | | - public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, |
106 | | - Object... bsmArgs) { |
107 | | - mutate("visitInvokeDynamicInsn"); |
108 | | - super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); |
109 | | - } |
110 | | - |
111 | | - @Override |
112 | | - public void visitJumpInsn(int opcode, Label label) { |
113 | | - mutate("visitJumpInsn", opcode); |
114 | | - super.visitJumpInsn(opcode, label); |
115 | | - } |
116 | | - |
117 | | - @Override |
118 | | - public void visitLdcInsn(Object cst) { |
119 | | - mutate("visitLdcInsn"); |
120 | | - super.visitLdcInsn(cst); |
121 | | - } |
122 | | - |
123 | | - @Override |
124 | | - public void visitTableSwitchInsn(int min, int max, Label dflt, |
125 | | - Label... labels) { |
126 | | - mutate("visitTableSwitchInsn"); |
127 | | - super.visitTableSwitchInsn(min, max, dflt, labels); |
128 | | - } |
129 | | - |
130 | | - @Override |
131 | | - public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { |
132 | | - mutate("visitLookupSwitchInsn"); |
133 | | - super.visitLookupSwitchInsn(dflt, keys, labels); |
134 | | - } |
135 | | - |
136 | | - @Override |
137 | | - public void visitMultiANewArrayInsn(String desc, int dims) { |
138 | | - mutate("visitMultiANewArrayInsn"); |
139 | | - super.visitMultiANewArrayInsn(desc, dims); |
140 | | - } |
141 | | - |
142 | | - @Override |
143 | | - public void visitTryCatchBlock(Label start, Label end, Label handler, |
144 | | - String type) { |
145 | | - // Can't mutate try catch blocks as they are not modelled as an instruction in ASM |
146 | | - super.visitTryCatchBlock(start, end, handler, type); |
147 | | - } |
148 | | - |
149 | | - private void mutate(String string, int opcode) { |
150 | | - mutate("Null mutation in " + string + " with " + opcode); |
151 | | - } |
152 | | - |
153 | | - private void mutate(String string) { |
154 | | - this.context.registerMutation(this.factory, string); |
155 | | - } |
| 47 | + private final MethodMutatorFactory factory; |
| 48 | + private final MutationContext context; |
| 49 | + |
| 50 | + MutateEveryThing(final MethodMutatorFactory factory, |
| 51 | + final MutationContext context, |
| 52 | + final MethodVisitor delegateMethodVisitor) { |
| 53 | + super(ASMVersion.ASM_VERSION, delegateMethodVisitor); |
| 54 | + this.factory = factory; |
| 55 | + this.context = context; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void visitIincInsn(final int var, final int increment) { |
| 60 | + mutate("visitIincInsn"); |
| 61 | + super.visitIincInsn(var, increment); |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public void visitInsn(int opcode) { |
| 66 | + if (opcode != Opcodes.RETURN) { |
| 67 | + mutate("visitInsn", opcode); |
| 68 | + } |
| 69 | + super.visitInsn(opcode); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public void visitIntInsn(int opcode, int operand) { |
| 74 | + mutate("visitIntInsn", opcode); |
| 75 | + super.visitIntInsn(opcode, operand); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public void visitVarInsn(int opcode, int var) { |
| 80 | + mutate("visitVarInsn", opcode); |
| 81 | + super.visitVarInsn(opcode, var); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public void visitTypeInsn(int opcode, String type) { |
| 86 | + mutate("visitTypeInsn", opcode); |
| 87 | + super.visitTypeInsn(opcode, type); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public void visitFieldInsn(int opcode, String owner, String name, |
| 92 | + String desc) { |
| 93 | + mutate("visitFieldInsn", opcode); |
| 94 | + super.visitFieldInsn(opcode, owner, name, desc); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public void visitMethodInsn(int opcode, String owner, String name, |
| 99 | + String desc, boolean itf) { |
| 100 | + mutate("visitMethodInsn", opcode); |
| 101 | + super.visitMethodInsn(opcode, owner, name, desc, itf); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, |
| 106 | + Object... bsmArgs) { |
| 107 | + mutate("visitInvokeDynamicInsn"); |
| 108 | + super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void visitJumpInsn(int opcode, Label label) { |
| 113 | + mutate("visitJumpInsn", opcode); |
| 114 | + super.visitJumpInsn(opcode, label); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public void visitLdcInsn(Object cst) { |
| 119 | + mutate("visitLdcInsn"); |
| 120 | + super.visitLdcInsn(cst); |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + public void visitTableSwitchInsn(int min, int max, Label dflt, |
| 125 | + Label... labels) { |
| 126 | + mutate("visitTableSwitchInsn"); |
| 127 | + super.visitTableSwitchInsn(min, max, dflt, labels); |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { |
| 132 | + mutate("visitLookupSwitchInsn"); |
| 133 | + super.visitLookupSwitchInsn(dflt, keys, labels); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public void visitMultiANewArrayInsn(String desc, int dims) { |
| 138 | + mutate("visitMultiANewArrayInsn"); |
| 139 | + super.visitMultiANewArrayInsn(desc, dims); |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public void visitTryCatchBlock(Label start, Label end, Label handler, |
| 144 | + String type) { |
| 145 | + // Can't mutate try catch blocks as they are not modelled as an instruction in ASM |
| 146 | + super.visitTryCatchBlock(start, end, handler, type); |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { |
| 151 | + mutate("visitAnnotation_" + descriptor); |
| 152 | + return super.visitAnnotation(descriptor, visible); |
| 153 | + } |
| 154 | + |
| 155 | + |
| 156 | + private void mutate(String string, int opcode) { |
| 157 | + mutate("Null mutation in " + string + " with " + opcode); |
| 158 | + } |
| 159 | + |
| 160 | + private void mutate(String string) { |
| 161 | + this.context.registerMutation(this.factory, string); |
| 162 | + } |
156 | 163 |
|
157 | 164 | } |
0 commit comments