• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  *             of Java bytecode.
4  *
5  * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program 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 program 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 General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 package proguard.classfile;
22 
23 import proguard.classfile.attribute.visitor.AttributeVisitor;
24 import proguard.classfile.constant.visitor.ConstantVisitor;
25 import proguard.classfile.visitor.*;
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      */
getAccessFlags()39     public int getAccessFlags();
40 
41     /**
42      * Returns the full internal name of this class.
43      */
getName()44     public String 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      */
getSuperName()50     public String getSuperName();
51 
52     /**
53      * Returns the number of interfaces that this class implements.
54      */
getInterfaceCount()55     public int getInterfaceCount();
56 
57     /**
58      * Returns the full internal name of the interface at the given index of
59      * this class.
60      */
getInterfaceName(int index)61     public String getInterfaceName(int index);
62 
63     /**
64      * Returns the tag value of the Constant at the specified index.
65      */
getTag(int constantIndex)66     public int getTag(int constantIndex);
67 
68     /**
69      * Returns the String value of the Utf8Constant at the specified index.
70      */
getString(int constantIndex)71     public String getString(int constantIndex);
72 
73     /**
74      * Returns the String value of the StringConstant at the specified index.
75      */
getStringString(int constantIndex)76     public String getStringString(int constantIndex);
77 
78     /**
79      * Returns the class name of ClassConstant at the specified index.
80      */
getClassName(int constantIndex)81     public String getClassName(int constantIndex);
82 
83     /**
84      * Returns the name of the NameAndTypeConstant at the specified index.
85      */
getName(int constantIndex)86     public String getName(int constantIndex);
87 
88     /**
89      * Returns the type of the NameAndTypeConstant at the specified index.
90      */
getType(int constantIndex)91     public String 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      */
addSubClass(Clazz clazz)99     public void addSubClass(Clazz clazz);
100 
101     /**
102      * Returns the super class of this class.
103      */
getSuperClass()104     public Clazz getSuperClass();
105 
106     /**
107      * Returns the interface at the given index.
108      */
getInterface(int index)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      */
extends_(Clazz clazz)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      */
extendsOrImplements(Clazz clazz)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      */
findField(String name, String descriptor)131     Field findField(String name, String descriptor);
132 
133     /**
134      * Returns the method with the given name and descriptor.
135      */
findMethod(String name, String descriptor)136     Method findMethod(String name, String descriptor);
137 
138 
139     // Methods for accepting various types of visitors.
140 
141     /**
142      * Accepts the given class visitor.
143      */
accept(ClassVisitor classVisitor)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      */
hierarchyAccept(boolean visitThisClass, boolean visitSuperClass, boolean visitInterfaces, boolean visitSubclasses, ClassVisitor classVisitor)155     public void hierarchyAccept(boolean      visitThisClass,
156                                 boolean      visitSuperClass,
157                                 boolean      visitInterfaces,
158                                 boolean      visitSubclasses,
159                                 ClassVisitor classVisitor);
160 
161     /**
162      * Lets the given class visitor visit all known subclasses.
163      * @param classVisitor the <code>ClassVisitor</code> that will visit the
164      *                     subclasses.
165      */
subclassesAccept(ClassVisitor classVisitor)166     public void subclassesAccept(ClassVisitor classVisitor);
167 
168     /**
169      * Lets the given constant pool entry visitor visit all constant pool entries
170      * of this class.
171      */
constantPoolEntriesAccept(ConstantVisitor constantVisitor)172     public void constantPoolEntriesAccept(ConstantVisitor constantVisitor);
173 
174     /**
175      * Lets the given constant pool entry visitor visit the constant pool entry
176      * at the specified index.
177      */
constantPoolEntryAccept(int index, ConstantVisitor constantVisitor)178     public void constantPoolEntryAccept(int index, ConstantVisitor constantVisitor);
179 
180     /**
181      * Lets the given constant pool entry visitor visit the class constant pool
182      * entry of this class.
183      */
thisClassConstantAccept(ConstantVisitor constantVisitor)184     public void thisClassConstantAccept(ConstantVisitor constantVisitor);
185 
186     /**
187      * Lets the given constant pool entry visitor visit the class constant pool
188      * entry of the super class of this class, if there is one.
189      */
superClassConstantAccept(ConstantVisitor constantVisitor)190     public void superClassConstantAccept(ConstantVisitor constantVisitor);
191 
192     /**
193      * Lets the given constant pool entry visitor visit the class constant pool
194      * entries for all interfaces of this class.
195      */
interfaceConstantsAccept(ConstantVisitor constantVisitor)196     public void interfaceConstantsAccept(ConstantVisitor constantVisitor);
197 
198     /**
199      * Lets the given member info visitor visit all fields of this class.
200      */
fieldsAccept(MemberVisitor memberVisitor)201     public void fieldsAccept(MemberVisitor memberVisitor);
202 
203     /**
204      * Lets the given member info visitor visit the specified field.
205      */
fieldAccept(String name, String descriptor, MemberVisitor memberVisitor)206     public void fieldAccept(String name, String descriptor, MemberVisitor memberVisitor);
207 
208     /**
209      * Lets the given member info visitor visit all methods of this class.
210      */
methodsAccept(MemberVisitor memberVisitor)211     public void methodsAccept(MemberVisitor memberVisitor);
212 
213     /**
214      * Lets the given member info visitor visit the specified method.
215      */
methodAccept(String name, String descriptor, MemberVisitor memberVisitor)216     public void methodAccept(String name, String descriptor, MemberVisitor memberVisitor);
217 
218     /**
219      * Returns whether the given method may possibly have implementing or
220      * overriding methods down the class hierarchy. This can only be true
221      * if the class is not final, and the method is not private, static, or
222      * final, or a constructor.
223      * @param method the method that may have implementations.
224      * @return whether it may have implementations.
225      */
mayHaveImplementations(Method method)226     public boolean mayHaveImplementations(Method method);
227 
228     /**
229      * Lets the given attribute info visitor visit all attributes of this class.
230      */
attributesAccept(AttributeVisitor attributeVisitor)231     public void attributesAccept(AttributeVisitor attributeVisitor);
232 }
233