| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package org.apache.commons.compress.harmony.unpack200.bytecode; |
| 20 |
|
| 21 |
import java.io.DataOutputStream; |
| 22 |
import java.io.IOException; |
| 23 |
import java.util.ArrayList; |
| 24 |
import java.util.List; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class RuntimeVisibleorInvisibleAnnotationsAttribute extends AnnotationsAttribute { |
| 30 |
|
| 31 |
private final Annotation[] annotations; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public RuntimeVisibleorInvisibleAnnotationsAttribute(final CPUTF8 name, final Annotation[] annotations) { |
| 40 |
super(name); |
| 41 |
this.annotations = annotations; |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
protected int getLength() { |
| 46 |
int length = 2; |
| 47 |
for (final Annotation annotation : annotations) { |
| 48 |
length += annotation.getLength(); |
| 49 |
} |
| 50 |
return length; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
protected ClassFileEntry[] getNestedClassFileEntries() { |
| 55 |
final List<Object> nested = new ArrayList<>(); |
| 56 |
nested.add(attributeName); |
| 57 |
for (final Annotation annotation : annotations) { |
| 58 |
nested.addAll(annotation.getClassFileEntries()); |
| 59 |
} |
| 60 |
return nested.toArray(NONE); |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
protected void resolve(final ClassConstantPool pool) { |
| 65 |
super.resolve(pool); |
| 66 |
for (final Annotation annotation : annotations) { |
| 67 |
annotation.resolve(pool); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
@Override |
| 72 |
public String toString() { |
| 73 |
return attributeName.underlyingString() + ": " + annotations.length + " annotations"; |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
protected void writeBody(final DataOutputStream dos) throws IOException { |
| 78 |
final int size = dos.size(); |
| 79 |
dos.writeShort(annotations.length); |
| 80 |
for (final Annotation annotation : annotations) { |
| 81 |
annotation.writeBody(dos); |
| 82 |
} |
| 83 |
if (dos.size() - size != getLength()) { |
| 84 |
throw new Error(); |
| 85 |
} |
| 86 |
} |
| 87 |
} |