Class ClassReader
🏭 Constructors
constructor
new ClassReader(buffer: Uint8Array, classFileOffset: number= 0, len: number= buffer.length): ClassReader
Constructs a new ClassReader object.
Parameters
- buffer:
Uint8Array
- classFileOffset:
number
- len:
number
the length of the class data.
Return Type
ClassReader
Defined in: packages/asm/libs/ClassReader.ts:178
🏷️ Properties
buf
buf: Uint8Array
The class to be parsed. <i>The content of this array must not be modified. This field is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Defined in: packages/asm/libs/ClassReader.ts:141
header
header: number
Start index of the class header information (access, name...) in #b b.
Defined in: packages/asm/libs/ClassReader.ts:169
items
items: number[]
The start index of each constant pool item in #b b, plus one. The one byte offset skips the constant pool item tag that indicates its type.
Defined in: packages/asm/libs/ClassReader.ts:147
maxStringLength
maxStringLength: number
Maximum length of the strings contained in the constant pool of the class.
Defined in: packages/asm/libs/ClassReader.ts:163
strings
strings: string[]
The String objects corresponding to the CONSTANT_Utf8 items. This cache avoids multiple parsing of a given CONSTANT_Utf8 constant pool item, which GREATLY improves performances (by a factor 2 to 3). This caching strategy could be extended to all constant pool items, but its benefit would not be so great for these items (because they are much less expensive to parse than CONSTANT_Utf8 items).
Defined in: packages/asm/libs/ClassReader.ts:157
ANNOTATIONS
ANNOTATIONS: boolean = true
True to enable annotations support.
Defined in: packages/asm/libs/ClassReader.ts:68
EXPAND_ASM_INSNS
EXPAND_ASM_INSNS: number = 256
Flag to expand the ASM pseudo instructions into an equivalent sequence of standard bytecode instructions. When resolving a forward jump it may happen that the signed 2 bytes offset reserved for it is not sufficient to store the bytecode offset. In this case the jump instruction is replaced with a temporary ASM pseudo instruction using an unsigned 2 bytes offset (see Label#resolve). This internal flag is used to re-read classes containing such instructions, in order to replace them with standard instructions. In addition, when this flag is used, GOTO_W and JSR_W are <i>not</i> converted into GOTO and JSR, to make sure that infinite loops where a GOTO_W is replaced with a GOTO in ClassReader and converted back to a GOTO_W in ClassWriter cannot occur.
Defined in: packages/asm/libs/ClassReader.ts:134
EXPAND_FRAMES
EXPAND_FRAMES: number = 8
Flag to expand the stack map frames. By default stack map frames are visited in their original format (i.e. "expanded" for classes whose version is less than V1_6, and "compressed" for the other classes). If this flag is set, stack map frames are always visited in expanded format (this option adds a decompression/recompression step in ClassReader and ClassWriter which degrades performances quite a lot).
Defined in: packages/asm/libs/ClassReader.ts:119
FRAMES
FRAMES: boolean = true
True to enable stack map frames support.
Defined in: packages/asm/libs/ClassReader.ts:73
RESIZE
RESIZE: boolean = true
True to enable JSR_W and GOTO_W support.
Defined in: packages/asm/libs/ClassReader.ts:83
SIGNATURES
SIGNATURES: boolean = true
True to enable signatures support.
Defined in: packages/asm/libs/ClassReader.ts:63
SKIP_CODE
SKIP_CODE: number = 1
Flag to skip method code. If this class is set <code>CODE</code> attribute won't be visited. This can be used, for example, to retrieve annotations for methods and method parameters.
Defined in: packages/asm/libs/ClassReader.ts:90
SKIP_DEBUG
SKIP_DEBUG: number = 2
Flag to skip the debug information in the class. If this flag is set the debug information of the class is not visited, i.e. the visitLocalVariable and visitLineNumber methods will not be called.
Defined in: packages/asm/libs/ClassReader.ts:99
SKIP_FRAMES
SKIP_FRAMES: number = 4
Flag to skip the stack map frames in the class. If this flag is set the stack map frames of the class is not visited, i.e. the visitFrame method will not be called. This flag is useful when the [ClassWriter#COMPUTE_FRAMES] option is used: it avoids visiting frames that will be ignored and recomputed from scratch in the class writer.
Defined in: packages/asm/libs/ClassReader.ts:109
WRITER
WRITER: boolean = true
True to enable bytecode writing support.
Defined in: packages/asm/libs/ClassReader.ts:78
🔧 Methods
accept
accept(classVisitor: ClassVisitor, attrs: Attribute[]= [], flags: number= 0): void
Makes the given visitor visit the Java class of this ClassReader. This class is the one specified in the constructor (see #ClassReader(byte[]) ClassReader).
Parameters
- classVisitor:
ClassVisitor
the visitor that must visit this class. - attrs:
Attribute[]
prototypes of the attributes that must be parsed during the visit of the class. Any attribute whose type is not equal to the type of one the prototypes will not be parsed: its byte array value will be passed unchanged to the ClassWriter. <i>This may corrupt it if this value contains references to the constant pool, or has syntactic or semantic links with a class element that has been transformed by a class adapter between the reader and the writer</i>. - flags:
number
option flags that can be used to modify the default behavior of this class. See #SKIP_DEBUG, #EXPAND_FRAMES , #SKIP_FRAMES, #SKIP_CODE.
Return Type
void
Defined in: packages/asm/libs/ClassReader.ts:301
getAccess
getAccess(): number
Returns the class's access flags (see Opcodes). This value may not reflect Deprecated and Synthetic flags when bytecode is before 1.5 and those flags are represented by attributes.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:233
getAttributes
getAttributes(): number
Returns the start index of the attribute_info structure of this class.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1689
getClassName
getClassName(): string
Returns the internal name of the class (see [Type#getInternalName() getInternalName]).
Return Type
string
Defined in: packages/asm/libs/ClassReader.ts:244
getImplicitFrame
getImplicitFrame(frame: Context): void
Computes the implicit frame of the method currently being parsed (as defined in the given [Context]) and stores it in the given context.
Parameters
- frame:
Context
information about the class being parsed.
Return Type
void
Defined in: packages/asm/libs/ClassReader.ts:1483
getInterfaces
getInterfaces(): string[]
Returns the internal names of the class's interfaces (see [Type#getInternalName() getInternalName]).
Return Type
string[]
Defined in: packages/asm/libs/ClassReader.ts:269
getItem
getItem(item: number): number
Returns the start index of the constant pool item in #b b, plus one. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- item:
number
the index a constant pool item.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1760
getItemCount
getItemCount(): number
Returns the number of constant pool items in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1747
getMaxStringLength
getMaxStringLength(): number
Returns the maximum length of the strings contained in the constant pool of the class.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1771
getSuperName
getSuperName(): string
Returns the internal of name of the super class (see [Type#getInternalName() getInternalName]). For interfaces, the super class is [Object].
Return Type
string
Defined in: packages/asm/libs/ClassReader.ts:257
readAnnotationTarget
readAnnotationTarget(context: Context, u: number): number
Parses the header of a type annotation to extract its target_type and target_path (the result is stored in the given context), and returns the start offset of the rest of the type_annotation structure (i.e. the offset to the type_index field, which is followed by num_element_value_pairs and then the name,value pairs).
Parameters
- context:
Context
information about the class being parsed. This is where the extracted target_type and target_path must be stored. - u:
number
the start offset of a type_annotation structure.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1210
readAnnotationValue
readAnnotationValue(v: number, buf: number[], name: null | string, av: null | AnnotationVisitor): number
Reads a value of an annotation and makes the given visitor visit it.
Parameters
- v:
number
the start offset in #b b of the value to be read (<i>not including the value name constant pool index</i>). - buf:
number[]
buffer to be used to call #readUTF8 readUTF8, #readClass(int, int[]) readClass or #readConst readConst. - name:
null | string
the name of the value to be read. - av:
null | AnnotationVisitor
the visitor that must visit the value.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1337
readAnnotationValues
readAnnotationValues(v: number, buf: number[], named: boolean, av: null | AnnotationVisitor): number
Reads the values of an annotation and makes the given visitor visit them.
Parameters
- v:
number
the start offset in #b b of the values to be read (including the unsigned short that gives the number of values). - buf:
number[]
buffer to be used to call #readUTF8 readUTF8, #readClass(int, int[]) readClass or #readConst readConst. - named:
boolean
if the annotation values are named or not. - av:
null | AnnotationVisitor
the visitor that must visit the values.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1307
readAttribute
readAttribute(attrs: Attribute[], type: null | string, off: number, len: number, buf: number[], codeOff: number, labels: null | Label[]): Attribute
Reads an attribute in #b b.
Parameters
- attrs:
Attribute[]
prototypes of the attributes that must be parsed during the visit of the class. Any attribute whose type is not equal to the type of one the prototypes is ignored (i.e. an empty Attribute instance is returned). - type:
null | string
the type of the attribute. - off:
number
index of the first byte of the attribute's content in #b b. The 6 attribute header bytes, containing the type and the length of the attribute, are not taken into account here (they have already been read). - len:
number
the length of the attribute's content. - buf:
number[]
buffer to be used to call #readUTF8 readUTF8, #readClass(int, int[]) readClass or #readConst readConst. - codeOff:
number
index of the first byte of code's attribute content in #b b, or -1 if the attribute to be read is not a code attribute. The 6 attribute header bytes, containing the type and the length of the attribute, are not taken into account here. - labels:
null | Label[]
the labels of the method's code, or <tt>null</tt> if the attribute to be read is not a code attribute.
Return Type
Attribute
Defined in: packages/asm/libs/ClassReader.ts:1733
readByte
readByte(index: number): number
Reads a byte value in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of the value to be read in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1783
readClass
readClass(index: number, buf: number[]): string
Reads a class constant pool item in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of an unsigned short value in #b b, whose value is the index of a class constant pool item. - buf:
number[]
buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
Return Type
string
Defined in: packages/asm/libs/ClassReader.ts:1919
readCode
readCode(mv: MethodVisitor, context: Context, u: number): void
Reads the bytecode of a method and makes the given visitor visit it.
Parameters
- mv:
MethodVisitor
the visitor that must visit the method's code. - context:
Context
information about the class being parsed. - u:
number
the start offset of the code attribute in the class file.
Return Type
void
Defined in: packages/asm/libs/ClassReader.ts:674
readConst
readConst(item: number, buf: number[]): any
Reads a numeric or string constant pool item in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- item:
number
the index of a constant pool item. - buf:
number[]
buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
Return Type
any
Defined in: packages/asm/libs/ClassReader.ts:1935
readField
readField(classVisitor: ClassVisitor, context: Context, u: number): number
Reads a field and makes the given visitor visit it.
Parameters
- classVisitor:
ClassVisitor
the visitor that must visit the field. - context:
Context
information about the class being parsed. - u:
number
the start offset of the field in the class file.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:434
readFrame
readFrame(stackMap: number, zip: boolean, unzip: boolean, frame: Context): number
Reads a stack map frame and stores the result in the given [Context] object.
Parameters
- stackMap:
number
the start offset of a stack map frame in the class file. - zip:
boolean
if the stack map frame at stackMap is compressed or not. - unzip:
boolean
if the stack map frame must be uncompressed. - frame:
Context
where the parsed stack map frame must be stored.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1550
readFrameType
readFrameType(frame: any[], index: number, v: number, buf: number[], labels: Label[]): number
Reads a stack map frame type and stores it at the given index in the given array.
Parameters
- frame:
any[]
the array where the parsed type must be stored. - index:
number
the index in 'frame' where the parsed type must be stored. - v:
number
the start offset of the stack map frame type to read. - buf:
number[]
a buffer to read strings. - labels:
Label[]
the labels of the method currently being parsed, indexed by their offset. If the parsed type is an Uninitialized type, a new label for the corresponding NEW instruction is stored in this array if it does not already exist.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1631
readInt
readInt(index: number): number
Reads a signed int value in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of the value to be read in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1823
readLabel
readLabel(offset: number, labels: Label[]): Label
Returns the label corresponding to the given offset. The default implementation of this method creates a label for the given offset if it has not been already created.
Parameters
- offset:
number
a bytecode offset in a method. - labels:
Label[]
the already created labels, indexed by their offset. If a label already exists for offset this method must not create a new one. Otherwise it must store the new label in this array.
Return Type
Label
Defined in: packages/asm/libs/ClassReader.ts:1677
readLong
readLong(index: number): bigint
Reads a signed long value in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of the value to be read in #b b.
Return Type
bigint
Defined in: packages/asm/libs/ClassReader.ts:1837
readMethod
readMethod(classVisitor: ClassVisitor, context: Context, u: number): number
Reads a method and makes the given visitor visit it.
Parameters
- classVisitor:
ClassVisitor
the visitor that must visit the method. - context:
Context
information about the class being parsed. - u:
number
the start offset of the method in the class file.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:521
readParameterAnnotations
readParameterAnnotations(mv: MethodVisitor, context: Context, v: number, visible: boolean): void
Reads parameter annotations and makes the given visitor visit them.
Parameters
- mv:
MethodVisitor
the visitor that must visit the annotations. - context:
Context
information about the class being parsed. - v:
number
start offset in #b b of the annotations to be read. - visible:
boolean
<tt>true</tt> if the annotations to be read are visible at runtime.
Return Type
void
Defined in: packages/asm/libs/ClassReader.ts:1272
readShort
readShort(index: number): number
Reads a signed short value in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of the value to be read in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1810
readTypeAnnotations
readTypeAnnotations(mv: MethodVisitor, context: Context, u: number, visible: boolean): number[]
Parses a type annotation table to find the labels, and to visit the try catch block annotations.
Parameters
- mv:
MethodVisitor
the method visitor to be used to visit the try catch block annotations. - context:
Context
information about the class being parsed. - u:
number
the start offset of a type annotation table. - visible:
boolean
if the type annotation table to parse contains runtime visible annotations.
Return Type
number[]
Defined in: packages/asm/libs/ClassReader.ts:1146
readUTF
readUTF(index: number, utfLen: number, buf: number[]): string
Reads UTF8 string in #b b.
Parameters
- index:
number
start offset of the UTF8 string to be read. - utfLen:
number
length of the UTF8 string to be read. - buf:
number[]
buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.
Return Type
string
Defined in: packages/asm/libs/ClassReader.ts:1873
readUTF8
readUTF8(index: number, buf: number[]): string
Reads an UTF8 string constant pool item in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of an unsigned short value in #b b, whose value is the index of an UTF8 constant pool item. - buf:
number[]
buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
Return Type
string
Defined in: packages/asm/libs/ClassReader.ts:1854
readUnsignedShort
readUnsignedShort(index: number): number
Reads an unsigned short value in #b b. <i>This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.</i>
Parameters
- index:
number
the start index of the value to be read in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1796