1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.compress.harmony.unpack200.bytecode;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27 public class RuntimeVisibleorInvisibleParameterAnnotationsAttribute extends AnnotationsAttribute {
28
29
30
31
32 public static class ParameterAnnotation {
33
34 private final Annotation[] annotations;
35 private final int numAnnotations;
36
37 public ParameterAnnotation(final Annotation[] annotations) {
38 this.numAnnotations = annotations.length;
39 this.annotations = annotations;
40 }
41
42 public List<Object> getClassFileEntries() {
43 final List<Object> nested = new ArrayList<>();
44 for (final Annotation annotation : annotations) {
45 nested.addAll(annotation.getClassFileEntries());
46 }
47 return nested;
48 }
49
50 public int getLength() {
51 int length = 2;
52 for (final Annotation annotation : annotations) {
53 length += annotation.getLength();
54 }
55 return length;
56 }
57
58 public void resolve(final ClassConstantPool pool) {
59 for (final Annotation annotation : annotations) {
60 annotation.resolve(pool);
61 }
62 }
63
64 public void writeBody(final DataOutputStream dos) throws IOException {
65 dos.writeShort(numAnnotations);
66 for (final Annotation annotation : annotations) {
67 annotation.writeBody(dos);
68 }
69 }
70
71 }
72
73 private final int numParameters;
74
75 private final ParameterAnnotation[] parameterAnnotations;
76
77 public RuntimeVisibleorInvisibleParameterAnnotationsAttribute(final CPUTF8 name, final ParameterAnnotation[] parameterAnnotations) {
78 super(name);
79 this.numParameters = parameterAnnotations.length;
80 this.parameterAnnotations = parameterAnnotations;
81 }
82
83 @Override
84 protected int getLength() {
85 int length = 1;
86 for (int i = 0; i < numParameters; i++) {
87 length += parameterAnnotations[i].getLength();
88 }
89 return length;
90 }
91
92 @Override
93 protected ClassFileEntry[] getNestedClassFileEntries() {
94 final List<Object> nested = new ArrayList<>();
95 nested.add(attributeName);
96 for (final ParameterAnnotation parameterAnnotation : parameterAnnotations) {
97 nested.addAll(parameterAnnotation.getClassFileEntries());
98 }
99 return nested.toArray(NONE);
100 }
101
102 @Override
103 protected void resolve(final ClassConstantPool pool) {
104 super.resolve(pool);
105 for (final ParameterAnnotation parameterAnnotation : parameterAnnotations) {
106 parameterAnnotation.resolve(pool);
107 }
108 }
109
110 @Override
111 public String toString() {
112 return attributeName.underlyingString() + ": " + numParameters + " parameter annotations";
113 }
114
115 @Override
116 protected void writeBody(final DataOutputStream dos) throws IOException {
117 dos.writeByte(numParameters);
118 for (int i = 0; i < numParameters; i++) {
119 parameterAnnotations[i].writeBody(dos);
120 }
121 }
122
123 }