Class MethodWriter
java.lang.Object
mockit.asm.BaseWriter
mockit.asm.methods.MethodVisitor
mockit.asm.methods.MethodWriter
A
MethodVisitor that generates methods in bytecode form. Each visit method of this class appends the bytecode
corresponding to the visited instruction to a byte vector, in the order these methods are called.-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ClassWriterThe class writer to which this method must be added.Fields inherited from class BaseWriter
annotations, classOrMemberAccess, cp -
Constructor Summary
ConstructorsConstructorDescriptionMethodWriter(ClassWriter cw, int access, String name, String desc, String signature, String[] exceptions, boolean computeFrames) Initializes this MethodWriter. -
Method Summary
Modifier and TypeMethodDescription@NonNegative intgetSize()Returns the size of the bytecode of this method.protected voidput(ByteVector out) Puts the bytecode of this method in the given byte vector.voidvisitFieldInsn(int opcode, String owner, String name, String desc) Visits a field access instruction, which loads or stores the value of a field of an object or a class.voidvisitIincInsn(@NonNegative int varIndex, int increment) Visits anIINCinstruction.voidvisitInsn(int opcode) Visits a zero operand instruction.voidvisitIntInsn(int opcode, int operand) Visits an instruction with a singleintoperand.voidvisitInvokeDynamicInsn(String name, String desc, MethodHandle bsm, Object... bsmArgs) Visits anINVOKEDYNAMICinstruction.voidvisitJumpInsn(int opcode, Label label) Visits a jump instruction.voidvisitLabel(Label label) Visits a label, which designates the instruction that will be visited just after it.voidvisitLdcInsn(Object cst) Visits aLDCinstruction.voidvisitLineNumber(@NonNegative int line, Label start) Visits a line number within the body of the method.voidvisitLocalVariable(String name, String desc, String signature, Label start, Label end, @NonNegative int index) Visits a local variable declaration.voidvisitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) Visits aLOOKUPSWITCHinstruction.voidvisitMaxStack(@NonNegative int maxStack) Visits the maximum stack size of the method.voidvisitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) Visits a method invocation instruction, which invokes a method or constructor.voidvisitMultiANewArrayInsn(String desc, @NonNegative int dims) Visits aMULTIANEWARRAYinstruction.visitParameterAnnotation(@NonNegative int parameter, String desc) Visits an annotation on a parameter of the method being visited.voidvisitTableSwitchInsn(int min, int max, Label dflt, Label... labels) Visits aTABLESWITCHinstruction.voidvisitTryCatchBlock(Label start, Label end, Label handler, String type) Visits atry..catchblock.voidvisitTypeInsn(int opcode, String typeDesc) Visits a type instruction, which takes the internal name of a class as parameter.voidvisitVarInsn(int opcode, @NonNegative int varIndex) Visits a local variable instruction, which loads or stores the value of a local variable.Methods inherited from class BaseWriter
createMarkerAttributes, getAnnotationsSize, getConstantPoolGeneration, getMarkerAttributeCount, getMarkerAttributesSize, put, putAccess, putAnnotations, putMarkerAttributes, visitAnnotation, visitEnd
-
Field Details
-
cw
The class writer to which this method must be added.
-
-
Constructor Details
-
MethodWriter
public MethodWriter(@NonNull ClassWriter cw, int access, @NonNull String name, @NonNull String desc, @Nullable String signature, @Nullable String[] exceptions, boolean computeFrames) Initializes this MethodWriter.- Parameters:
cw- the class writer in which the method must be addedaccess- the method's access flags (seeOpcodes)name- the method's namedesc- the method's descriptor (seeJavaType)signature- the method's signatureexceptions- the internal names of the method's exceptionscomputeFrames-trueif the stack map tables must be recomputed from scratch
-
-
Method Details
-
visitParameterAnnotation
@NonNull public AnnotationVisitor visitParameterAnnotation(@NonNegative int parameter, @NonNull String desc) Description copied from class:MethodVisitorVisits an annotation on a parameter of the method being visited.- Overrides:
visitParameterAnnotationin classMethodVisitor- Parameters:
parameter- the parameter indexdesc- the descriptor of the annotation type- Returns:
- a visitor to visit the annotation values, or
nullif this visitor is not interested in visiting this annotation
-
visitInsn
public void visitInsn(int opcode) Description copied from class:MethodVisitorVisits a zero operand instruction.- Overrides:
visitInsnin classMethodVisitor- Parameters:
opcode- the opcode of the instruction to be visited: NOP, ACONST_NULL, ICONST_M1, ICONST_0 ICONST_0 to ICONST_5, LCONST_0, LCONST_1, FCONST_0 to 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
-
visitIntInsn
public void visitIntInsn(int opcode, int operand) Description copied from class:MethodVisitorVisits an instruction with a singleintoperand.- Overrides:
visitIntInsnin classMethodVisitor- Parameters:
opcode- the opcode of the instruction to be visited: BIPUSH, SIPUSH, or NEWARRAYoperand- the operand of the instruction to be visited: when opcode is BIPUSH, it's betweenByte.MIN_VALUEandByte.MAX_VALUE; when opcode is SIPUSH, it's betweenShort.MIN_VALUEandShort.MAX_VALUE; when opcode is NEWARRAY, the operand value is one of theArrayElementTypevalues
-
visitVarInsn
public void visitVarInsn(int opcode, @NonNegative int varIndex) Description copied from class:MethodVisitorVisits a local variable instruction, which loads or stores the value of a local variable.- Overrides:
visitVarInsnin classMethodVisitor- Parameters:
opcode- the opcode of the local variable instruction to be visited: ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RETvarIndex- the operand of the instruction to be visited, which is the index of a local variable
-
visitTypeInsn
Description copied from class:MethodVisitorVisits a type instruction, which takes the internal name of a class as parameter.- Overrides:
visitTypeInsnin classMethodVisitor- Parameters:
opcode- the opcode of the instruction to be visited: NEW, ANEWARRAY, CHECKCAST, or INSTANCEOFtypeDesc- the operand of the instruction, which is the internal name of an object or array class
-
visitFieldInsn
public void visitFieldInsn(int opcode, @NonNull String owner, @NonNull String name, @NonNull String desc) Description copied from class:MethodVisitorVisits a field access instruction, which loads or stores the value of a field of an object or a class.- Overrides:
visitFieldInsnin classMethodVisitor- Parameters:
opcode- the opcode of the instruction to be visited: GETSTATIC, PUTSTATIC, GETFIELD, or PUTFIELDowner- the internal name of the field's owner classname- the field's namedesc- the field's descriptor (seeJavaType)
-
visitMethodInsn
public void visitMethodInsn(int opcode, @NonNull String owner, @NonNull String name, @NonNull String desc, boolean itf) Description copied from class:MethodVisitorVisits a method invocation instruction, which invokes a method or constructor.- Overrides:
visitMethodInsnin classMethodVisitor- Parameters:
opcode- the opcode of the instruction: INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, or INVOKEINTERFACEowner- the internal name of the method's owner classname- the method's namedesc- the method's descriptor (seeJavaType)itf- whether the method's owner class is an interface or not
-
visitInvokeDynamicInsn
public void visitInvokeDynamicInsn(@NonNull String name, @NonNull String desc, @NonNull MethodHandle bsm, @NonNull Object... bsmArgs) Description copied from class:MethodVisitorVisits anINVOKEDYNAMICinstruction.- Overrides:
visitInvokeDynamicInsnin classMethodVisitor- Parameters:
name- the method's namedesc- the method's descriptor (seeJavaType)bsm- the bootstrap methodbsmArgs- the bootstrap method constant arguments, where each argument must be anInteger,Float,Long,Double,String,JavaType, orMethodHandlevalue
-
visitJumpInsn
Description copied from class:MethodVisitorVisits a jump instruction.- Overrides:
visitJumpInsnin classMethodVisitor- Parameters:
opcode- the opcode of the jump instruction to be visited: 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 IFNONNULLlabel- the operand of the instruction to be visited, which is a label that designates the instruction to which the jump instruction may jump
-
visitLabel
Description copied from class:MethodVisitorVisits a label, which designates the instruction that will be visited just after it.- Overrides:
visitLabelin classMethodVisitor
-
visitLdcInsn
Description copied from class:MethodVisitorVisits aLDCinstruction.- Overrides:
visitLdcInsnin classMethodVisitor- Parameters:
cst- the constant to be loaded on the stack, which must be a non nullInteger/Float/Long/Double/String, anObjectTypeorArrayTypefor.classconstants, aMethodType, or aMethodHandle
-
visitIincInsn
public void visitIincInsn(@NonNegative int varIndex, int increment) Description copied from class:MethodVisitorVisits anIINCinstruction.- Overrides:
visitIincInsnin classMethodVisitor- Parameters:
varIndex- index of the local variable to be incrementedincrement- amount to increment the local variable by
-
visitTableSwitchInsn
Description copied from class:MethodVisitorVisits aTABLESWITCHinstruction.- Overrides:
visitTableSwitchInsnin classMethodVisitor- Parameters:
min- the minimum key valuemax- the maximum key valuedflt- beginning of the default handler blocklabels- beginnings of the handler blocks;labels[i]is the beginning of the handler block for themin + ikey
-
visitLookupSwitchInsn
public void visitLookupSwitchInsn(@NonNull Label dflt, @NonNull int[] keys, @NonNull Label[] labels) Description copied from class:MethodVisitorVisits aLOOKUPSWITCHinstruction.- Overrides:
visitLookupSwitchInsnin classMethodVisitor- Parameters:
dflt- beginning of the default handler blockkeys- the values of the keyslabels- beginnings of the handler blocks;labels[i]is the beginning of the handler block for thekeys[i]
-
visitMultiANewArrayInsn
Description copied from class:MethodVisitorVisits aMULTIANEWARRAYinstruction.- Overrides:
visitMultiANewArrayInsnin classMethodVisitor- Parameters:
desc- an array type descriptor (seeArrayType)dims- number of dimensions of the array to allocate
-
visitTryCatchBlock
public void visitTryCatchBlock(@NonNull Label start, @NonNull Label end, @NonNull Label handler, @Nullable String type) Description copied from class:MethodVisitorVisits atry..catchblock.- Overrides:
visitTryCatchBlockin classMethodVisitor- Parameters:
start- beginning of the exception handler's scope (inclusive)end- end of the exception handler's scope (exclusive)handler- beginning of the exception handler's codetype- internal name of the type of exceptions handled by the handler, ornullto catch any exceptions (for "finally" blocks)
-
visitLocalVariable
public void visitLocalVariable(@NonNull String name, @NonNull String desc, @Nullable String signature, @NonNull Label start, @NonNull Label end, @NonNegative int index) Description copied from class:MethodVisitorVisits a local variable declaration.- Overrides:
visitLocalVariablein classMethodVisitor- Parameters:
name- the name of the local variabledesc- the type descriptor of the local variablesignature- the type signature of the local variable;nullwhen the local variable type does not use generic typesstart- the first instruction corresponding to the scope of this local variable (inclusive)end- the last instruction corresponding to the scope of this local variable (exclusive)index- the local variable's index
-
visitLineNumber
Description copied from class:MethodVisitorVisits a line number within the body of the method.- Overrides:
visitLineNumberin classMethodVisitor- Parameters:
line- a line number, which refers to the source file from which the class was compiledstart- the first instruction corresponding to this line number
-
visitMaxStack
public void visitMaxStack(@NonNegative int maxStack) Description copied from class:MethodVisitorVisits the maximum stack size of the method.- Overrides:
visitMaxStackin classMethodVisitor
-
getSize
public @NonNegative int getSize()Returns the size of the bytecode of this method. -
put
Puts the bytecode of this method in the given byte vector.- Overrides:
putin classBaseWriter
-
getCurrentBlock
-