Class ClassFile


  • public class ClassFile
    extends java.lang.Object
    http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html
    • Field Detail

      • minorVersion

        private final int minorVersion
      • majorVersion

        private final int majorVersion
      • accessFlags

        private final int accessFlags
      • thisSignature

        private java.lang.String thisSignature
      • superSignature

        private java.lang.String superSignature
      • annotations

        private java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.Object>> annotations
    • Constructor Detail

      • ClassFile

        public ClassFile​(java.io.InputStream stream)
                  throws java.io.IOException
        Load a class file and create a model of the class.
        Parameters:
        stream - The InputStream of the class file. Will be closed if finish.
        Throws:
        java.io.IOException - if this input stream reaches the end before reading the class file.
      • ClassFile

        public ClassFile​(java.lang.String className,
                         ClassFile classFile)
        Create a replaced instance.
        Parameters:
        className - the class name that should be replaced
        classFile - the replacing class file data
    • Method Detail

      • patchConstantPool

        private void patchConstantPool​(java.lang.String origClassName,
                                       ConstantClass thisClass)
        Replace the reference to the Class in the the constant pool.
        Parameters:
        origClassName - the class name that should be replaced.
        thisClass - the reference of the class that should be used.
      • getSourceFile

        public java.lang.String getSourceFile()
                                       throws java.io.IOException
        Get value of SourceFile if available.
        Returns:
        the source file name or null.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getAnnotation

        @Nullable
        public java.util.Map<java.lang.String,​java.lang.Object> getAnnotation​(java.lang.String annotation)
                                                                             throws java.io.IOException
        Get a single annotation or null
        Parameters:
        annotation - the class name of the annotation
        Returns:
        the value or null if not exists
        Throws:
        java.io.IOException - if any I/O error occur
      • getBootstrapMethod

        public BootstrapMethod getBootstrapMethod​(int methodIdx)
                                           throws java.io.IOException
        Get the x-the BootstrapMethod. Bootstrap methods are used for creating an lambda object.
        Parameters:
        methodIdx - the index of the method
        Returns:
        the method
        Throws:
        java.io.IOException - if any error occur
      • getConstantPool

        public ConstantPool getConstantPool()
        Get the constant pool of the the current class.
        Returns:
        the constant pool
      • getMethod

        public MethodInfo getMethod​(java.lang.String name,
                                    java.lang.String signature)
        Find a method via name and signature.
        Parameters:
        name - the name
        signature - the signature
        Returns:
        the method or null if not found
      • getField

        public FieldInfo getField​(java.lang.String name)
      • getFields

        public FieldInfo[] getFields()
        Get the fields of the class.
        Returns:
        the fields
      • getAccessFlags

        public int getAccessFlags()
        The access flags of the class. http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-E http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#23242
        Returns:
        the flag
        See Also:
        Class.isInterface()
      • isAbstract

        public boolean isAbstract()
        If the class is abstract
        Returns:
        true, if abstract class
      • isEnum

        public boolean isEnum()
        If the class is an Enum
        Returns:
        true, if Enum class
      • readFields

        private FieldInfo[] readFields​(java.io.DataInputStream input)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readMethods

        private MethodInfo[] readMethods​(java.io.DataInputStream input)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getThisSignature

        public java.lang.String getThisSignature()
        Get the signature of the class with generic types.
        Returns:
        the signature
      • getSuperSignature

        public java.lang.String getSuperSignature()
        Get the signature of the super class with generic types.
        Returns:
        the signature
      • getType

        public ClassFile.Type getType()
        Get the type of class.
        Returns:
        the type of the class
      • partial

        public void partial​(ClassFile partialClassFile)
                     throws java.io.IOException
        Extends this class with the methods and fields of the partial class.
        Parameters:
        partialClassFile - extension of the class
        Throws:
        java.io.IOException - If any I/O error occur