Interface ClassModel

All Superinterfaces:
AttributedElement, ClassfileElement, CompoundElement<ClassElement>, Iterable<ClassElement>
All Known Implementing Classes:
ClassImpl

public sealed interface ClassModel extends CompoundElement<ClassElement>, AttributedElement permits ClassImpl
Models a classfile. The contents of the classfile can be traversed via a streaming view (e.g., CompoundElement.elements()), or via random access (e.g., flags()), or by freely mixing the two.
  • Method Details

    • constantPool

      ConstantPool constantPool()
      Returns the constant pool for this class.
      Returns:
      the constant pool for this class
    • flags

      AccessFlags flags()
      Returns the access flags.
      Returns:
      the access flags
    • thisClass

      ClassEntry thisClass()
      Returns the constant pool entry describing the name of this class.
      Returns:
      the constant pool entry describing the name of this class
    • majorVersion

      int majorVersion()
      Returns the major classfile version.
      Returns:
      the major classfile version
    • minorVersion

      int minorVersion()
      Returns the minor classfile version.
      Returns:
      the minor classfile version
    • fields

      List<FieldModel> fields()
      Returns the fields of this class.
      Returns:
      the fields of this class
    • methods

      List<MethodModel> methods()
      Returns the methods of this class.
      Returns:
      the methods of this class
    • superclass

      Optional<ClassEntry> superclass()
      Returns the superclass of this class, if there is one.
      Returns:
      the superclass of this class, if there is one
    • interfaces

      List<ClassEntry> interfaces()
      Returns the interfaces implemented by this class.
      Returns:
      the interfaces implemented by this class
    • transform

      byte[] transform(ClassTransform transform)
      Transform this classfile into a new classfile with the aid of a ClassTransform. The transform will receive each element of this class, as well as a ClassBuilder for building the new class. The transform is free to preserve, remove, or replace elements as it sees fit.
      Parameters:
      transform - the transform
      Returns:
      the bytes of the new class
      ImplNote:

      This method behaves as if:

          Classfile.build(thisClass(), ConstantPoolBuilder.of(this),
                          b -> b.transform(this, transform));
      
    • isModuleInfo

      boolean isModuleInfo()
      Returns whether this class is a module descriptor.
      Returns:
      whether this class is a module descriptor
    • verify

      default List<VerifyError> verify(Consumer<String> debugOutput)
      Verify this classfile. Any verification errors found will be returned.
      Parameters:
      debugOutput - handler to receive debug information
      Returns:
      a list of verification errors, or an empty list if no errors are found
    • verify

      default List<VerifyError> verify(ClassHierarchyResolver classHierarchyResolver, Consumer<String> debugOutput)
      Verify this classfile. Any verification errors found will be returned.
      Parameters:
      classHierarchyResolver - class hierarchy resolver to provide additional information about the class hiearchy
      debugOutput - handler to receive debug information
      Returns:
      a list of verification errors, or an empty list if no errors are found