Class ClassReaderImpl

java.lang.Object
org.glavo.classfile.impl.ClassReaderImpl
All Implemented Interfaces:
Iterable<PoolEntry>, ClassReader, ConstantPool

public final class ClassReaderImpl extends Object implements ClassReader
  • Method Details

    • context

      public ClassFileImpl context()
    • customAttributes

      public Function<Utf8Entry,AttributeMapper<?>> customAttributes()
      Description copied from interface: ClassReader
      Returns the table of custom attribute mappers. This is derived from the processing option ClassFile.AttributeMapperOption.
      Specified by:
      customAttributes in interface ClassReader
      Returns:
      the table of custom attribute mappers
    • size

      public int size()
      Description copied from interface: ConstantPool
      Returns the size of the constant pool.
      Specified by:
      size in interface ConstantPool
      Returns:
      the size of the constant pool
    • flags

      public int flags()
      Description copied from interface: ClassReader
      Returns the access flags for the class, as a bit mask .
      Specified by:
      flags in interface ClassReader
      Returns:
      the access flags for the class, as a bit mask
    • thisClassEntry

      public ClassEntry thisClassEntry()
      Description copied from interface: ClassReader
      Returns the constant pool entry describing the name of class.
      Specified by:
      thisClassEntry in interface ClassReader
      Returns:
      the constant pool entry describing the name of class
    • superclassEntry

      public Optional<ClassEntry> superclassEntry()
      Description copied from interface: ClassReader
      Returns the constant pool entry describing the name of the superclass, if any.
      Specified by:
      superclassEntry in interface ClassReader
      Returns:
      the constant pool entry describing the name of the superclass, if any
    • thisClassPos

      public int thisClassPos()
      Description copied from interface: ClassReader
      Returns the offset into the classfile of the this_class field.
      Specified by:
      thisClassPos in interface ClassReader
      Returns:
      the offset into the classfile of the this_class field
    • classfileLength

      public int classfileLength()
      Description copied from interface: ClassReader
      Returns the length of the classfile, in bytes.
      Specified by:
      classfileLength in interface ClassReader
      Returns:
      the length of the classfile, in bytes
    • bootstrapMethodCount

      public int bootstrapMethodCount()
      Description copied from interface: ConstantPool
      Returns the number of entries in the bootstrap method table.
      Specified by:
      bootstrapMethodCount in interface ConstantPool
      Returns:
      the number of entries in the bootstrap method table
    • bootstrapMethodEntry

      public BootstrapMethodEntryImpl bootstrapMethodEntry(int index)
      Description copied from interface: ConstantPool
      Returns the BootstrapMethodEntry at the specified index within the bootstrap method table.
      Specified by:
      bootstrapMethodEntry in interface ConstantPool
      Parameters:
      index - the index within the bootstrap method table of the desired entry
      Returns:
      the BootstrapMethodEntry at the specified index within the bootstrap method table
    • readU1

      public int readU1(int p)
      Description copied from interface: ClassReader
      Returns the unsigned byte at the specified offset within the classfile.
      Specified by:
      readU1 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the unsigned byte at the specified offset within the classfile
    • readU2

      public int readU2(int p)
      Description copied from interface: ClassReader
      Returns the unsigned short at the specified offset within the classfile.
      Specified by:
      readU2 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the unsigned short at the specified offset within the classfile
    • readS1

      public int readS1(int p)
      Description copied from interface: ClassReader
      Returns the signed byte at the specified offset within the classfile.
      Specified by:
      readS1 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed byte at the specified offset within the classfile
    • readS2

      public int readS2(int p)
      Description copied from interface: ClassReader
      Returns the signed byte at the specified offset within the classfile.
      Specified by:
      readS2 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed byte at the specified offset within the classfile
    • readInt

      public int readInt(int p)
      Description copied from interface: ClassReader
      Returns the signed int at the specified offset within the classfile.
      Specified by:
      readInt in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed int at the specified offset within the classfile
    • readLong

      public long readLong(int p)
      Description copied from interface: ClassReader
      Returns the signed long at the specified offset within the classfile.
      Specified by:
      readLong in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed long at the specified offset within the classfile
    • readFloat

      public float readFloat(int p)
      Description copied from interface: ClassReader
      Returns the float value at the specified offset within the classfile.
      Specified by:
      readFloat in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the float value at the specified offset within the classfile
    • readDouble

      public double readDouble(int p)
      Description copied from interface: ClassReader
      Returns the double value at the specified offset within the classfile.
      Specified by:
      readDouble in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the double value at the specified offset within the classfile
    • readBytes

      public byte[] readBytes(int p, int len)
      Description copied from interface: ClassReader
      Returns a copy of the bytes at the specified range in the classfile.
      Specified by:
      readBytes in interface ClassReader
      Parameters:
      p - the offset within the classfile
      len - the length of the range
      Returns:
      a copy of the bytes at the specified range in the classfile
    • copyBytesTo

      public void copyBytesTo(BufWriter buf, int p, int len)
      Description copied from interface: ClassReader
      Copy a range of bytes from the classfile to a BufWriter
      Specified by:
      copyBytesTo in interface ClassReader
      Parameters:
      buf - the BufWriter
      p - the offset within the classfile
      len - the length of the range
    • entryByIndex

      public PoolEntry entryByIndex(int index)
      Description copied from interface: ConstantPool
      Returns the entry at the specified index.
      Specified by:
      entryByIndex in interface ConstantPool
      Parameters:
      index - the index within the pool of the desired entry
      Returns:
      the entry at the specified index
    • utf8EntryByIndex

      public AbstractPoolEntry.Utf8EntryImpl utf8EntryByIndex(int index)
      Description copied from interface: ClassReader
      Returns the UTF8 constant pool entry at the given index of the constant pool. The given index must correspond to a valid constant pool index whose slot holds a UTF8 constant.
      Specified by:
      utf8EntryByIndex in interface ClassReader
      Parameters:
      index - the index into the constant pool
      Returns:
      the UTF8 constant pool entry at the given index of the constant pool
    • skipAttributeHolder

      public int skipAttributeHolder(int offset)
      Description copied from interface: ClassReader
      Returns the offset following the block of attributes starting at the specified position.
      Specified by:
      skipAttributeHolder in interface ClassReader
      Parameters:
      offset - the offset into the classfile at which the attribute block starts
      Returns:
      the offset following the block of attributes starting at the specified position
    • readEntry

      public PoolEntry readEntry(int pos)
      Description copied from interface: ClassReader
      Returns the constant pool entry whose index is given at the specified offset within the classfile.
      Specified by:
      readEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the constant pool entry whose index is given at the specified offset within the classfile
    • readEntry

      public <T extends PoolEntry> T readEntry(int pos, Class<T> cls)
      Description copied from interface: ClassReader
      Returns the constant pool entry of a given type whose index is given at the specified offset within the classfile.
      Specified by:
      readEntry in interface ClassReader
      Type Parameters:
      T - the entry type
      Parameters:
      pos - the offset of the index within the classfile
      cls - the entry type
      Returns:
      the constant pool entry of a given type whose index is given at the specified offset within the classfile
    • readEntryOrNull

      public PoolEntry readEntryOrNull(int pos)
      Description copied from interface: ClassReader
      Returns the constant pool entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero.
      Specified by:
      readEntryOrNull in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the constant pool entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero
    • readUtf8Entry

      public Utf8Entry readUtf8Entry(int pos)
      Description copied from interface: ClassReader
      Returns the UTF8 entry whose index is given at the specified offset within the classfile.
      Specified by:
      readUtf8Entry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the UTF8 entry whose index is given at the specified offset within the classfile
    • readUtf8EntryOrNull

      public Utf8Entry readUtf8EntryOrNull(int pos)
      Description copied from interface: ClassReader
      Returns the UTF8 entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero.
      Specified by:
      readUtf8EntryOrNull in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the UTF8 entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero
    • readModuleEntry

      public ModuleEntry readModuleEntry(int pos)
      Description copied from interface: ClassReader
      Returns the module entry whose index is given at the specified offset within the classfile.
      Specified by:
      readModuleEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the module entry whose index is given at the specified offset within the classfile
    • readPackageEntry

      public PackageEntry readPackageEntry(int pos)
      Description copied from interface: ClassReader
      Returns the package entry whose index is given at the specified offset within the classfile.
      Specified by:
      readPackageEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the package entry whose index is given at the specified offset within the classfile
    • readClassEntry

      public ClassEntry readClassEntry(int pos)
      Description copied from interface: ClassReader
      Returns the class entry whose index is given at the specified offset within the classfile.
      Specified by:
      readClassEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the class entry whose index is given at the specified offset within the classfile
    • readNameAndTypeEntry

      public NameAndTypeEntry readNameAndTypeEntry(int pos)
      Description copied from interface: ClassReader
      Returns the name-and-type entry whose index is given at the specified offset within the classfile.
      Specified by:
      readNameAndTypeEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the name-and-type entry whose index is given at the specified offset within the classfile
    • readMethodHandleEntry

      public MethodHandleEntry readMethodHandleEntry(int pos)
      Description copied from interface: ClassReader
      Returns the method handle entry whose index is given at the specified offset within the classfile.
      Specified by:
      readMethodHandleEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the method handle entry whose index is given at the specified offset within the classfile
    • compare

      public boolean compare(BufWriter bufWriter, int bufWriterOffset, int classReaderOffset, int length)
      Description copied from interface: ClassReader
      Compare a range of bytes from the classfile to a range of bytes within a BufWriter.
      Specified by:
      compare in interface ClassReader
      Parameters:
      bufWriter - the BufWriter
      bufWriterOffset - the offset within the BufWriter
      classReaderOffset - the offset within the classfile
      length - the length of the range
      Returns:
      whether the two ranges were identical