KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > Clazz


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile;
22
23 import proguard.classfile.visitor.*;
24 import proguard.classfile.attribute.visitor.AttributeVisitor;
25 import proguard.classfile.constant.visitor.ConstantVisitor;
26
27
28 /**
29  * This interface provides access to the representation of a Java class.
30  *
31  * @author Eric Lafortune
32  */

33 public interface Clazz extends VisitorAccepter
34 {
35     /**
36      * Returns the access flags of this class.
37      * @see ClassConstants
38      */

39     public int getAccessFlags();
40
41     /**
42      * Returns the full internal name of this class.
43      */

44     public String JavaDoc getName();
45
46     /**
47      * Returns the full internal name of the super class of this class, or
48      * null if this class represents java.lang.Object.
49      */

50     public String JavaDoc getSuperName();
51
52     /**
53      * Returns the number of interfaces that this class implements.
54      */

55     public int getInterfaceCount();
56
57     /**
58      * Returns the full internal name of the interface at the given index of
59      * this class.
60      */

61     public String JavaDoc getInterfaceName(int index);
62
63     /**
64      * Returns the tag value of the Constant at the specified index.
65      */

66     public int getTag(int constantIndex);
67
68     /**
69      * Returns the String value of the Utf8Constant at the specified index.
70      */

71     public String JavaDoc getString(int constantIndex);
72
73     /**
74      * Returns the String value of the StringConstant at the specified index.
75      */

76     public String JavaDoc getStringString(int constantIndex);
77
78     /**
79      * Returns the class name of ClassConstant at the specified index.
80      */

81     public String JavaDoc getClassName(int constantIndex);
82
83     /**
84      * Returns the name of the NameAndTypeConstant at the specified index.
85      */

86     public String JavaDoc getName(int constantIndex);
87
88     /**
89      * Returns the type of the NameAndTypeConstant at the specified index.
90      */

91     public String JavaDoc getType(int constantIndex);
92
93
94     // Methods pertaining to related classes.
95

96     /**
97      * Notifies this Clazz that it is being subclassed by another class.
98      */

99     public void addSubClass(Clazz clazz);
100
101     /**
102      * Returns the super class of this class.
103      */

104     public Clazz getSuperClass();
105
106     /**
107      * Returns the interface at the given index.
108      */

109     public Clazz getInterface(int index);
110
111     /**
112      * Returns whether this class extends the given class.
113      * A class is always considered to extend itself.
114      * Interfaces are considered to only extend the root Object class.
115      */

116     public boolean extends_(Clazz clazz);
117
118     /**
119      * Returns whether this class implements the given class.
120      * A class is always considered to implement itself.
121      * Interfaces are considered to implement all their superinterfaces.
122      */

123     public boolean extendsOrImplements(Clazz clazz);
124
125
126     // Methods for getting specific class members.
127

128     /**
129      * Returns the field with the given name and descriptor.
130      */

131     Field findField(String JavaDoc name, String JavaDoc descriptor);
132
133     /**
134      * Returns the method with the given name and descriptor.
135      */

136     Method findMethod(String JavaDoc name, String JavaDoc descriptor);
137
138
139     // Methods for accepting various types of visitors.
140

141     /**
142      * Accepts the given class visitor.
143      */

144     public void accept(ClassVisitor classVisitor);
145
146     /**
147      * Accepts the given class visitor in the class hierarchy.
148      * @param visitThisClass specifies whether to visit this class.
149      * @param visitSuperClass specifies whether to visit the super classes.
150      * @param visitInterfaces specifies whether to visit the interfaces.
151      * @param visitSubclasses specifies whether to visit the subclasses.
152      * @param classVisitor the <code>ClassVisitor</code> that will
153      * visit the class hierarchy.
154      */

155     public void hierarchyAccept(boolean visitThisClass,
156                                 boolean visitSuperClass,
157                                 boolean visitInterfaces,
158                                 boolean visitSubclasses,
159                                 ClassVisitor classVisitor);
160
161     /**
162      * Lets the given constant pool entry visitor visit all constant pool entries
163      * of this class.
164      */

165     public void constantPoolEntriesAccept(ConstantVisitor constantVisitor);
166
167     /**
168      * Lets the given constant pool entry visitor visit the constant pool entry
169      * at the specified index.
170      */

171     public void constantPoolEntryAccept(int index, ConstantVisitor constantVisitor);
172
173     /**
174      * Lets the given member info visitor visit all fields of this class.
175      */

176     public void fieldsAccept(MemberVisitor memberVisitor);
177
178     /**
179      * Lets the given member info visitor visit the specified field.
180      */

181     public void fieldAccept(String JavaDoc name, String JavaDoc descriptor, MemberVisitor memberVisitor);
182
183     /**
184      * Lets the given member info visitor visit all methods of this class.
185      */

186     public void methodsAccept(MemberVisitor memberVisitor);
187
188     /**
189      * Lets the given member info visitor visit the specified method.
190      */

191     public void methodAccept(String JavaDoc name, String JavaDoc descriptor, MemberVisitor memberVisitor);
192
193     /**
194      * Returns whether the given method may possibly have implementing or
195      * overriding methods down the class hierarchy. This can only be true
196      * if the class is not final, and the method is not private, static, or
197      * final, or a constructor.
198      * @param method the method that may have implementations.
199      * @return whether it may have implementations.
200      */

201     public boolean mayHaveImplementations(Method method);
202
203     /**
204      * Lets the given member info visitor visit all concrete implementations of
205      * the specified method in the class hierarchy.
206      * @param method the method that may have concrete implementations.
207      * @param visitThisMethod specifies whether to visit the method in
208      * this class.
209      * @param memberVisitor the <code>MemberVisitor</code> that will
210      * visit the method hierarchy.
211      */

212     public void methodImplementationsAccept(Method method,
213                                             boolean visitThisMethod,
214                                             MemberVisitor memberVisitor);
215
216     /**
217      * Lets the given member info visitor visit all concrete implementations of
218      * the specified method in the class hierarchy.
219      * @param name the method name.
220      * @param type the method descriptor.
221      * @param visitThisMethod specifies whether to visit the method in
222      * this class.
223      * @param memberVisitor the <code>MemberVisitor</code> that will
224      * visit the method hierarchy.
225      */

226     public void methodImplementationsAccept(String JavaDoc name,
227                                             String JavaDoc type,
228                                             boolean visitThisMethod,
229                                             MemberVisitor memberVisitor);
230
231     /**
232      * Lets the given member info visitor visit all concrete implementations of
233      * the specified method in the class hierarchy.
234      * @param name the method name.
235      * @param descriptor the method descriptor.
236      * @param visitThisMethod specifies whether to visit the method in
237      * this class.
238      * @param visitSpecialMethods specifies whether to visit the special
239      * initializer methods.
240      * @param visitSuperMethods specifies whether to visit the method in
241      * the super classes.
242      * @param visitOverridingMethods specifies whether to visit the method in
243      * the subclasses.
244      * @param visitSpecialMethods specifies whether to visit special methods.
245      * @param memberVisitor the <code>MemberVisitor</code> that
246      * will visit the method hierarchy.
247      */

248     public void methodImplementationsAccept(String JavaDoc name,
249                                             String JavaDoc descriptor,
250                                             boolean visitThisMethod,
251                                             boolean visitSpecialMethods,
252                                             boolean visitSuperMethods,
253                                             boolean visitOverridingMethods,
254                                             MemberVisitor memberVisitor);
255     /**
256      * Lets the given member info visitor visit all concrete implementations of
257      * the specified method in the class hierarchy.
258      * @param name the method name.
259      * @param descriptor the method descriptor.
260      * @param method the method itself, if present.
261      * @param visitThisMethod specifies whether to visit the method in
262      * this class.
263      * @param visitSpecialMethods specifies whether to visit the method in
264      * the interfaces.
265      * @param visitSuperMethods specifies whether to visit the method in
266      * the super classes.
267      * @param visitOverridingMethods specifies whether to visit the method in
268      * the subclasses.
269      * @param visitSpecialMethods specifies whether to visit special methods.
270      * @param memberVisitor the <code>MemberVisitor</code> that
271      * will visit the method hierarchy.
272      */

273     public void methodImplementationsAccept(String JavaDoc name,
274                                             String JavaDoc descriptor,
275                                             Method method,
276                                             boolean visitThisMethod,
277                                             boolean visitSuperMethods,
278                                             boolean visitOverridingMethods,
279                                             boolean visitSpecialMethods,
280                                             MemberVisitor memberVisitor);
281
282     /**
283      * Lets the given attribute info visitor visit all attributes of this class.
284      */

285     public void attributesAccept(AttributeVisitor attributeVisitor);
286 }
287
Popular Tags