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 RuntimeVisibleorInvisibleAnnotationsAttribute extends AnnotationsAttribute {
28
29 private final int numAnnotations;
30 private final Annotation[] annotations;
31
32 public RuntimeVisibleorInvisibleAnnotationsAttribute(final CPUTF8 name, final Annotation[] annotations) {
33 super(name);
34 this.numAnnotations = annotations.length;
35 this.annotations = annotations;
36 }
37
38 @Override
39 protected int getLength() {
40 int length = 2;
41 for (int i = 0; i < numAnnotations; i++) {
42 length += annotations[i].getLength();
43 }
44 return length;
45 }
46
47 @Override
48 protected ClassFileEntry[] getNestedClassFileEntries() {
49 final List<Object> nested = new ArrayList<>();
50 nested.add(attributeName);
51 for (final Annotation annotation : annotations) {
52 nested.addAll(annotation.getClassFileEntries());
53 }
54 return nested.toArray(NONE);
55 }
56
57 @Override
58 protected void resolve(final ClassConstantPool pool) {
59 super.resolve(pool);
60 for (final Annotation annotation : annotations) {
61 annotation.resolve(pool);
62 }
63 }
64
65 @Override
66 public String toString() {
67 return attributeName.underlyingString() + ": " + numAnnotations + " annotations";
68 }
69
70 @Override
71 protected void writeBody(final DataOutputStream dos) throws IOException {
72 final int size = dos.size();
73 dos.writeShort(numAnnotations);
74 for (int i = 0; i < numAnnotations; i++) {
75 annotations[i].writeBody(dos);
76 }
77 if (dos.size() - size != getLength()) {
78 throw new Error();
79 }
80 }
81 }