01: /*
02: * AnnotationInfo.java
03: *
04: * Created on April 20, 2005, 4:18 PM
05: */
06:
07: package com.yworks.yguard.obf.classfile;
08:
09: import java.io.DataInput;
10: import java.io.DataOutput;
11:
12: public class AnnotationInfo {
13: // Constants -------------------------------------------------------------
14:
15: // Fields ----------------------------------------------------------------
16: protected int u2typeIndex;
17: private int u2elementCount;
18: private ElementValuePairInfo[] elementValuePairs;
19:
20: // Class Methods ---------------------------------------------------------
21: public static AnnotationInfo create(DataInput din)
22: throws java.io.IOException {
23: if (din == null)
24: throw new NullPointerException("DataInput cannot be null!");
25: AnnotationInfo an = new AnnotationInfo();
26: an.read(din);
27: return an;
28: }
29:
30: protected ElementValuePairInfo[] getElementValuePairs() {
31: return elementValuePairs;
32: }
33:
34: // Instance Methods ------------------------------------------------------
35: private AnnotationInfo() {
36: }
37:
38: protected void markUtf8RefsInInfo(ConstantPool pool) {
39: pool.getCpEntry(u2typeIndex).incRefCount();
40: for (int i = 0; i < u2elementCount; i++) {
41: elementValuePairs[i].markUtf8RefsInInfo(pool);
42: }
43: }
44:
45: private void read(DataInput din) throws java.io.IOException {
46: u2typeIndex = din.readUnsignedShort();
47: u2elementCount = din.readUnsignedShort();
48: elementValuePairs = new ElementValuePairInfo[u2elementCount];
49: for (int i = 0; i < u2elementCount; i++) {
50: elementValuePairs[i] = ElementValuePairInfo.create(din);
51: }
52: }
53:
54: /** Export the representation to a DataOutput stream. */
55: public void write(DataOutput dout) throws java.io.IOException {
56: dout.writeShort(u2typeIndex);
57: dout.writeShort(u2elementCount);
58: for (int i = 0; i < u2elementCount; i++) {
59: elementValuePairs[i].write(dout);
60: }
61: }
62: }
|