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.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26
27
28
29
30
31 public class ParameterAnnotationEntry implements Node {
32
33 static final ParameterAnnotationEntry[] EMPTY_ARRAY = {};
34
35 public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final Attribute[] attributes) {
36 if (attributes == null) {
37 return EMPTY_ARRAY;
38 }
39
40 final List<ParameterAnnotationEntry> accumulatedAnnotations = new ArrayList<>(attributes.length);
41 for (final Attribute attribute : attributes) {
42 if (attribute instanceof ParameterAnnotations) {
43 final ParameterAnnotations runtimeAnnotations = (ParameterAnnotations) attribute;
44 final ParameterAnnotationEntry[] parameterAnnotationEntries = runtimeAnnotations.getParameterAnnotationEntries();
45 if (parameterAnnotationEntries != null) {
46 Collections.addAll(accumulatedAnnotations, parameterAnnotationEntries);
47 }
48 }
49 }
50 return accumulatedAnnotations.toArray(EMPTY_ARRAY);
51 }
52
53 private final AnnotationEntry[] annotationTable;
54
55
56
57
58
59
60
61 ParameterAnnotationEntry(final DataInput input, final ConstantPool constantPool) throws IOException {
62 final int annotationTableLength = input.readUnsignedShort();
63 annotationTable = new AnnotationEntry[annotationTableLength];
64 for (int i = 0; i < annotationTableLength; i++) {
65
66 annotationTable[i] = AnnotationEntry.read(input, constantPool, false);
67 }
68 }
69
70
71
72
73
74
75
76 @Override
77 public void accept(final Visitor v) {
78 v.visitParameterAnnotationEntry(this);
79 }
80
81 public void dump(final DataOutputStream dos) throws IOException {
82 dos.writeShort(annotationTable.length);
83 for (final AnnotationEntry entry : annotationTable) {
84 entry.dump(dos);
85 }
86 }
87
88
89
90
91 public AnnotationEntry[] getAnnotationEntries() {
92 return annotationTable;
93 }
94 }