/** * Changes the annotations represented by this object according to the given array of <code> * Annotation</code> objects. * * @param annotations the data structure representing the new annotations. */ public void setAnnotations(Annotation[] annotations) { ByteArrayOutputStream output = new ByteArrayOutputStream(); AnnotationsWriter writer = new AnnotationsWriter(output, constPool); try { int n = annotations.length; writer.numAnnotations(n); for (int i = 0; i < n; ++i) annotations[i].write(writer); writer.close(); } catch (IOException e) { throw new RuntimeException(e); // should never reach here. } set(output.toByteArray()); }
/** * Changes the annotations represented by this object according to the given array of <code> * Annotation</code> objects. * * @param params the data structure representing the new annotations. Every element of this array * is an array of <code>Annotation</code> and it represens annotations of each method * parameter. */ public void setAnnotations(Annotation[][] params) { ByteArrayOutputStream output = new ByteArrayOutputStream(); AnnotationsWriter writer = new AnnotationsWriter(output, constPool); try { int n = params.length; writer.numParameters(n); for (int i = 0; i < n; ++i) { Annotation[] anno = params[i]; writer.numAnnotations(anno.length); for (int j = 0; j < anno.length; ++j) anno[j].write(writer); } writer.close(); } catch (IOException e) { throw new RuntimeException(e); // should never reach here. } set(output.toByteArray()); }
int arrayMemberValue(int pos, int num) throws Exception { writer.arrayValue(num); return super.arrayMemberValue(pos, num); }
int annotationMemberValue(int pos) throws Exception { writer.annotationValue(); return super.annotationMemberValue(pos); }
void classMemberValue(int pos, int index) throws Exception { writer.classInfoIndex(copyType(index)); super.classMemberValue(pos, index); }
void enumMemberValue(int pos, int typeNameIndex, int constNameIndex) throws Exception { writer.enumConstValue(copyType(typeNameIndex), copy(constNameIndex)); super.enumMemberValue(pos, typeNameIndex, constNameIndex); }
void constValueMember(int tag, int index) throws Exception { writer.constValueIndex(tag, copy(index)); super.constValueMember(tag, index); }
int memberValuePair(int pos, int nameIndex) throws Exception { writer.memberValuePair(copy(nameIndex)); return super.memberValuePair(pos, nameIndex); }
int annotation(int pos, int type, int numPairs) throws Exception { writer.annotation(copyType(type), numPairs); return super.annotation(pos, type, numPairs); }
int annotationArray(int pos, int num) throws Exception { writer.numAnnotations(num); return super.annotationArray(pos, num); }
void parameters(int numParam, int pos) throws Exception { writer.numParameters(numParam); super.parameters(numParam, pos); }
byte[] close() throws IOException { writer.close(); return output.toByteArray(); }
/** Writes the value. */ public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); }
@Override public void write(final AnnotationsWriter writer) throws IOException { writer.annotationValue(); this.value.write(writer); }