- 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 Summary
Modifier and TypeMethodDescriptionReturns the constant pool for this class.fields()Returns the fields of this class.flags()Returns the access flags.Returns the interfaces implemented by this class.booleanReturns whether this class is a module descriptor.intReturns the major classfile version.methods()Returns the methods of this class.intReturns the minor classfile version.Returns the superclass of this class, if there is one.Returns the constant pool entry describing the name of this class.byte[]transform(ClassTransform transform) Transform this classfile into a new classfile with the aid of aClassTransform.default List<VerifyError>Verify this classfile.default List<VerifyError>verify(ClassHierarchyResolver classHierarchyResolver, Consumer<String> debugOutput) Verify this classfile.Methods inherited from interface org.glavo.classfile.AttributedElement
attributes, findAttribute, findAttributesMethods inherited from interface org.glavo.classfile.CompoundElement
elementList, elements, elementStream, forEachElement, iteratorMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
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
Transform this classfile into a new classfile with the aid of aClassTransform. The transform will receive each element of this class, as well as aClassBuilderfor 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
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 hiearchydebugOutput- handler to receive debug information- Returns:
- a list of verification errors, or an empty list if no errors are found
-