1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.classfile;
18
19 import java.io.DataInput;
20 import java.io.DataOutputStream;
21 import java.io.IOException;
22 import java.util.Iterator;
23 import java.util.stream.Stream;
24
25
26
27
28
29
30 public abstract class ParameterAnnotations extends Attribute implements Iterable<ParameterAnnotationEntry> {
31
32 private static final ParameterAnnotationEntry[] EMPTY_ARRAY = {};
33
34
35 private ParameterAnnotationEntry[] parameterAnnotationTable;
36
37
38
39
40
41
42
43
44
45
46 ParameterAnnotations(final byte parameterAnnotationType, final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool)
47 throws IOException {
48 this(parameterAnnotationType, nameIndex, length, (ParameterAnnotationEntry[]) null, constantPool);
49 final int numParameters = input.readUnsignedByte();
50 parameterAnnotationTable = new ParameterAnnotationEntry[numParameters];
51 for (int i = 0; i < numParameters; i++) {
52 parameterAnnotationTable[i] = new ParameterAnnotationEntry(input, constantPool);
53 }
54 }
55
56
57
58
59
60
61
62
63
64
65 public ParameterAnnotations(final byte parameterAnnotationType, final int nameIndex, final int length,
66 final ParameterAnnotationEntry[] parameterAnnotationTable, final ConstantPool constantPool) {
67 super(parameterAnnotationType, nameIndex, length, constantPool);
68 this.parameterAnnotationTable = parameterAnnotationTable;
69 }
70
71
72
73
74
75
76
77 @Override
78 public void accept(final Visitor v) {
79 v.visitParameterAnnotation(this);
80 }
81
82
83
84
85 @Override
86 public Attribute copy(final ConstantPool constantPool) {
87 return (Attribute) clone();
88 }
89
90 @Override
91 public void dump(final DataOutputStream dos) throws IOException {
92 super.dump(dos);
93 dos.writeByte(parameterAnnotationTable.length);
94
95 for (final ParameterAnnotationEntry element : parameterAnnotationTable) {
96 element.dump(dos);
97 }
98
99 }
100
101
102
103
104 public ParameterAnnotationEntry[] getParameterAnnotationEntries() {
105 return parameterAnnotationTable;
106 }
107
108
109
110
111 public final ParameterAnnotationEntry[] getParameterAnnotationTable() {
112 return parameterAnnotationTable;
113 }
114
115 @Override
116 public Iterator<ParameterAnnotationEntry> iterator() {
117 return Stream.of(parameterAnnotationTable).iterator();
118 }
119
120
121
122
123 public final void setParameterAnnotationTable(final ParameterAnnotationEntry[] parameterAnnotationTable) {
124 this.parameterAnnotationTable = parameterAnnotationTable != null ? parameterAnnotationTable : EMPTY_ARRAY;
125 }
126 }