1
2
3
4
5
6 package mockit.asm.methods;
7
8 import edu.umd.cs.findbugs.annotations.NonNull;
9
10 import mockit.asm.constantPool.AttributeWriter;
11 import mockit.asm.constantPool.ConstantPoolGeneration;
12 import mockit.asm.util.ByteVector;
13
14 import org.checkerframework.checker.index.qual.NonNegative;
15
16
17
18
19
20
21 final class ExceptionsWriter extends AttributeWriter {
22 @NonNull
23 private final int[] exceptionIndices;
24
25 ExceptionsWriter(@NonNull ConstantPoolGeneration cp, @NonNull String[] exceptionTypeDescs) {
26 super(cp, "Exceptions");
27 int n = exceptionTypeDescs.length;
28 exceptionIndices = new int[n];
29
30 for (int i = 0; i < n; i++) {
31 exceptionIndices[i] = cp.newClass(exceptionTypeDescs[i]);
32 }
33 }
34
35 @NonNegative
36 @Override
37 public int getSize() {
38 return 8 + 2 * exceptionIndices.length;
39 }
40
41 @Override
42 public void put(@NonNull ByteVector out) {
43 int n = exceptionIndices.length;
44 put(out, 2 + 2 * n);
45 out.putShort(n);
46
47 for (int exceptionIndex : exceptionIndices) {
48 out.putShort(exceptionIndex);
49 }
50 }
51 }