KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > InnerClassesEntry


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.attributes;
9
10 import org.gjt.jclasslib.structures.*;
11
12 import java.io.*;
13
14 /**
15  * Describes an entry in a <tt>InnerClasses</tt> attribute structure.
16  *
17  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>, <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
18  * @version $Revision: 1.4 $ $Date: 2004/12/28 13:04:32 $
19  */

20 public class InnerClassesEntry extends AbstractStructure
21         implements AccessFlags {
22
23     /**
24      * Length in bytes of an inner class entry.
25      */

26     public static final int LENGTH = 8;
27
28     private int innerClassInfoIndex;
29     private int outerClassInfoIndex;
30     private int innerNameIndex;
31     private int innerClassAccessFlags;
32
33     /**
34      * Factory method for creating <tt>InnerClassesEntry</tt> structures.
35      *
36      * @param in the <tt>DataInput</tt> from which to read the
37      * <tt>InnerClassesEntry</tt> structure
38      * @param classFile the parent class file of the structure to be created
39      * @return the new <tt>InnerClassesEntry</tt> structure
40      * @throws InvalidByteCodeException if the byte code is invalid
41      * @throws IOException if an exception occurs with the <tt>DataInput</tt>
42      */

43     public static InnerClassesEntry create(DataInput in, ClassFile classFile)
44             throws InvalidByteCodeException, IOException {
45
46         InnerClassesEntry innerClassesEntry = new InnerClassesEntry();
47         innerClassesEntry.setClassFile(classFile);
48         innerClassesEntry.read(in);
49
50         return innerClassesEntry;
51     }
52
53     /**
54      * Get the constant pool index of the <tt>CONSTANT_Class_info</tt> structure
55      * describing the inner class of this <tt>InnerClassEntry</tt>.
56      *
57      * @return the index
58      */

59     public int getInnerClassInfoIndex() {
60         return innerClassInfoIndex;
61     }
62
63     /**
64      * Set the constant pool index of the <tt>CONSTANT_Class_info</tt> structure
65      * describing the inner class of this <tt>InnerClassEntry</tt>.
66      *
67      * @param innerClassInfoIndex the index
68      */

69     public void setInnerClassInfoIndex(int innerClassInfoIndex) {
70         this.innerClassInfoIndex = innerClassInfoIndex;
71     }
72
73     /**
74      * Get the constant pool index of the <tt>CONSTANT_Class_info</tt> structure
75      * describing the outer class of this <tt>InnerClassEntry</tt>.
76      *
77      * @return the index
78      */

79     public int getOuterClassInfoIndex() {
80         return outerClassInfoIndex;
81     }
82
83     /**
84      * Set the constant pool index of the <tt>CONSTANT_Class_info</tt> structure
85      * describing the outer class of this <tt>InnerClassEntry</tt>.
86      *
87      * @param outerClassInfoIndex the index
88      */

89     public void setOuterClassInfoIndex(int outerClassInfoIndex) {
90         this.outerClassInfoIndex = outerClassInfoIndex;
91     }
92
93     /**
94      * Get the constant pool index containing the simple name of the
95      * inner class of this <tt>InnerClassEntry</tt>.
96      *
97      * @return the index
98      */

99     public int getInnerNameIndex() {
100         return innerNameIndex;
101     }
102
103     /**
104      * Set the constant pool index containing the simple name of the
105      * inner class of this <tt>InnerClassEntry</tt>.
106      *
107      * @param innerNameIndex the index
108      */

109     public void setInnerNameIndex(int innerNameIndex) {
110         this.innerNameIndex = innerNameIndex;
111     }
112
113     /**
114      * Get the access flags of the inner class.
115      *
116      * @return the access flags
117      */

118     public int getInnerClassAccessFlags() {
119         return innerClassAccessFlags;
120     }
121
122     /**
123      * Set the access flags of the inner class.
124      *
125      * @param innerClassAccessFlags the access flags
126      */

127     public void setInnerClassAccessFlags(int innerClassAccessFlags) {
128         this.innerClassAccessFlags = innerClassAccessFlags;
129     }
130
131     /**
132      * Get the the access flags of the inner class as a hex string.
133      *
134      * @return the hex string
135      */

136     public String JavaDoc getInnerClassFormattedAccessFlags() {
137         return printAccessFlags(innerClassAccessFlags);
138     }
139
140     /**
141      * Get the verbose description of the access flags of the inner class.
142      *
143      * @return the description
144      */

145     public String JavaDoc getInnerClassAccessFlagsVerbose() {
146         return printAccessFlagsVerbose(innerClassAccessFlags);
147     }
148
149     public void read(DataInput in)
150             throws InvalidByteCodeException, IOException {
151
152         innerClassInfoIndex = in.readUnsignedShort();
153         outerClassInfoIndex = in.readUnsignedShort();
154         innerNameIndex = in.readUnsignedShort();
155         innerClassAccessFlags = in.readUnsignedShort();
156
157         if (debug) debug("read ");
158     }
159
160     public void write(DataOutput out)
161             throws InvalidByteCodeException, IOException {
162
163         super.write(out);
164         out.writeShort(innerClassInfoIndex);
165         out.writeShort(outerClassInfoIndex);
166         out.writeShort(innerNameIndex);
167         out.writeShort(innerClassAccessFlags);
168         if (debug) debug("wrote ");
169     }
170
171     protected void debug(String JavaDoc message) {
172         super.debug(message + "InnerClasses entry with inner_class_info_index " + innerClassInfoIndex +
173                 ", outer_class_info_index " + outerClassInfoIndex + ", inner_name_index " + innerNameIndex +
174                 ", access flags " + printAccessFlags(innerClassAccessFlags));
175     }
176
177     protected String JavaDoc printAccessFlagsVerbose(int accessFlags) {
178         return printAccessFlagsVerbose(AccessFlags.INNER_CLASS_ACCESS_FLAGS,
179                 AccessFlags.INNER_CLASS_ACCESS_FLAGS_VERBOSE, accessFlags);
180     }
181
182 }
183
Popular Tags