Class ClassFile

java.lang.Object
de.inetsoftware.classparser.ClassFile

public class ClassFile extends 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 Details

    • minorVersion

      private final int minorVersion
    • majorVersion

      private final int majorVersion
    • constantPool

      private final ConstantPool constantPool
    • accessFlags

      private final int accessFlags
    • thisClass

      private final ConstantClass thisClass
    • superClass

      private final ConstantClass superClass
    • interfaces

      private final ConstantClass[] interfaces
    • fields

      private FieldInfo[] fields
    • methods

      private MethodInfo[] methods
    • attributes

      private final Attributes attributes
    • thisSignature

      private String thisSignature
    • superSignature

      private String superSignature
    • annotations

      private Map<String,Map<String,Object>> annotations
    • bootstrapMethods

      private BootstrapMethod[] bootstrapMethods
  • Constructor Details

    • ClassFile

      public ClassFile(InputStream stream) throws 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:
      IOException - if this input stream reaches the end before reading the class file.
    • ClassFile

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

    • patchConstantPool

      private void patchConstantPool(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 String getSourceFile() throws IOException
      Get value of SourceFile if available.
      Returns:
      the source file name or null.
      Throws:
      IOException - if an I/O error occurs.
    • getAnnotation

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

      public BootstrapMethod getBootstrapMethod(int methodIdx) throws 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:
      IOException - if any error occur
    • getConstantPool

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

      public ConstantClass getThisClass()
    • getSuperClass

      public ConstantClass getSuperClass()
    • getInterfaces

      public ConstantClass[] getInterfaces()
    • getMethods

      public MethodInfo[] getMethods()
    • getMethod

      public MethodInfo getMethod(String name, 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(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:
    • 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(DataInputStream input) throws IOException
      Throws:
      IOException
    • readMethods

      private MethodInfo[] readMethods(DataInputStream input) throws IOException
      Throws:
      IOException
    • getThisSignature

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

      public 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 IOException
      Extends this class with the methods and fields of the partial class.
      Parameters:
      partialClassFile - extension of the class
      Throws:
      IOException - If any I/O error occur