Overview | Package | Class | Tree | Deprecated | Index | Help
| ej-technologies
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.gjt.jclasslib.structures
Class ClassFile

    java.lang.Object
      org.gjt.jclasslib.structures.AbstractStructure
          org.gjt.jclasslib.structures.AbstractStructureWithAttributes
              org.gjt.jclasslib.structures.ClassFile

public class ClassFile
extends AbstractStructureWithAttributes

The class file structure in which all other structures are hooked up.

Version:
  $Revision: 1.10 $ $Date: 2004/12/28 13:04:32 $
Author:
  Ingo Kegel, Vitor Carreira

Field Summary
`static String` | `SYSTEM_PROPERTY_SKIP_CONSTANT_POOL` Set this JVM System property to true to skip reading of constant pool entries.

Fields inherited from class org.gjt.jclasslib.structures.AbstractStructureWithAttributes
`attributes`

Fields inherited from class org.gjt.jclasslib.structures.AbstractStructure
`classFile, debug, SYSTEM_PROPERTY_DEBUG`

Constructor Summary
`ClassFile()` Constructor.

Method Summary
`void` | `enlargeConstantPool(CPInfo[] enlargedConstantPool)` Set the array with all constant pool entries where the new array of constant pool entries starts with the old constant pool.
`int` | `getAccessFlags()` Get the access flags of this class.
`String` | `getAccessFlagsVerbose()` Get the verbose description of the access flags of this class.
`CPInfo[]` | `getConstantPool()` Get the array with all constant pool entries.
`CPInfo` | `getConstantPoolEntry(int index, Class entryClass)` Get the constant pool entry at the specified index and cast it to a specified class.
`String` | `getConstantPoolEntryName(int index)` Get an approximate verbose description of the content of the constant pool entry at the specified index.
`int` | `getConstantPoolIndex(CPInfo cpInfo)` Get the index of an equivalent constant pool entry.
`ConstantUtf8Info` | `getConstantPoolUtf8Entry(int index)` Get the `ConstantUtf8Info` constant pool entry at the specified index.
`FieldInfo` | `getField(String name, String descriptor)` Get the `FieldInfo` for given field name and signature.
`int` | `getFieldIndex(String name, String descriptor)` Get the index of a field for given field name and signature.
`FieldInfo[]` | `getFields()` Get the array with the `FieldInfo` structures for the fields of this class.
`String` | `getFormattedAccessFlags()` Get the the access flags of this class as a hex string.
`int[]` | `getInterfaces()` Get the array with the constant pool entries of all interfaces.
`int` | `getMajorVersion()` Get the major version of the class file format.
`MethodInfo` | `getMethod(String name, String descriptor)` Get the `MethodInfo` for given method name and signature.
`int` | `getMethodIndex(String name, String descriptor)` Get the index of a method for given method name and signature.
`MethodInfo[]` | `getMethods()` Get the array with the `MethodInfo` structures for the methods of this class.
`int` | `getMinorVersion()` Get the minor version of the class file format.
`int` | `getSuperClass()` Get the constant pool index of the super class of this class.
`String` | `getSuperClassName()` Get the name of the super class.
`int` | `getThisClass()` Get the constant pool index of this class.
`String` | `getThisClassName()` Get the name of this class.
`protected String` | `printAccessFlagsVerbose(int accessFlags)` Utility method for derived structures.
`void` | `read(DataInput in)` Read this structure from the given `DataInput`.
`protected void` | `readAttributes(DataInput in)` Read the attributes of this structure from the given `DataInput`.
`void` | `registerConstantPoolEntry(int index)` Register the constant pool entry at a given index, so that it can be found through the `getConstantPoolIndex` method.
`void` | `setAccessFlags(int accessFlags)` Set the access flags of this class.
`void` | `setConstantPool(CPInfo[] constantPool)` Set the array with all constant pool entries.
`void` | `setFields(FieldInfo[] fields)` Set the array with the `FieldInfo` structures for the fields of this class.
`void` | `setInterfaces(int[] interfaces)` Set the array with the constant pool entries of all interfaces.
`void` | `setMajorVersion(int majorVersion)` Set the major version of the class file format.
`void` | `setMethods(MethodInfo[] methods)` Set the array with the `MethodInfo` structures for the methods of this class.
`void` | `setMinorVersion(int minorVersion)` Set the minor version of the class file format.
`void` | `setSuperClass(int superClass)` Set the constant pool index of the super class of this class.
`void` | `setThisClass(int thisClass)` Set the constant pool index of this class.
`void` | `unregisterConstantPoolEntry(int index)` Unregister the constant pool entry at a given index, so that it can no longer be found through the `getConstantPoolIndex` method.
`void` | `write(DataOutput in)` Write this structure to the given `DataOutput`.
`protected void` | `writeAttributes(DataOutput out)` Write the attributes of this structure to the given `DataOutput`.

Methods inherited from class org.gjt.jclasslib.structures.AbstractStructureWithAttributes
`findAttribute, getAttributes, getTotalAttributesLength, setAttributes`

Methods inherited from class org.gjt.jclasslib.structures.AbstractStructure
`debug, getClassFile, getDebug, getLength, printAccessFlags, printAccessFlagsVerbose, printBytes, setClassFile, setDebug`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SYSTEM_PROPERTY_SKIP_CONSTANT_POOL

    public static final String SYSTEM_PROPERTY_SKIP_CONSTANT_POOL

  Set this JVM System property to true to skip reading of constant pool entries. This is not advisable, since most sunsequent operations on the class file structure will fail.

  See Also:
    Constant Field Values

Constructor Detail

### ClassFile

    public ClassFile()

  Constructor.

Method Detail

### getMinorVersion

    public int getMinorVersion()

  Get the minor version of the class file format.

  Returns:
    the minor version

### setMinorVersion

    public void setMinorVersion(int minorVersion)

  Set the minor version of the class file format.

  Parameters:
    `minorVersion` - the minor version

### getMajorVersion

    public int getMajorVersion()

  Get the major version of the class file format.

  Returns:
    the major version

### setMajorVersion

    public void setMajorVersion(int majorVersion)

  Set the major version of the class file format.

  Parameters:
    `majorVersion` - the major version

### getConstantPool

    public CPInfo[] getConstantPool()

  Get the array with all constant pool entries.

  Returns:
    the array

### getConstantPoolIndex

    public int getConstantPoolIndex(CPInfo cpInfo)

  Get the index of an equivalent constant pool entry.

  Parameters:
    `cpInfo` - the constant pool entry
  Returns:
    the index, -1 if no equivalent constant pool entry can be found

### setConstantPool

    public void setConstantPool(CPInfo[] constantPool)

  Set the array with all constant pool entries. An internal hash map will need to be recalulated. If you add to the end of the constant pool, use `enlargeConstantPool`.

  Parameters:
    `constantPool` - the array

### enlargeConstantPool

    public void enlargeConstantPool(CPInfo[] enlargedConstantPool)

  Set the array with all constant pool entries where the new array of constant pool entries starts with the old constant pool. If you delete entries, use `setConstantPool`.

  Parameters:
    `enlargedConstantPool` - the array

### registerConstantPoolEntry

    public void registerConstantPoolEntry(int index)

  Register the constant pool entry at a given index, so that it can be found through the `getConstantPoolIndex` method.

  Parameters:
    `index` - the index

### unregisterConstantPoolEntry

    public void unregisterConstantPoolEntry(int index)

  Unregister the constant pool entry at a given index, so that it can no longer be found through the `getConstantPoolIndex` method.

  Parameters:
    `index` - the index

### getAccessFlags

    public int getAccessFlags()

  Get the access flags of this class.

  Returns:
    the access flags

### setAccessFlags

    public void setAccessFlags(int accessFlags)

  Set the access flags of this class.

  Parameters:
    `accessFlags` - the access flags

### getThisClass

    public int getThisClass()

  Get the constant pool index of this class.

  Returns:
    the index

### setThisClass

    public void setThisClass(int thisClass)

  Set the constant pool index of this class.

  Parameters:
    `thisClass` - the index

### getThisClassName

    public String getThisClassName()
                            throws InvalidByteCodeException

  Get the name of this class.

  Returns:
    the name
  Throws:
    `InvalidByteCodeException`

### getSuperClass

    public int getSuperClass()

  Get the constant pool index of the super class of this class.

  Returns:
    the index

### setSuperClass

    public void setSuperClass(int superClass)

  Set the constant pool index of the super class of this class.

  Parameters:
    `superClass` - the index

### getSuperClassName

    public String getSuperClassName()
                             throws InvalidByteCodeException

  Get the name of the super class.

  Returns:
    the name
  Throws:
    `InvalidByteCodeException`

### getInterfaces

    public int[] getInterfaces()

  Get the array with the constant pool entries of all interfaces.

  Returns:
    the array

### setInterfaces

    public void setInterfaces(int[] interfaces)

  Set the array with the constant pool entries of all interfaces.

  Parameters:
    `interfaces` - the array

### getFields

    public FieldInfo[] getFields()

  Get the array with the `FieldInfo` structures for the fields of this class.

  Returns:
    the array

### setFields

    public void setFields(FieldInfo[] fields)

  Set the array with the `FieldInfo` structures for the fields of this class.

  Parameters:
    `fields` - the array

### getMethods

    public MethodInfo[] getMethods()

  Get the array with the `MethodInfo` structures for the methods of this class.

  Returns:
    the array

### setMethods

    public void setMethods(MethodInfo[] methods)

  Set the array with the `MethodInfo` structures for the methods of this class.

  Parameters:
    `methods` - the array

### getFormattedAccessFlags

    public String getFormattedAccessFlags()

  Get the the access flags of this class as a hex string.

  Returns:
    the hex string

### getAccessFlagsVerbose

    public String getAccessFlagsVerbose()

  Get the verbose description of the access flags of this class.

  Returns:
    the description

### getConstantPoolUtf8Entry

    public ConstantUtf8Info getConstantPoolUtf8Entry(int index)
                                              throws InvalidByteCodeException

  Get the `ConstantUtf8Info` constant pool entry at the specified index.

  Parameters:
    `index` - the index
  Returns:
    the constant pool entry
  Throws:
    `InvalidByteCodeException` - if the entry is not a `ConstantUtf8Info`

### getConstantPoolEntry

    public CPInfo getConstantPoolEntry(int index,
                                       Class entryClass)
                                throws InvalidByteCodeException

  Get the constant pool entry at the specified index and cast it to a specified class.

  Parameters:
    `index` - the index
    `entryClass` - the required subtype of `CPInfo`
  Returns:
    the constant pool entry
  Throws:
    `InvalidByteCodeException` - if the entry is of a different class than expected

### getConstantPoolEntryName

    public String getConstantPoolEntryName(int index)
                                    throws InvalidByteCodeException

  Get an approximate verbose description of the content of the constant pool entry at the specified index.

  Parameters:
    `index` - the index
  Returns:
    the description
  Throws:
    `InvalidByteCodeException` - if the entry is invalid

### getFieldIndex

    public int getFieldIndex(String name,
                             String descriptor)
                      throws InvalidByteCodeException

  Get the index of a field for given field name and signature.

  Parameters:
    `name` - the field name.
    `descriptor` - the signature.
  Returns:
    the index or `-1` if not found.
  Throws:
    `InvalidByteCodeException`

### getField

    public FieldInfo getField(String name,
                              String descriptor)
                       throws InvalidByteCodeException

  Get the `FieldInfo` for given field name and signature.

  Parameters:
    `name` - the field name.
    `descriptor` - the signature.
  Returns:
    the `FieldInfo` or `null` if not found.
  Throws:
    `InvalidByteCodeException`

### getMethodIndex

    public int getMethodIndex(String name,
                              String descriptor)
                       throws InvalidByteCodeException

  Get the index of a method for given method name and signature.

  Parameters:
    `name` - the method name.
    `descriptor` - the signature.
  Returns:
    the index or `-1` if not found.
  Throws:
    `InvalidByteCodeException`

### getMethod

    public MethodInfo getMethod(String name,
                                String descriptor)
                         throws InvalidByteCodeException

  Get the `MethodInfo` for given method name and signature.

  Parameters:
    `name` - the method name.
    `descriptor` - the signature.
  Returns:
    the `MethodInfo` or `null` if not found.
  Throws:
    `InvalidByteCodeException`

### read

    public void read(DataInput in)
              throws InvalidByteCodeException,
                     IOException

  Description copied from class: `AbstractStructure`
  Read this structure from the given `DataInput`.

  Excpects `DataInput` to be in JVM class file format and just before a structure of this kind. No look ahead parsing since the class file format is deterministic.

  Overrides:
    `read` in class `AbstractStructure`
  Parameters:
    `in` - the `DataInput` from which to read
  Throws:
    `IOException` - if an exception occurs with the `DataInput`
    `InvalidByteCodeException` - if the byte code is invalid

### write

    public void write(DataOutput in)
               throws InvalidByteCodeException,
                      IOException

  Description copied from class: `AbstractStructure`
  Write this structure to the given `DataOutput`.

  The written bytes are in JVM class file format.

  Overrides:
    `write` in class `AbstractStructure`
  Parameters:
    `in` - the `DataOutput` to which to write
  Throws:
    `IOException` - if an exception occurs with the `DataOutput`
    `InvalidByteCodeException` - if the structure is internally inconsistent

### readAttributes

    protected void readAttributes(DataInput in)
                           throws InvalidByteCodeException,
                                  IOException

  Description copied from class: `AbstractStructureWithAttributes`
  Read the attributes of this structure from the given `DataInput`.

  Excpects `DataInput` to be in JVM class file format and just before an attribute length field.

  Overrides:
    `readAttributes` in class `AbstractStructureWithAttributes`
  Parameters:
    `in` - the `DataInput` from which to read
  Throws:
    `IOException` - if an exception occurs with the `DataInput`
    `InvalidByteCodeException` - if the byte code is invalid

### writeAttributes

    protected void writeAttributes(DataOutput out)
                            throws InvalidByteCodeException,
                                   IOException

  Description copied from class: `AbstractStructureWithAttributes`
  Write the attributes of this structure to the given `DataOutput`.

  The written bytes are in JVM class file format.

  Overrides:
    `writeAttributes` in class `AbstractStructureWithAttributes`
  Parameters:
    `out` - the `DataOutput` to which to write
  Throws:
    `IOException` - if an exception occurs with the `DataOutput`
    `InvalidByteCodeException` - if the structure is internally inconsistent

### printAccessFlagsVerbose

    protected String printAccessFlagsVerbose(int accessFlags)

  Description copied from class: `AbstractStructure`
  Utility method for derived structures. Print an access flag as a space separated list of verbose java access modifiers.

  Specified by:
    `printAccessFlagsVerbose` in class `AbstractStructure`
  Parameters:
    `accessFlags` - the unsigned short value to print as a hex string
  Returns:
    the hex string

Overview | Package | Class | Tree | Deprecated | Index | Help
| ej-technologies
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD