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