Class ClassFileReader
Parses the constant pool (all tags defined up to Java 25), the name, superclass and interfaces of the class, the
access flags, names and descriptors of its fields and methods, and the BootstrapMethods and
SourceFile attributes. The bytecode of the methods (Code attributes) is scanned only as far as needed to
determine the source lines (from the LineNumberTable attributes) where the constant pool entries are
used; see getLineNumbers(MemberReference). All other attributes are skipped.
Class names are reported in the format of Class.getName(), i.e. with dots as package separators (e.g.
"java.lang.String", "[Ljava.lang.String;"); field and method descriptors are reported verbatim
(e.g. "(Ljava/lang/String;)V").
Invalid or truncated class files cause a ClassFormatError.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn entry of theBootstrapMethodsattribute.static final classACONSTANT_DynamicorCONSTANT_InvokeDynamicentry of the constant pool.static final classA field or method declared by the class.static final classACONSTANT_Fieldref,CONSTANT_MethodreforCONSTANT_InterfaceMethodrefentry of the constant pool.static final classACONSTANT_MethodHandleentry of the constant pool. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetBootstrapMethod(ClassFileReader.DynamicReference dynamicReference) getLineNumbers(ClassFileReader.DynamicReference dynamicReference) getLineNumbers(ClassFileReader.MemberReference memberReference) Returns the source lines of the instructions that use the given memberReference, i.e. of the field access and method invocation instructions that refer to it, and of the instructions that use a method handle of it, either directly (ldc), or as the bootstrap method or a bootstrap argument of aninvokedynamicinstruction or a dynamically-computed constant (e.g. a method reference likeRuntime::getRuntime).intint
-
Constructor Details
-
ClassFileReader
public ClassFileReader(byte[] classFile) Parses the given class file.- Throws:
ClassFormatError- The classFile is invalid or truncated
-
-
Method Details
-
getMajorVersion
public int getMajorVersion() -
getMinorVersion
public int getMinorVersion() -
getAccessFlags
public int getAccessFlags()- Returns:
- The access flags of the class, e.g.
Modifier.INTERFACE
-
getClassName
- Returns:
- The name of the class, e.g.
"pkg.Outer$Inner"
-
getSuperclassName
-
getInterfaceNames
-
getFields
-
getMethods
-
getClassReferences
-
getMemberReferences
- Returns:
- All
CONSTANT_Fieldref,CONSTANT_MethodrefandCONSTANT_InterfaceMethodrefentries of the constant pool
-
getMethodHandles
- Returns:
- All
CONSTANT_MethodHandleentries of the constant pool
-
getDynamicReferences
- Returns:
- All
CONSTANT_DynamicandCONSTANT_InvokeDynamicentries of the constant pool
-
getBootstrapMethods
- Returns:
- The entries of the
BootstrapMethodsattribute; empty if the class file has no such attribute
-
getBootstrapMethod
public ClassFileReader.BootstrapMethod getBootstrapMethod(ClassFileReader.DynamicReference dynamicReference) - Returns:
- The bootstrap method of the given dynamicReference
-
getSourceFileName
-
getLineNumbers
Returns the source lines of the instructions that use the given memberReference, i.e. of the field access and method invocation instructions that refer to it, and of the instructions that use a method handle of it, either directly (ldc), or as the bootstrap method or a bootstrap argument of aninvokedynamicinstruction or a dynamically-computed constant (e.g. a method reference likeRuntime::getRuntime).- Returns:
- The line numbers; empty iff the class file has no
LineNumberTableattributes, or iff no instruction uses the memberReference
-
getLineNumbers
- Returns:
- The source lines of the
invokedynamicandldcinstructions that use the given dynamicReference; empty iff the class file has noLineNumberTableattributes, or iff no instruction uses the dynamicReference
-