Skip to content

Class MethodVisitor

🏭 Constructors

constructor

ts
new MethodVisitor(api: number, mv: null | MethodVisitor= null): MethodVisitor

Constructs a new MethodVisitor.

Parameters

  • api: number the ASM API version implemented by this visitor. Must be one of ASM4 or ASM5.
  • mv: null | MethodVisitor the method visitor to which this visitor must delegate method calls. May be null.

Return Type

  • MethodVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:84

🏷️ Properties

api

ts
api: number

The ASM API version implemented by this visitor. The value of this field must be one of ASM4 or ASM5.

Defined in: packages/asm/libs/MethodVisitor.ts:66

mv

ts
mv: null | MethodVisitor

The method visitor to which this visitor must delegate method calls. May be null.

Defined in: packages/asm/libs/MethodVisitor.ts:72

🔧 Methods

visitAnnotation

ts
visitAnnotation(desc: null | string, visible: boolean): null | AnnotationVisitor

Visits an annotation of this method.

Parameters

  • desc: null | string the class descriptor of the annotation class.
  • visible: boolean <tt>true</tt> if the annotation is visible at runtime.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:139

visitAnnotationDefault

ts
visitAnnotationDefault(): null | AnnotationVisitor

Visits the default value of this annotation interface method.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:122

visitAttribute

ts
visitAttribute(attr: Attribute): void

Visits a non standard attribute of this method.

Parameters

  • attr: Attribute an attribute.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:206

visitCode

ts
visitCode(): void

Starts the visit of the method's code, if any (i.e. non abstract method).

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:215

visitEnd

ts
visitEnd(): void

Visits the end of the method. This method, which is the last one to be called, is used to inform the visitor that all the annotations and attributes of the method have been visited.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:849

visitFieldInsn

ts
visitFieldInsn(opcode: number, owner: string, name: null | string, desc: null | string): void

Visits a field instruction. A field instruction is an instruction that loads or stores the value of a field of an object.

Parameters

  • opcode: number the opcode of the type instruction to be visited. This opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
  • owner: string the internal name of the field's owner class (see [Type#getInternalName() getInternalName]).
  • name: null | string the field's name.
  • desc: null | string the field's descriptor (see Type).

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:408

visitFrame

ts
visitFrame(type: any, nLocal: any, local: any, nStack: any, stack: any): any

Visits the current state of the local variables and operand stack elements. This method must() be called <i>just before</i> any instruction <b>i</b> that follows an unconditional branch instruction such as GOTO or THROW, that is the target of a jump instruction, or that starts an exception handler block. The visited types must describe the values of the local variables and of the operand stack elements <i>just before</i> <b>i</b> is executed.<br> <br> () this is mandatory only for classes whose version is greater than or equal to V1_6. <br> <br> The frames of a method must be given either in expanded form, or in compressed form (all frames must use the same format, i.e. you must not mix expanded and compressed frames within a single method): <ul> <li>In expanded form, all frames must have the F_NEW type.</li> <li>In compressed form, frames are basically "deltas" from the state of the previous frame: <ul> <li>F_SAME representing frame with exactly the same locals as the previous frame and with the empty stack.</li> <li>F_SAME1 representing frame with exactly the same locals as the previous frame and with single value on the stack ( <code>nStack</code> is 1 and <code>stack[0]</code> contains value for the type of the stack item).</li> <li>F_APPEND representing frame with current locals are the same as the locals in the previous frame, except that additional locals are defined (<code>nLocal</code> is 1, 2 or 3 and <code>local</code> elements contains values representing added types).</li> <li>F_CHOP representing frame with current locals are the same as the locals in the previous frame, except that the last 1-3 locals are absent and with the empty stack (<code>nLocals</code> is 1, 2 or 3).</li> <li>F_FULL representing complete frame data.</li> </ul> </li> </ul> <br> In both cases the first frame, corresponding to the method's parameters and access flags, is implicit and must not be visited. Also, it is illegal to visit two or more frames for the same code location (i.e., at least one instruction must be visited between two calls to visitFrame).

Parameters

  • type: any the type of this stack map frame. Must be F_NEW for expanded frames, or F_FULL, F_APPEND, F_CHOP, F_SAME or F_APPEND, F_SAME1 for compressed frames.
  • nLocal: any the number of local variables in the visited frame.
  • local: any the local variable types in this frame. This array must not be modified. Primitive types are represented by TOP, INTEGER, FLOAT, LONG, DOUBLE,NULL or UNINITIALIZED_THIS (long and double are represented by a single element). Reference types are represented by String objects (representing internal names), and uninitialized types by Label objects (this label designates the NEW instruction that created this uninitialized value).
  • nStack: any the number of operand stack elements in the visited frame.
  • stack: any the operand stack types in this frame. This array must not be modified. Its content has the same format as the "local" array.

Return Type

  • any

Defined in: packages/asm/libs/MethodVisitor.ts:296

visitIincInsn

ts
visitIincInsn(__var: number, increment: number): void

Visits an IINC instruction.

Parameters

  • __var: number
  • increment: number amount to increment the local variable by.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:592

visitInsn

ts
visitInsn(opcode: number): void

Visits a zero operand instruction.

Parameters

  • opcode: number the opcode of the instruction to be visited. This opcode is either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:327

visitInsnAnnotation

ts
visitInsnAnnotation(typeRef: number, typePath: null | TypePath, desc: null | string, visible: boolean): null | AnnotationVisitor

Visits an annotation on an instruction. This method must be called just <i>after</i> the annotated instruction. It can be called several times for the same instruction.

Parameters

  • typeRef: number a reference to the annotated type. The sort of this type reference must be [TypeReference#INSTANCEOF INSTANCEOF], [TypeReference#NEW NEW], [TypeReference#CONSTRUCTOR_REFERENCE CONSTRUCTOR_REFERENCE], [TypeReference#METHOD_REFERENCE METHOD_REFERENCE], [TypeReference#CAST CAST], [TypeReference#CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT], [TypeReference#METHOD_INVOCATION_TYPE_ARGUMENT METHOD_INVOCATION_TYPE_ARGUMENT], [TypeReference#CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT], or [TypeReference#METHOD_REFERENCE_TYPE_ARGUMENT METHOD_REFERENCE_TYPE_ARGUMENT]. See TypeReference.
  • typePath: null | TypePath the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be <tt>null</tt> if the annotation targets 'typeRef' as a whole.
  • desc: null | string the class descriptor of the annotation class.
  • visible: boolean <tt>true</tt> if the annotation is visible at runtime.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:679

visitIntInsn

ts
visitIntInsn(opcode: number, operand: number): void

Visits an instruction with a single int operand.

Parameters

  • opcode: number the opcode of the instruction to be visited. This opcode is either BIPUSH, SIPUSH or NEWARRAY.
  • operand: number the operand of the instruction to be visited.<br> When opcode is BIPUSH, operand value should be between Byte.MIN_VALUE and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When opcode is NEWARRAY, operand value should be one of T_BOOLEAN, T_CHAR, T_FLOAT, T_DOUBLE, T_BYTE, T_SHORT, T_INT or T_LONG.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:351

visitInvokeDynamicInsn

ts
visitInvokeDynamicInsn(name: string, desc: string, bsm: Handle, bsmArgs: any[]): void

Visits an invokedynamic instruction.

Parameters

  • name: string the method's name.
  • desc: string the method's descriptor (see Type).
  • bsm: Handle the bootstrap method.
  • bsmArgs: any[] the bootstrap method constant arguments. Each argument must be an [Integer], [Float], [Long], [Double], [String], Type or Handle value. This method is allowed to modify the content of the array so a caller should expect that this array may change.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:495

visitJumpInsn

ts
visitJumpInsn(opcode: number, label: Label): void

Visits a jump instruction. A jump instruction is an instruction that may jump to another instruction.

Parameters

  • opcode: number the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
  • label: Label the operand of the instruction to be visited. This operand is a label that designates the instruction to which the jump instruction may jump.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:515

visitLabel

ts
visitLabel(label: Label): void

Visits a label. A label designates the instruction that will be visited just after it.

Parameters

  • label: Label a Label object.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:528

visitLdcInsn

ts
visitLdcInsn(cst: any): void

Visits a LDC instruction. Note that new constant types may be added in future versions of the Java Virtual Machine. To easily detect new constant types, implementations of this method should check for unexpected constant types, like this:

<pre> if (cst instanceof Integer) { // ... } else if (cst instanceof Float) { // ... } else if (cst instanceof Long) { // ... } else if (cst instanceof Double) { // ... } else if (cst instanceof String) { // ... } else if (cst instanceof Type) { int sort = ((Type) cst).getSort(); if (sort == Type.OBJECT) { // ... } else if (sort == Type.ARRAY) { // ... } else if (sort == Type.METHOD) { // ... } else { // throw an exception } } else if (cst instanceof Handle) { // ... } else { // throw an exception } </pre>

Parameters

  • cst: any the constant to be loaded on the stack. This parameter must be a non null [Integer], a [Float], a [Long], a [Double], a [String], a Type of OBJECT or ARRAY sort for <tt>.class</tt> constants, for classes whose version is 49.0, a Type of METHOD sort or a Handle for MethodType and MethodHandle constants, for classes whose version is 51.0.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:578

visitLineNumber

ts
visitLineNumber(line: number, start: Label): void

Visits a line number declaration.

Parameters

  • line: number a line number. This number refers to the source file from which the class was compiled.
  • start: Label the first instruction corresponding to this line number.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:823

visitLocalVariable

ts
visitLocalVariable(name: null | string, desc: null | string, signature: null | string, start: Label, end: Label, index: number): void

Visits a local variable declaration.

Parameters

  • name: null | string the name of a local variable.
  • desc: null | string the type descriptor of this local variable.
  • signature: null | string the type signature of this local variable. May be <tt>null</tt> if the local variable type does not use generic types.
  • start: Label the first instruction corresponding to the scope of this local variable (inclusive).
  • end: Label the last instruction corresponding to the scope of this local variable (exclusive).
  • index: number the local variable's index.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:766

visitLocalVariableAnnotation

ts
visitLocalVariableAnnotation(typeRef: number, typePath: null | TypePath, start: Label[], end: Label[], index: number[], desc: null | string, visible: boolean): null | AnnotationVisitor

Visits an annotation on a local variable type.

Parameters

  • typeRef: number a reference to the annotated type. The sort of this type reference must be [TypeReference#LOCAL_VARIABLE LOCAL_VARIABLE] or [TypeReference#RESOURCE_VARIABLE RESOURCE_VARIABLE]. See TypeReference.
  • typePath: null | TypePath the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be <tt>null</tt> if the annotation targets 'typeRef' as a whole.
  • start: Label[] the fist instructions corresponding to the continuous ranges that make the scope of this local variable (inclusive).
  • end: Label[] the last instructions corresponding to the continuous ranges that make the scope of this local variable (exclusive). This array must have the same size as the 'start' array.
  • index: number[] the local variable's index in each range. This array must have the same size as the 'start' array.
  • desc: null | string the class descriptor of the annotation class.
  • visible: boolean <tt>true</tt> if the annotation is visible at runtime.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:801

visitLookupSwitchInsn

ts
visitLookupSwitchInsn(dflt: Label, keys: number[], labels: Label[]): void

Visits a LOOKUPSWITCH instruction.

Parameters

  • dflt: Label beginning of the default handler block.
  • keys: number[] the values of the keys.
  • labels: Label[] beginnings of the handler blocks. <tt>labels[i]</tt> is the beginning of the handler block for the <tt>keys[i]</tt> key.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:628

visitMaxs

ts
visitMaxs(maxStack: number, maxLocals: number): void

Visits the maximum stack size and the maximum number of local variables of the method.

Parameters

  • maxStack: number maximum stack size of the method.
  • maxLocals: number maximum number of local variables for the method.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:838

visitMethodInsn

ts
visitMethodInsn(opcode: any, owner: any, name: any, desc: any, itf: any): any

Visits a method instruction. A method instruction is an instruction that invokes a method.

Parameters

  • opcode: any the opcode of the type instruction to be visited. This opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.
  • owner: any the internal name of the method's owner class (see [Type#getInternalName() getInternalName]).
  • name: any the method's name.
  • desc: any the method's descriptor (see Type).
  • itf: any if the method's owner class is an interface.

Return Type

  • any

Defined in: packages/asm/libs/MethodVisitor.ts:459

visitMethodInsn$int$java_lang_String$java_lang_String$java_lang_String

ts
visitMethodInsn$int$java_lang_String$java_lang_String$java_lang_String(opcode: number, owner: string, name: string, desc: string): void

Visits a method instruction. A method instruction is an instruction that invokes a method.

Parameters

  • opcode: number the opcode of the type instruction to be visited. This opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.
  • owner: string the internal name of the method's owner class (see [Type#getInternalName() getInternalName]).
  • name: string the method's name.
  • desc: string the method's descriptor (see Type).

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:430

visitMultiANewArrayInsn

ts
visitMultiANewArrayInsn(desc: string, dims: number): void

Visits a MULTIANEWARRAY instruction.

Parameters

  • desc: string an array type descriptor (see Type).
  • dims: number number of dimensions of the array to allocate.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:642

visitParameter

ts
visitParameter(name: null | string, access: number): void

Visits a parameter of this method.

Parameters

  • name: null | string parameter name or null if none is provided.
  • access: number the parameter's access flags, only <tt>ACC_FINAL</tt>, <tt>ACC_SYNTHETIC</tt> or/and <tt>ACC_MANDATED</tt> are allowed (see Opcodes).

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:103

visitParameterAnnotation

ts
visitParameterAnnotation(parameter: number, desc: null | string, visible: boolean): null | AnnotationVisitor

Visits an annotation of a parameter this method.

Parameters

  • parameter: number the parameter index.
  • desc: null | string the class descriptor of the annotation class.
  • visible: boolean <tt>true</tt> if the annotation is visible at runtime.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:193

visitTableSwitchInsn

ts
visitTableSwitchInsn(min: number, max: number, dflt: Label, labels: Label[]): void

Visits a TABLESWITCH instruction.

Parameters

  • min: number the minimum key value.
  • max: number the maximum key value.
  • dflt: Label beginning of the default handler block.
  • labels: Label[] beginnings of the handler blocks. <tt>labels[i]</tt> is the beginning of the handler block for the <tt>min + i</tt> key.

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:611

visitTryCatchAnnotation

ts
visitTryCatchAnnotation(typeRef: number, typePath: null | TypePath, desc: null | string, visible: boolean): null | AnnotationVisitor

Visits an annotation on an exception handler type. This method must be called <i>after</i> the #visitTryCatchBlock for the annotated exception handler. It can be called several times for the same exception handler.

Parameters

  • typeRef: number a reference to the annotated type. The sort of this type reference must be [TypeReference#EXCEPTION_PARAMETER EXCEPTION_PARAMETER]. See TypeReference.
  • typePath: null | TypePath the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be <tt>null</tt> if the annotation targets 'typeRef' as a whole.
  • desc: null | string the class descriptor of the annotation class.
  • visible: boolean <tt>true</tt> if the annotation is visible at runtime.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:733

visitTryCatchBlock

ts
visitTryCatchBlock(start: Label, end: Label, handler: Label, type: null | string): void

Visits a try catch block.

Parameters

  • start: Label beginning of the exception handler's scope (inclusive).
  • end: Label end of the exception handler's scope (exclusive).
  • handler: Label beginning of the exception handler's code.
  • type: null | string internal name of the type of exceptions handled by the handler, or <tt>null</tt> to catch any exceptions (for "finally" blocks).

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:706

visitTypeAnnotation

ts
visitTypeAnnotation(typeRef: number, typePath: null | TypePath, desc: null | string, visible: boolean): null | AnnotationVisitor

Visits an annotation on a type in the method signature.

Parameters

  • typeRef: number a reference to the annotated type. The sort of this type reference must be [TypeReference#METHOD_TYPE_PARAMETER METHOD_TYPE_PARAMETER], [TypeReference#METHOD_TYPE_PARAMETER_BOUND METHOD_TYPE_PARAMETER_BOUND], [TypeReference#METHOD_RETURN METHOD_RETURN], [TypeReference#METHOD_RECEIVER METHOD_RECEIVER], [TypeReference#METHOD_FORMAL_PARAMETER METHOD_FORMAL_PARAMETER] or [TypeReference#THROWS THROWS]. See TypeReference.
  • typePath: null | TypePath the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be <tt>null</tt> if the annotation targets 'typeRef' as a whole.
  • desc: null | string the class descriptor of the annotation class.
  • visible: boolean <tt>true</tt> if the annotation is visible at runtime.

Return Type

  • null | AnnotationVisitor

Defined in: packages/asm/libs/MethodVisitor.ts:171

visitTypeInsn

ts
visitTypeInsn(opcode: number, type: string): void

Visits a type instruction. A type instruction is an instruction that takes the internal name of a class as parameter.

Parameters

  • opcode: number the opcode of the type instruction to be visited. This opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
  • type: string the operand of the instruction to be visited. This operand must be the internal name of an object or array class (see [Type#getInternalName() getInternalName]).

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:387

visitVarInsn

ts
visitVarInsn(opcode: number, __var: number): void

Visits a local variable instruction. A local variable instruction is an instruction that loads or stores the value of a local variable.

Parameters

  • opcode: number the opcode of the local variable instruction to be visited. This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
  • __var: number

Return Type

  • void

Defined in: packages/asm/libs/MethodVisitor.ts:369

Released under the MIT License.