Class ClassReader
🏭 Constructors
constructor
new ClassReader(buffer: Uint8Array, classFileOffset: number= 0, len: number= buffer.length): ClassReaderConstructs a new ClassReader object.
Parameters
- buffer:
Uint8Array - classFileOffset:
number - len:
numberthe length of the class data.
Return Type
ClassReader
Defined in: packages/asm/libs/ClassReader.ts:178
🏷️ Properties
buf
buf: Uint8ArrayThe 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: numberStart 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: numberMaximum 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 = trueTrue to enable annotations support.
Defined in: packages/asm/libs/ClassReader.ts:68
EXPAND_ASM_INSNS
EXPAND_ASM_INSNS: number = 256Flag 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 = 8Flag 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 = trueTrue to enable stack map frames support.
Defined in: packages/asm/libs/ClassReader.ts:73
RESIZE
RESIZE: boolean = trueTrue to enable JSR_W and GOTO_W support.
Defined in: packages/asm/libs/ClassReader.ts:83
SIGNATURES
SIGNATURES: boolean = trueTrue to enable signatures support.
Defined in: packages/asm/libs/ClassReader.ts:63
SKIP_CODE
SKIP_CODE: number = 1Flag 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 = 2Flag 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 = 4Flag 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 = trueTrue to enable bytecode writing support.
Defined in: packages/asm/libs/ClassReader.ts:78
🔧 Methods
accept
accept(classVisitor: ClassVisitor, attrs: Attribute[]= [], flags: number= 0): voidMakes 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:
ClassVisitorthe 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:
numberoption 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(): numberReturns 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(): numberReturns the start index of the attribute_info structure of this class.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1689
getClassName
getClassName(): stringReturns 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): voidComputes the implicit frame of the method currently being parsed (as defined in the given [Context]) and stores it in the given context.
Parameters
- frame:
Contextinformation 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): numberReturns 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:
numberthe index a constant pool item.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1760
getItemCount
getItemCount(): numberReturns the number of constant pool items in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1747
getMaxStringLength
getMaxStringLength(): numberReturns 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(): stringReturns 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): numberParses 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:
Contextinformation about the class being parsed. This is where the extracted target_type and target_path must be stored. - u:
numberthe 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): numberReads a value of an annotation and makes the given visitor visit it.
Parameters
- v:
numberthe 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 | stringthe name of the value to be read. - av:
null | AnnotationVisitorthe 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): numberReads the values of an annotation and makes the given visitor visit them.
Parameters
- v:
numberthe 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:
booleanif the annotation values are named or not. - av:
null | AnnotationVisitorthe 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[]): AttributeReads 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 | stringthe type of the attribute. - off:
numberindex 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:
numberthe length of the attribute's content. - buf:
number[]buffer to be used to call #readUTF8 readUTF8, #readClass(int, int[]) readClass or #readConst readConst. - codeOff:
numberindex 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): numberReads 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:
numberthe 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[]): stringReads 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:
numberthe 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): voidReads the bytecode of a method and makes the given visitor visit it.
Parameters
- mv:
MethodVisitorthe visitor that must visit the method's code. - context:
Contextinformation about the class being parsed. - u:
numberthe 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[]): anyReads 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:
numberthe 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): numberReads a field and makes the given visitor visit it.
Parameters
- classVisitor:
ClassVisitorthe visitor that must visit the field. - context:
Contextinformation about the class being parsed. - u:
numberthe 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): numberReads a stack map frame and stores the result in the given [Context] object.
Parameters
- stackMap:
numberthe start offset of a stack map frame in the class file. - zip:
booleanif the stack map frame at stackMap is compressed or not. - unzip:
booleanif the stack map frame must be uncompressed. - frame:
Contextwhere 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[]): numberReads 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:
numberthe index in 'frame' where the parsed type must be stored. - v:
numberthe 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): numberReads 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:
numberthe 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[]): LabelReturns 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:
numbera 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): bigintReads 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:
numberthe 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): numberReads a method and makes the given visitor visit it.
Parameters
- classVisitor:
ClassVisitorthe visitor that must visit the method. - context:
Contextinformation about the class being parsed. - u:
numberthe 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): voidReads parameter annotations and makes the given visitor visit them.
Parameters
- mv:
MethodVisitorthe visitor that must visit the annotations. - context:
Contextinformation about the class being parsed. - v:
numberstart 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): numberReads 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:
numberthe 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:
MethodVisitorthe method visitor to be used to visit the try catch block annotations. - context:
Contextinformation about the class being parsed. - u:
numberthe start offset of a type annotation table. - visible:
booleanif 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[]): stringReads UTF8 string in #b b.
Parameters
- index:
numberstart offset of the UTF8 string to be read. - utfLen:
numberlength 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[]): stringReads 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:
numberthe 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): numberReads 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:
numberthe start index of the value to be read in #b b.
Return Type
number
Defined in: packages/asm/libs/ClassReader.ts:1796