001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This library is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This library is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this library; if not, write to the Free Software Foundation,
019: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.classfile;
022:
023: import proguard.classfile.attribute.visitor.AttributeVisitor;
024: import proguard.classfile.constant.visitor.ConstantVisitor;
025: import proguard.classfile.visitor.*;
026:
027: /**
028: * This interface provides access to the representation of a Java class.
029: *
030: * @author Eric Lafortune
031: */
032: public interface Clazz extends VisitorAccepter {
033: /**
034: * Returns the access flags of this class.
035: * @see ClassConstants
036: */
037: public int getAccessFlags();
038:
039: /**
040: * Returns the full internal name of this class.
041: */
042: public String getName();
043:
044: /**
045: * Returns the full internal name of the super class of this class, or
046: * null if this class represents java.lang.Object.
047: */
048: public String getSuperName();
049:
050: /**
051: * Returns the number of interfaces that this class implements.
052: */
053: public int getInterfaceCount();
054:
055: /**
056: * Returns the full internal name of the interface at the given index of
057: * this class.
058: */
059: public String getInterfaceName(int index);
060:
061: /**
062: * Returns the tag value of the Constant at the specified index.
063: */
064: public int getTag(int constantIndex);
065:
066: /**
067: * Returns the String value of the Utf8Constant at the specified index.
068: */
069: public String getString(int constantIndex);
070:
071: /**
072: * Returns the String value of the StringConstant at the specified index.
073: */
074: public String getStringString(int constantIndex);
075:
076: /**
077: * Returns the class name of ClassConstant at the specified index.
078: */
079: public String getClassName(int constantIndex);
080:
081: /**
082: * Returns the name of the NameAndTypeConstant at the specified index.
083: */
084: public String getName(int constantIndex);
085:
086: /**
087: * Returns the type of the NameAndTypeConstant at the specified index.
088: */
089: public String getType(int constantIndex);
090:
091: // Methods pertaining to related classes.
092:
093: /**
094: * Notifies this Clazz that it is being subclassed by another class.
095: */
096: public void addSubClass(Clazz clazz);
097:
098: /**
099: * Returns the super class of this class.
100: */
101: public Clazz getSuperClass();
102:
103: /**
104: * Returns the interface at the given index.
105: */
106: public Clazz getInterface(int index);
107:
108: /**
109: * Returns whether this class extends the given class.
110: * A class is always considered to extend itself.
111: * Interfaces are considered to only extend the root Object class.
112: */
113: public boolean extends_(Clazz clazz);
114:
115: /**
116: * Returns whether this class implements the given class.
117: * A class is always considered to implement itself.
118: * Interfaces are considered to implement all their superinterfaces.
119: */
120: public boolean extendsOrImplements(Clazz clazz);
121:
122: // Methods for getting specific class members.
123:
124: /**
125: * Returns the field with the given name and descriptor.
126: */
127: Field findField(String name, String descriptor);
128:
129: /**
130: * Returns the method with the given name and descriptor.
131: */
132: Method findMethod(String name, String descriptor);
133:
134: // Methods for accepting various types of visitors.
135:
136: /**
137: * Accepts the given class visitor.
138: */
139: public void accept(ClassVisitor classVisitor);
140:
141: /**
142: * Accepts the given class visitor in the class hierarchy.
143: * @param visitThisClass specifies whether to visit this class.
144: * @param visitSuperClass specifies whether to visit the super classes.
145: * @param visitInterfaces specifies whether to visit the interfaces.
146: * @param visitSubclasses specifies whether to visit the subclasses.
147: * @param classVisitor the <code>ClassVisitor</code> that will
148: * visit the class hierarchy.
149: */
150: public void hierarchyAccept(boolean visitThisClass,
151: boolean visitSuperClass, boolean visitInterfaces,
152: boolean visitSubclasses, ClassVisitor classVisitor);
153:
154: /**
155: * Lets the given constant pool entry visitor visit all constant pool entries
156: * of this class.
157: */
158: public void constantPoolEntriesAccept(
159: ConstantVisitor constantVisitor);
160:
161: /**
162: * Lets the given constant pool entry visitor visit the constant pool entry
163: * at the specified index.
164: */
165: public void constantPoolEntryAccept(int index,
166: ConstantVisitor constantVisitor);
167:
168: /**
169: * Lets the given member info visitor visit all fields of this class.
170: */
171: public void fieldsAccept(MemberVisitor memberVisitor);
172:
173: /**
174: * Lets the given member info visitor visit the specified field.
175: */
176: public void fieldAccept(String name, String descriptor,
177: MemberVisitor memberVisitor);
178:
179: /**
180: * Lets the given member info visitor visit all methods of this class.
181: */
182: public void methodsAccept(MemberVisitor memberVisitor);
183:
184: /**
185: * Lets the given member info visitor visit the specified method.
186: */
187: public void methodAccept(String name, String descriptor,
188: MemberVisitor memberVisitor);
189:
190: /**
191: * Returns whether the given method may possibly have implementing or
192: * overriding methods down the class hierarchy. This can only be true
193: * if the class is not final, and the method is not private, static, or
194: * final, or a constructor.
195: * @param method the method that may have implementations.
196: * @return whether it may have implementations.
197: */
198: public boolean mayHaveImplementations(Method method);
199:
200: /**
201: * Lets the given member info visitor visit all concrete implementations of
202: * the specified method in the class hierarchy.
203: * @param method the method that may have concrete implementations.
204: * @param visitThisMethod specifies whether to visit the method in
205: * this class.
206: * @param memberVisitor the <code>MemberVisitor</code> that will
207: * visit the method hierarchy.
208: */
209: public void methodImplementationsAccept(Method method,
210: boolean visitThisMethod, MemberVisitor memberVisitor);
211:
212: /**
213: * Lets the given member info visitor visit all concrete implementations of
214: * the specified method in the class hierarchy.
215: * @param name the method name.
216: * @param type the method descriptor.
217: * @param visitThisMethod specifies whether to visit the method in
218: * this class.
219: * @param memberVisitor the <code>MemberVisitor</code> that will
220: * visit the method hierarchy.
221: */
222: public void methodImplementationsAccept(String name, String type,
223: boolean visitThisMethod, MemberVisitor memberVisitor);
224:
225: /**
226: * Lets the given member info visitor visit all concrete implementations of
227: * the specified method in the class hierarchy.
228: * @param name the method name.
229: * @param descriptor the method descriptor.
230: * @param visitThisMethod specifies whether to visit the method in
231: * this class.
232: * @param visitSpecialMethods specifies whether to visit the special
233: * initializer methods.
234: * @param visitSuperMethods specifies whether to visit the method in
235: * the super classes.
236: * @param visitOverridingMethods specifies whether to visit the method in
237: * the subclasses.
238: * @param visitSpecialMethods specifies whether to visit special methods.
239: * @param memberVisitor the <code>MemberVisitor</code> that
240: * will visit the method hierarchy.
241: */
242: public void methodImplementationsAccept(String name,
243: String descriptor, boolean visitThisMethod,
244: boolean visitSpecialMethods, boolean visitSuperMethods,
245: boolean visitOverridingMethods, MemberVisitor memberVisitor);
246:
247: /**
248: * Lets the given member info visitor visit all concrete implementations of
249: * the specified method in the class hierarchy.
250: * @param name the method name.
251: * @param descriptor the method descriptor.
252: * @param method the method itself, if present.
253: * @param visitThisMethod specifies whether to visit the method in
254: * this class.
255: * @param visitSpecialMethods specifies whether to visit the method in
256: * the interfaces.
257: * @param visitSuperMethods specifies whether to visit the method in
258: * the super classes.
259: * @param visitOverridingMethods specifies whether to visit the method in
260: * the subclasses.
261: * @param visitSpecialMethods specifies whether to visit special methods.
262: * @param memberVisitor the <code>MemberVisitor</code> that
263: * will visit the method hierarchy.
264: */
265: public void methodImplementationsAccept(String name,
266: String descriptor, Method method, boolean visitThisMethod,
267: boolean visitSuperMethods, boolean visitOverridingMethods,
268: boolean visitSpecialMethods, MemberVisitor memberVisitor);
269:
270: /**
271: * Lets the given attribute info visitor visit all attributes of this class.
272: */
273: public void attributesAccept(AttributeVisitor attributeVisitor);
274: }
|