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:
    ClassFile
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      FieldInfo addNewField​(int modifiers, int typeIndex, int nameIndex)
      Factory method that creates a new field in the class being modeled
      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
      MethodInfo addNewMethod​(int modifiers, int typeIndex, int nameIndex, int exceptionIndex, int[] exceptionTypeIndices, int codeIndex)
      Adds a new method to this class.
      int classIndex()
      Get the index into the constant pool of class.
      void commit()
      Commit any changes to the file or to the virtual machine.
      void commitOnly​(java.util.Set methods, java.util.Set fields)
      Commits only certain methods and fields.
      Constant[] constants()
      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
      FieldInfo[] fields()
      Get an array of FieldInfo structures for each field in the class.
      int[] interfaceIndices()
      Get the indices into the constant pool of class's interfaces.
      ClassInfoLoader loader()
      Get the class info loader for the class.
      MethodInfo[] methods()
      Returns an array of MethodInfo structures for each method in the class.
      int modifiers()
      Get the modifiers of the class.
      java.lang.String name()
      Get the name of the class.
      void print​(java.io.PrintStream out)  
      void print​(java.io.PrintWriter out)  
      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 setMethods​(MethodInfo[] methods)
      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 superclassIndex()
      Get the index into the constant pool of class's superclass.
      java.lang.String toString()  
    • Method Detail

      • loader

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

        java.lang.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
      • 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:
        Modifiers
      • fields

        FieldInfo[] fields()
        Get an array of FieldInfo structures for each field in the class.
        Returns:
        An array of FieldInfo structures.
        See Also:
        FieldInfo
      • 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:
        Constant
      • commit

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

        void commitOnly​(java.util.Set methods,
                        java.util.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:
        java.lang.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:
        java.lang.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​(java.io.PrintStream out)
      • print

        void print​(java.io.PrintWriter out)
      • toString

        java.lang.String toString()
        Overrides:
        toString in class java.lang.Object