1 7 package org.gjt.jclasslib.structures.elementvalues; 8 9 import org.gjt.jclasslib.structures.InvalidByteCodeException; 10 11 import java.io.*; 12 13 19 public class AnnotationElementValue extends ElementValue { 20 21 public final static String ENTRY_NAME = "Annotation"; 22 23 private static final int INITIAL_LENGTH = 4; 24 25 private int typeIndex; 26 private ElementValuePair[] elementValuePairEntries; 27 28 29 public AnnotationElementValue() { 30 super(ANNOTATION_TAG); 31 } 32 33 public String getEntryName() { 34 return ENTRY_NAME; 35 } 36 37 43 public ElementValuePair[] getElementValuePairEntries() { 44 return elementValuePairEntries; 45 } 46 47 53 public void setElementValuePairEntries(ElementValuePair[] elementValuePairEntries) { 54 this.elementValuePairEntries = elementValuePairEntries; 55 } 56 57 62 public int getTypeIndex() { 63 return typeIndex; 64 } 65 66 71 public void setTypeIndex(int typeIndex) { 72 this.typeIndex = typeIndex; 73 } 74 75 public void read(DataInput in) throws InvalidByteCodeException, IOException { 76 super.read(in); 77 78 typeIndex = in.readUnsignedShort(); 79 int elementValuePairEntriesLength = in.readUnsignedShort(); 80 81 elementValuePairEntries = new ElementValuePair[elementValuePairEntriesLength]; 82 83 for (int i = 0; i < elementValuePairEntriesLength; i++) { 84 elementValuePairEntries[i] = ElementValuePair.create(in, classFile); 85 } 86 87 if (debug) debug("read "); 88 } 89 90 public void write(DataOutput out) throws InvalidByteCodeException, IOException { 91 super.write(out); 92 93 out.writeShort(typeIndex); 94 int elementValuePairEntriesLength = getLength(elementValuePairEntries); 95 96 out.writeShort(elementValuePairEntriesLength); 97 for (int i = 0; i < elementValuePairEntriesLength; i++) { 98 elementValuePairEntries[i].write(out); 99 } 100 101 if (debug) debug("wrote "); 102 } 103 104 protected int getSpecificLength() { 105 int length = INITIAL_LENGTH; 106 for (int i = 0; i < elementValuePairEntries.length; i++) { 107 length += elementValuePairEntries[i].getLength(); 108 } 109 return length; 110 } 111 112 protected void debug(String message) { 113 super.debug(message + "Annotation with " + 114 getLength(elementValuePairEntries) + " value pair elements"); 115 } 116 } 117 | Popular Tags |