com.ibm.wala.shrikeCT
Class ClassReader

java.lang.Object
  extended by com.ibm.wala.shrikeCT.ClassReader
All Implemented Interfaces:
ClassConstants

public final class ClassReader
extends java.lang.Object
implements ClassConstants

This is the core class for reading class file data. ClassReader performs lazy parsing, and thus most of the methods can throw an InvalidClassFileException.


Nested Class Summary
static class ClassReader.AttrIterator
          AttrIterator provides access to attributes in the class file.
 
Field Summary
 
Fields inherited from interface com.ibm.wala.shrikeCT.ClassConstants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, CONSTANT_FieldRef, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodRef, CONSTANT_Long, CONSTANT_MethodRef, CONSTANT_NameAndType, CONSTANT_String, CONSTANT_Utf8, MAGIC
 
Constructor Summary
ClassReader(byte[] bytes)
          Build a reader.
 
Method Summary
 int getAccessFlags()
           
 byte getByte(int i)
           
 byte[] getBytes()
           
 ConstantPoolParser getCP()
          This method allows direct read-only access to the constant pool for the class.
 int getFieldAccessFlags(int f)
           
 int getFieldCount()
           
 java.lang.String getFieldName(int f)
           
 int getFieldNameIndex(int f)
           
 int getFieldRawOffset(int f)
           
 int getFieldRawSize(int f)
           
 java.lang.String getFieldType(int f)
           
 int getFieldTypeIndex(int f)
           
 int getInt(int i)
           
 int getInterfaceCount()
           
 java.lang.String getInterfaceName(int i)
           
 int getInterfaceNameIndex(int i)
           
 int[] getInterfaceNameIndices()
           
 java.lang.String[] getInterfaceNames()
           
 int getMagic()
           
 int getMajorVersion()
           
 int getMethodAccessFlags(int m)
           
 int getMethodCount()
           
 java.lang.String getMethodName(int m)
           
 int getMethodNameIndex(int m)
           
 int getMethodRawOffset(int m)
           
 int getMethodRawSize(int m)
           
 java.lang.String getMethodType(int m)
           
 int getMethodTypeIndex(int m)
           
 int getMinorVersion()
           
 java.lang.String getName()
           
 int getNameIndex()
           
 int getShort(int i)
           
 java.lang.String getSuperName()
           
 int getSuperNameIndex()
           
 int getUShort(int i)
           
 void initClassAttributeIterator(ClassReader.AttrIterator iter)
          Point iter at the list of attributes for the class.
 void initFieldAttributeIterator(int f, ClassReader.AttrIterator iter)
          Point iter at the list of attributes for field f.
 void initMethodAttributeIterator(int m, ClassReader.AttrIterator iter)
          Point iter at the list of attributes for method m.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassReader

public ClassReader(byte[] bytes)
            throws InvalidClassFileException
Build a reader. If the class file data is corrupt an exception might not be thrown immediately. Instead an exception might be thrown later, during the execution of some access method. This is a consequence of the 'lazy parsing' performed by ClassReader.

Parameters:
bytes - the class file data
Throws:
InvalidClassFileException - the class file data is corrupt
Method Detail

getBytes

public byte[] getBytes()
Returns:
the raw class data bytes

getMagic

public int getMagic()
Returns:
the magic number at the start of the class file.

getMinorVersion

public int getMinorVersion()
Returns:
the minor version of the class file

getMajorVersion

public int getMajorVersion()
Returns:
the major version of the class file

getAccessFlags

public int getAccessFlags()
Returns:
the access flags for the class

getNameIndex

public int getNameIndex()
Returns:
the index of the constant pool entry for the class name

getName

public java.lang.String getName()
                         throws InvalidClassFileException
Returns:
the name of the class in JVM format (e.g., java/lang/Object)
Throws:
InvalidClassFileException

getSuperNameIndex

public int getSuperNameIndex()
Returns:
the constant pool index of the superclass name, or 0 if this is java.lang.Object

getSuperName

public java.lang.String getSuperName()
                              throws InvalidClassFileException
Returns:
the superclass name in JVM format (e.g., java/lang/Object), or null if this class is java.lang.Object
Throws:
InvalidClassFileException

getInterfaceCount

public int getInterfaceCount()
Returns:
the number of interfaces this class implements

getInterfaceNameIndex

public int getInterfaceNameIndex(int i)
Returns:
the constant pool index of the name of the i'th implemented interface

getInterfaceNameIndices

public int[] getInterfaceNameIndices()
Returns:
an array of the constant pool indices for the names of the implemented interfaces

getInterfaceName

public java.lang.String getInterfaceName(int i)
                                  throws InvalidClassFileException
Returns:
the name of the i'th implemented interface
Throws:
InvalidClassFileException

getInterfaceNames

public java.lang.String[] getInterfaceNames()
                                     throws InvalidClassFileException
Returns:
an array of the names of the implemented interfaces
Throws:
InvalidClassFileException

getCP

public ConstantPoolParser getCP()
This method allows direct read-only access to the constant pool for the class.

Returns:
the constant pool for the class

getInt

public int getInt(int i)
Returns:
the signed 32-bit value at offset i in the class data

getUShort

public int getUShort(int i)
Returns:
the unsigned 16-bit value at offset i in the class data

getShort

public int getShort(int i)
Returns:
the signed 16-bit value at offset i in the class data

getByte

public byte getByte(int i)
Returns:
the signed 8-bit value at offset i in the class data

getFieldCount

public int getFieldCount()
Returns:
the number of fields in the class

getFieldAccessFlags

public int getFieldAccessFlags(int f)
Returns:
the access flags for the f'th field

getFieldName

public java.lang.String getFieldName(int f)
                              throws InvalidClassFileException
Returns:
the name of the f'th field
Throws:
InvalidClassFileException

getFieldType

public java.lang.String getFieldType(int f)
                              throws InvalidClassFileException
Returns:
the type of the f'th field, in JVM format (e.g., I, Z, java/lang/Object)
Throws:
InvalidClassFileException

getFieldNameIndex

public int getFieldNameIndex(int f)
Returns:
the index of the constant pool entry for the name of the f'th field, in JVM format (e.g., I, Z, Ljava/lang/Object;)

getFieldTypeIndex

public int getFieldTypeIndex(int f)
Returns:
the index of the constant pool entry for the type of the f'th field, in JVM format (e.g., I, Z, Ljava/lang/Object;)

initFieldAttributeIterator

public void initFieldAttributeIterator(int f,
                                       ClassReader.AttrIterator iter)
Point iter at the list of attributes for field f.

Throws:
java.lang.IllegalArgumentException - if iter is null

getFieldRawOffset

public int getFieldRawOffset(int f)
Returns:
the offset of the raw class data for field f

getFieldRawSize

public int getFieldRawSize(int f)
Returns:
the size of the raw class data for field f

getMethodCount

public int getMethodCount()
Returns:
the number of methods in the class

getMethodRawOffset

public int getMethodRawOffset(int m)
Returns:
the offset of the raw class data for method m

getMethodRawSize

public int getMethodRawSize(int m)
Returns:
the size of the raw class data for method m

getMethodAccessFlags

public int getMethodAccessFlags(int m)
Returns:
the access flags for method m

getMethodName

public java.lang.String getMethodName(int m)
                               throws InvalidClassFileException
Returns:
the name of method m
Throws:
InvalidClassFileException

getMethodType

public java.lang.String getMethodType(int m)
                               throws InvalidClassFileException
Returns:
the method descriptor of method m in JVM format (e.g., V(ILjava/lang/Object;) )
Throws:
InvalidClassFileException

getMethodNameIndex

public int getMethodNameIndex(int m)
Returns:
the constant pool index of the name of method m

getMethodTypeIndex

public int getMethodTypeIndex(int m)
Returns:
the constant pool index of the method descriptor of method m

initMethodAttributeIterator

public void initMethodAttributeIterator(int m,
                                        ClassReader.AttrIterator iter)
Point iter at the list of attributes for method m.

Throws:
java.lang.IllegalArgumentException - if iter is null

initClassAttributeIterator

public void initClassAttributeIterator(ClassReader.AttrIterator iter)
Point iter at the list of attributes for the class.

Throws:
java.lang.IllegalArgumentException - if iter is null