1/* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2013 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 */ 21package proguard.classfile; 22 23import proguard.classfile.attribute.visitor.AttributeVisitor; 24import proguard.classfile.constant.visitor.ConstantVisitor; 25import proguard.classfile.visitor.*; 26 27 28/** 29 * This interface provides access to the representation of a Java class. 30 * 31 * @author Eric Lafortune 32 */ 33public 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 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 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 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 getString(int constantIndex); 72 73 /** 74 * Returns the String value of the StringConstant at the specified index. 75 */ 76 public String getStringString(int constantIndex); 77 78 /** 79 * Returns the class name of ClassConstant at the specified index. 80 */ 81 public String getClassName(int constantIndex); 82 83 /** 84 * Returns the name of the NameAndTypeConstant at the specified index. 85 */ 86 public String getName(int constantIndex); 87 88 /** 89 * Returns the type of the NameAndTypeConstant at the specified index. 90 */ 91 public String getType(int constantIndex); 92 93 /** 94 * Returns the name of the RefConstant at the specified index. 95 */ 96 public String getRefName(int constantIndex); 97 98 /** 99 * Returns the type of the RefConstant at the specified index. 100 */ 101 public String getRefType(int constantIndex); 102 103 104 // Methods pertaining to related classes. 105 106 /** 107 * Notifies this Clazz that it is being subclassed by another class. 108 */ 109 public void addSubClass(Clazz clazz); 110 111 /** 112 * Returns the super class of this class. 113 */ 114 public Clazz getSuperClass(); 115 116 /** 117 * Returns the interface at the given index. 118 */ 119 public Clazz getInterface(int index); 120 121 /** 122 * Returns whether this class extends the given class. 123 * A class is always considered to extend itself. 124 * Interfaces are considered to only extend the root Object class. 125 */ 126 public boolean extends_(Clazz clazz); 127 128 /** 129 * Returns whether this class extends the specified class. 130 * A class is always considered to extend itself. 131 * Interfaces are considered to only extend the root Object class. 132 */ 133 public boolean extends_(String className); 134 135 /** 136 * Returns whether this class implements the given class. 137 * A class is always considered to implement itself. 138 * Interfaces are considered to implement all their superinterfaces. 139 */ 140 public boolean extendsOrImplements(Clazz clazz); 141 142 /** 143 * Returns whether this class implements the specified class. 144 * A class is always considered to implement itself. 145 * Interfaces are considered to implement all their superinterfaces. 146 */ 147 public boolean extendsOrImplements(String className); 148 149 150 // Methods for getting specific class members. 151 152 /** 153 * Returns the field with the given name and descriptor. 154 */ 155 Field findField(String name, String descriptor); 156 157 /** 158 * Returns the method with the given name and descriptor. 159 */ 160 Method findMethod(String name, String descriptor); 161 162 163 // Methods for accepting various types of visitors. 164 165 /** 166 * Accepts the given class visitor. 167 */ 168 public void accept(ClassVisitor classVisitor); 169 170 /** 171 * Accepts the given class visitor in the class hierarchy. 172 * @param visitThisClass specifies whether to visit this class. 173 * @param visitSuperClass specifies whether to visit the super classes. 174 * @param visitInterfaces specifies whether to visit the interfaces. 175 * @param visitSubclasses specifies whether to visit the subclasses. 176 * @param classVisitor the <code>ClassVisitor</code> that will 177 * visit the class hierarchy. 178 */ 179 public void hierarchyAccept(boolean visitThisClass, 180 boolean visitSuperClass, 181 boolean visitInterfaces, 182 boolean visitSubclasses, 183 ClassVisitor classVisitor); 184 185 /** 186 * Lets the given class visitor visit all known subclasses. 187 * @param classVisitor the <code>ClassVisitor</code> that will visit the 188 * subclasses. 189 */ 190 public void subclassesAccept(ClassVisitor classVisitor); 191 192 /** 193 * Lets the given constant pool entry visitor visit all constant pool entries 194 * of this class. 195 */ 196 public void constantPoolEntriesAccept(ConstantVisitor constantVisitor); 197 198 /** 199 * Lets the given constant pool entry visitor visit the constant pool entry 200 * at the specified index. 201 */ 202 public void constantPoolEntryAccept(int index, ConstantVisitor constantVisitor); 203 204 /** 205 * Lets the given constant pool entry visitor visit the class constant pool 206 * entry of this class. 207 */ 208 public void thisClassConstantAccept(ConstantVisitor constantVisitor); 209 210 /** 211 * Lets the given constant pool entry visitor visit the class constant pool 212 * entry of the super class of this class, if there is one. 213 */ 214 public void superClassConstantAccept(ConstantVisitor constantVisitor); 215 216 /** 217 * Lets the given constant pool entry visitor visit the class constant pool 218 * entries for all interfaces of this class. 219 */ 220 public void interfaceConstantsAccept(ConstantVisitor constantVisitor); 221 222 /** 223 * Lets the given member info visitor visit all fields of this class. 224 */ 225 public void fieldsAccept(MemberVisitor memberVisitor); 226 227 /** 228 * Lets the given member info visitor visit the specified field. 229 */ 230 public void fieldAccept(String name, String descriptor, MemberVisitor memberVisitor); 231 232 /** 233 * Lets the given member info visitor visit all methods of this class. 234 */ 235 public void methodsAccept(MemberVisitor memberVisitor); 236 237 /** 238 * Lets the given member info visitor visit the specified method. 239 */ 240 public void methodAccept(String name, String descriptor, MemberVisitor memberVisitor); 241 242 /** 243 * Returns whether the given method may possibly have implementing or 244 * overriding methods down the class hierarchy. This can only be true 245 * if the class is not final, and the method is not private, static, or 246 * final, or a constructor. 247 * @param method the method that may have implementations. 248 * @return whether it may have implementations. 249 */ 250 public boolean mayHaveImplementations(Method method); 251 252 /** 253 * Lets the given attribute info visitor visit all attributes of this class. 254 */ 255 public void attributesAccept(AttributeVisitor attributeVisitor); 256 257 /** 258 * Lets the given attribute info visitor visit the specified attribute. 259 */ 260 public void attributeAccept(String name, AttributeVisitor attributeVisitor); 261} 262