| 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 RuntimeVisibleorInvisibleParameterAnnotationsAttribute extends AnnotationsAttribute { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public static class ParameterAnnotation { |
| 35 |
|
| 36 |
private final Annotation[] annotations; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public ParameterAnnotation(final Annotation[] annotations) { |
| 44 |
this.annotations = annotations; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public List<Object> getClassFileEntries() { |
| 53 |
final List<Object> nested = new ArrayList<>(); |
| 54 |
for (final Annotation annotation : annotations) { |
| 55 |
nested.addAll(annotation.getClassFileEntries()); |
| 56 |
} |
| 57 |
return nested; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public int getLength() { |
| 66 |
int length = 2; |
| 67 |
for (final Annotation annotation : annotations) { |
| 68 |
length += annotation.getLength(); |
| 69 |
} |
| 70 |
return length; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public void resolve(final ClassConstantPool pool) { |
| 79 |
for (final Annotation annotation : annotations) { |
| 80 |
annotation.resolve(pool); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public void writeBody(final DataOutputStream dos) throws IOException { |
| 91 |
dos.writeShort(annotations.length); |
| 92 |
for (final Annotation annotation : annotations) { |
| 93 |
annotation.writeBody(dos); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
private final ParameterAnnotation[] parameterAnnotations; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public RuntimeVisibleorInvisibleParameterAnnotationsAttribute(final CPUTF8 name, final ParameterAnnotation[] parameterAnnotations) { |
| 108 |
super(name); |
| 109 |
this.parameterAnnotations = parameterAnnotations; |
| 110 |
} |
| 111 |
|
| 112 |
@Override |
| 113 |
protected int getLength() { |
| 114 |
int length = 1; |
| 115 |
for (final ParameterAnnotation parameterAnnotation : parameterAnnotations) { |
| 116 |
length += parameterAnnotation.getLength(); |
| 117 |
} |
| 118 |
return length; |
| 119 |
} |
| 120 |
|
| 121 |
@Override |
| 122 |
protected ClassFileEntry[] getNestedClassFileEntries() { |
| 123 |
final List<Object> nested = new ArrayList<>(); |
| 124 |
nested.add(attributeName); |
| 125 |
for (final ParameterAnnotation parameterAnnotation : parameterAnnotations) { |
| 126 |
nested.addAll(parameterAnnotation.getClassFileEntries()); |
| 127 |
} |
| 128 |
return nested.toArray(NONE); |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
protected void resolve(final ClassConstantPool pool) { |
| 133 |
super.resolve(pool); |
| 134 |
for (final ParameterAnnotation parameterAnnotation : parameterAnnotations) { |
| 135 |
parameterAnnotation.resolve(pool); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
@Override |
| 140 |
public String toString() { |
| 141 |
return attributeName.underlyingString() + ": " + parameterAnnotations.length + " parameter annotations"; |
| 142 |
} |
| 143 |
|
| 144 |
@Override |
| 145 |
protected void writeBody(final DataOutputStream dos) throws IOException { |
| 146 |
dos.writeByte(parameterAnnotations.length); |
| 147 |
for (final ParameterAnnotation parameterAnnotation : parameterAnnotations) { |
| 148 |
parameterAnnotation.writeBody(dos); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
} |