01: /* ===========================================================================
02: * $RCSfile: AnnotationsAttrInfo.java,v $
03: * ===========================================================================
04: *
05: * RetroGuard -- an obfuscation package for Java classfiles.
06: *
07: * Copyright (c) 1998-2006 Mark Welsh (markw@retrologic.com)
08: *
09: * This program can be redistributed and/or modified under the terms of the
10: * Version 2 of the GNU General Public License as published by the Free
11: * Software Foundation.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: */
19:
20: package COM.rl.obf.classfile;
21:
22: import java.io.*;
23: import java.util.*;
24:
25: /**
26: * Representation of an attribute.
27: *
28: * @author Mark Welsh
29: */
30: abstract public class AnnotationsAttrInfo extends AttrInfo {
31: // Constants -------------------------------------------------------------
32:
33: // Fields ----------------------------------------------------------------
34: private int u2numAnnotations;
35: private AnnotationInfo[] annotationTable;
36:
37: // Class Methods ---------------------------------------------------------
38:
39: // Instance Methods ------------------------------------------------------
40: protected AnnotationsAttrInfo(ClassFile cf, int attrNameIndex,
41: int attrLength) {
42: super (cf, attrNameIndex, attrLength);
43: }
44:
45: /** Return the array of annotation table entries. */
46: protected AnnotationInfo[] getAnnotationTable() throws Exception {
47: return annotationTable;
48: }
49:
50: /** Check for Utf8 references in the 'info' data to the constant pool and mark them. */
51: protected void markUtf8RefsInInfo(ConstantPool pool)
52: throws Exception {
53: for (int i = 0; i < annotationTable.length; i++) {
54: annotationTable[i].markUtf8Refs(pool);
55: }
56: }
57:
58: /** Read the data following the header. */
59: protected void readInfo(DataInput din) throws Exception {
60: u2numAnnotations = din.readUnsignedShort();
61: annotationTable = new AnnotationInfo[u2numAnnotations];
62: for (int i = 0; i < u2numAnnotations; i++) {
63: annotationTable[i] = AnnotationInfo.create(din);
64: }
65: }
66:
67: /** Export data following the header to a DataOutput stream. */
68: public void writeInfo(DataOutput dout) throws Exception {
69: dout.writeShort(u2numAnnotations);
70: for (int i = 0; i < u2numAnnotations; i++) {
71: annotationTable[i].write(dout);
72: }
73: }
74:
75: /** Do necessary name remapping. */
76: protected void remap(ClassFile cf, NameMapper nm) throws Exception {
77: for (int i = 0; i < u2numAnnotations; i++) {
78: annotationTable[i].remap(cf, nm);
79: }
80: }
81:
82: /** Provide debugging dump of this object. */
83: public void dump(PrintStream ps) throws Exception {
84: super .dump(ps);
85: ps.println("u2numAnnotations : " + u2numAnnotations);
86: for (int i = 0; i < u2numAnnotations; i++) {
87: annotationTable[i].dump(ps, cf);
88: }
89: }
90: }
|