Interface ClassInfo

All Known Implementing Classes:
ClassFile

public interface ClassInfo
ClassInfo allows a class to be accessed and modified at a very low level. ClassInfo is implemented by file.ClassFile
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    addNewField(int modifiers, int typeIndex, int nameIndex)
    Factory method that creates a new field in the class being modeled
    addNewField(int modifiers, int typeIndex, int nameIndex, int cvNameIndex, int constantValueIndex)
    Factory method that creates a new field with a constant value in the class being modeled
    addNewMethod(int modifiers, int typeIndex, int nameIndex, int exceptionIndex, int[] exceptionTypeIndices, int codeIndex)
    Adds a new method to this class.
    int
    Get the index into the constant pool of class.
    void
    Commit any changes to the file or to the virtual machine.
    void
    commitOnly(Set methods, Set fields)
    Commits only certain methods and fields.
    Returns an array of the constants in the constant pool.
    void
    deleteField(int nameIndex)
    Deletes a field from this class
    void
    deleteMethod(int nameIndex, int typeIndex)
    Deletes a method from this class
    Get an array of FieldInfo structures for each field in the class.
    int[]
    Get the indices into the constant pool of class's interfaces.
    Get the class info loader for the class.
    Returns an array of MethodInfo structures for each method in the class.
    int
    Get the modifiers of the class.
    Get the name of the class.
    void
     
    void
     
    void
    setClassIndex(int index)
    Set the index into the constant pool of class.
    void
    setConstants(Constant[] constants)
    Set all the constants in the constant pool.
    void
    setInterfaceIndices(int[] indices)
    Set the indices into the constant pool of class's interfaces.
    void
    Sets the methods in this class.
    void
    setModifiers(int modifiers)
    Set the modifiers of the class.
    void
    setSuperclassIndex(int index)
    Set the index into the constant pool of class's superclass.
    int
    Get the index into the constant pool of class's superclass.
     
  • Method Details

    • loader

      ClassInfoLoader loader()
      Get the class info loader for the class.
      Returns:
      The class info loader.
    • name

      String name()
      Get the name of the class.
      Returns:
      The name of the class.
    • classIndex

      int classIndex()
      Get the index into the constant pool of class.
      Returns:
      The index of the class.
    • superclassIndex

      int superclassIndex()
      Get the index into the constant pool of class's superclass.
      Returns:
      The index of the superclass.
    • interfaceIndices

      int[] interfaceIndices()
      Get the indices into the constant pool of class's interfaces.
      Returns:
      The indices of the interfaces.
    • setClassIndex

      void setClassIndex(int index)
      Set the index into the constant pool of class.
      Parameters:
      index - The index of the class.
    • setSuperclassIndex

      void setSuperclassIndex(int index)
      Set the index into the constant pool of class's superclass.
      Parameters:
      index - The index of the superclass.
    • setInterfaceIndices

      void setInterfaceIndices(int[] indices)
      Set the indices into the constant pool of class's interfaces.
      Parameters:
      indices - The indices of the interfaces.
    • setModifiers

      void setModifiers(int modifiers)
      Set the modifiers of the class. The values correspond to the constants in the Modifiers class.
      Parameters:
      modifiers - A bit vector of modifier flags for the class.
      See Also:
    • modifiers

      int modifiers()
      Get the modifiers of the class. The values correspond to the constants in the Modifiers class.
      Returns:
      A bit vector of modifier flags for the class.
      See Also:
    • fields

      FieldInfo[] fields()
      Get an array of FieldInfo structures for each field in the class.
      Returns:
      An array of FieldInfo structures.
      See Also:
    • methods

      MethodInfo[] methods()
      Returns an array of MethodInfo structures for each method in the class.
    • setMethods

      void setMethods(MethodInfo[] methods)
      Sets the methods in this class.
    • constants

      Constant[] constants()
      Returns an array of the constants in the constant pool.
    • setConstants

      void setConstants(Constant[] constants)
      Set all the constants in the constant pool.
      Parameters:
      constants - The array of Constants.
      See Also:
    • commit

      void commit()
      Commit any changes to the file or to the virtual machine.
    • commitOnly

      void commitOnly(Set methods, Set fields)
      Commits only certain methods and fields.
      Parameters:
      methods - Methods (MethodInfos) to commit. If null, all methods are committed.
      fields - Fields (FieldInfos) to commit. If null, all fields are committed.
    • addNewField

      FieldInfo addNewField(int modifiers, int typeIndex, int nameIndex)
      Factory method that creates a new field in the class being modeled
    • addNewField

      FieldInfo addNewField(int modifiers, int typeIndex, int nameIndex, int cvNameIndex, int constantValueIndex)
      Factory method that creates a new field with a constant value in the class being modeled
      Parameters:
      cvNameIndex - The index in the class's constant pool for the UTF8 constant "ConstantValue"
      constantValueIndex - The index in the class's constant pool for the constant value
    • deleteField

      void deleteField(int nameIndex)
      Deletes a field from this class
      Parameters:
      nameIndex - Index in the constant pool of the name of the field to be deleted
      Throws:
      IllegalArgumentException - The class modeled by this ClassInfo does not contain a field whose name is at the given index
    • deleteMethod

      void deleteMethod(int nameIndex, int typeIndex)
      Deletes a method from this class
      Parameters:
      nameIndex - Index in the constant pool of the name of the method to be deleted
      typeIndex - Index in the constant pool of the type of the method to be deleted
      Throws:
      IllegalArgumentException - The class modeled by this ClassInfo does not contain a method whose name and type are not at the given indices
    • addNewMethod

      MethodInfo addNewMethod(int modifiers, int typeIndex, int nameIndex, int exceptionIndex, int[] exceptionTypeIndices, int codeIndex)
      Adds a new method to this class.
      Parameters:
      modifiers - The modifiers for the new method
      typeIndex - The index of the type (conglomeration of the parameter types and the return type) for this method in the class's constant pool
      nameIndex - The index of the name of the method in the class's constant pool
      exceptionIndex - The index of the UTF8 string "Exceptions" in the class's constant pool
      exceptionTypeIndices - The indices in the class's constant pool of the type of the exceptions thrown by this method
      codeIndex - The index of the UTF8 string "Code" in the class's constant pool
    • print

      void print(PrintStream out)
    • print

      void print(PrintWriter out)
    • toString

      String toString()
      Overrides:
      toString in class Object