KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sli > kim > classfile > ClassInfo


1 package sli.kim.classfile;
2
3 import java.util.Vector JavaDoc;
4
5 /**
6 * A class for storing information about a class.
7 * This information can be read in by a ClassFileReader, or written out by
8 * a ClassFileWriter.
9 *
10 * @see FieldInfo
11 * @see MethodInfo
12 * @see AttributeInfo
13 * @see ClassFileReader
14 * @see ClassFileWriter
15 */

16 public class ClassInfo extends CommonInfo {
17     private String JavaDoc superName = "java.lang.Object", sourceFile;
18     private ConstPool cp;
19     // Vector of Strings
20
private Vector JavaDoc interfaces = new Vector JavaDoc();
21     // Vector of FieldInfo
22
private Vector JavaDoc fields = new Vector JavaDoc();
23     // Vector of MethodInfo
24
private Vector JavaDoc methods = new Vector JavaDoc();
25     private InnerClassInfo[] innerClasses;
26
27     /**
28     * Set the constant pool. The ClassInfo class itself does not actually use
29     * the ConstPool for anything. This method is useful if the ClassInfo is
30     * being read in by a ClassFileReader and there are attributes that the
31     * Reader does not understand, which reference entries in the constant
32     * pool. The best example of such an attribute is method bytecodes.
33     * In a future release, ClassFileReaders will understand bytecodes,
34     * and so this method will become less important.
35     *
36     * <p>The new ConstPool is not immutable. It may be passed to a
37     * ClassFileWriter, which will add entries as needed.
38     *
39     * @see ConstPool
40     */

41     public void setConstPool(ConstPool cp) {
42         this.cp = cp;
43     }
44
45     /**
46     * Get the constant pool. The ClassInfo class itself does not use the
47     * constant pool for anthing. The constant pool is useful if the ClassInfo is
48     * being written out by a ClassFileWriter and there are attributes that the
49     * Writer does not understand, which reference entries in the constant
50     * pool. The best example of such an attribute is method bytecodes.
51     * The Writer will use the ConstPool returned by this method in preference
52     * to creating its own ConstPool. Letting the Writer create its own
53     * ConstPool is probably not a good idea, for the reasons describe above.
54     * In a future release, ClassFileWriters will understand bytecodes, and so
55     * this method will become less important.
56     *
57     * @see ConstPool
58     */

59     public ConstPool getConstPool() {
60         return cp;
61     }
62
63     /**
64     * Set the name of the super class. The name should be of the form "java.lang.String".
65     */

66     public void setSuperClassName(String JavaDoc name) {
67         superName = name;
68     }
69
70     /**
71     * Get the name of the super class. The name is of the form "java.lang.String".
72     */

73     public String JavaDoc getSuperClassName() {
74         return superName;
75     }
76
77     /**
78     * Add an interface that the class implements.
79     */

80     public void addInterface(String JavaDoc interfaceName) {
81         interfaces.addElement(interfaceName);
82     }
83
84     /**
85     * Get the interfaces that this class implements.
86     */

87     public String JavaDoc[] getInterfaces() {
88         String JavaDoc[] list = new String JavaDoc[interfaces.size()];
89         interfaces.copyInto(list);
90         return list;
91     }
92
93     /**
94     * Add a field to this class. The FieldInfo should be need not be
95     * entirely filled out before being added.
96     *
97     * @see FieldInfo
98     */

99     public void addField(FieldInfo fieldInfo) {
100         fields.addElement(fieldInfo);
101     }
102
103     /**
104     * Get the fields of this class.
105     *
106     * @see FieldInfo
107     */

108     public FieldInfo[] getFields() {
109         FieldInfo[] list = new FieldInfo[fields.size()];
110         fields.copyInto(list);
111         return list;
112     }
113
114     /**
115     * Add a method to this class. The MethodInfo should be need not be
116     * entirely filled out before being added.
117     *
118     * @see MethodInfo
119     */

120     public void addMethod(MethodInfo methodInfo) {
121         methods.addElement(methodInfo);
122     }
123
124     /**
125     * Get the methods of this class.
126     *
127     * @see MethodInfo
128     */

129     public MethodInfo[] getMethods() {
130         MethodInfo[] list = new MethodInfo[methods.size()];
131         methods.copyInto(list);
132         return list;
133     }
134     
135     /**
136     * Specify the source file for this class, if it is known.
137     */

138     public void setSourceFile(String JavaDoc sourceFile) {
139         this.sourceFile = sourceFile;
140     }
141
142     /**
143     * Get the source file for this class. If the file is not known, this
144     * may return null.
145     */

146     public String JavaDoc getSourceFile() {
147         return sourceFile;
148     }
149
150     /**
151     * Set the inner class information of this class. Using inner classes is
152     * a bit tricky. The array should include elements for every inner class
153     * of this class, and every class that contains this class. For example:
154     *
155     *<pre>class Foo {
156     * class Bar {
157     * class Quux {
158     * class Squish {
159     * }
160     * }
161     * }
162     * class Baz {
163     * }
164     *}</pre>
165     *
166     * If this ClassInfo is for Foo.Bar, then the inner classes array should be
167     * {FooInfo, BarInfo, QuuxInfo}. The order is important: outer classes
168     * <strong>must</strong> come before their inner classes. Note that the
169     * current class must have an entry in the array. Squish and Baz may be
170     * included in the array, but they're not necessary.
171     *
172     * @see InnerClassInfo
173     */

174     public void setInnerClasses(InnerClassInfo[] innerClasses) {
175         this.innerClasses = innerClasses;
176     }
177
178     /**
179     * Get the inner class information of this class.
180     *
181     * @see #setInnerClasses()
182     */

183     public InnerClassInfo[] getInnerClasses() {
184         return innerClasses;
185     }
186 }
187
Popular Tags