1 7 package org.gjt.jclasslib.structures.attributes; 8 9 import org.gjt.jclasslib.structures.AttributeInfo; 10 import org.gjt.jclasslib.structures.InvalidByteCodeException; 11 import org.gjt.jclasslib.structures.elementvalues.AnnotationElementValue; 12 13 import java.io.*; 14 15 21 public class RuntimeAnnotationsAttribute extends AttributeInfo { 22 private static final int INITIAL_LENGTH = 2; 23 24 protected AnnotationElementValue[] runtimeAnnotations; 25 26 27 33 public AnnotationElementValue[] getRuntimeAnnotations() { 34 return runtimeAnnotations; 35 } 36 37 43 public void setRuntimeAnnotations(AnnotationElementValue[] runtimeAnnotations) { 44 this.runtimeAnnotations = runtimeAnnotations; 45 } 46 47 public void read(DataInput in) 48 throws InvalidByteCodeException, IOException { 49 50 super.read(in); 51 52 int runtimeVisibleAnnotationsLength = in.readUnsignedShort(); 53 runtimeAnnotations = new AnnotationElementValue[runtimeVisibleAnnotationsLength]; 54 for (int i = 0; i < runtimeVisibleAnnotationsLength; i++) { 55 runtimeAnnotations[i] = new AnnotationElementValue(); 56 runtimeAnnotations[i].setClassFile(classFile); 57 runtimeAnnotations[i].read(in); 58 } 59 60 if (debug) debug("read "); 61 } 62 63 public void write(DataOutput out) 64 throws InvalidByteCodeException, IOException { 65 66 super.write(out); 67 68 int runtimeVisibleAnnotationsLength = getLength(runtimeAnnotations); 69 70 out.writeShort(runtimeVisibleAnnotationsLength); 71 for (int i = 0; i < runtimeVisibleAnnotationsLength; i++) { 72 runtimeAnnotations[i].write(out); 73 } 74 75 if (debug) debug("wrote "); 76 } 77 78 public int getAttributeLength() { 79 int length = INITIAL_LENGTH; 80 for (int i = 0; i < runtimeAnnotations.length; i++) { 81 length += runtimeAnnotations[i].getLength(); 82 } 83 return length; 84 } 85 } 86 | Popular Tags |