1 package mockit.asm.methods; 2 3 import edu.umd.cs.findbugs.annotations.NonNull; 4 import edu.umd.cs.findbugs.annotations.Nullable; 5 6 import mockit.asm.BaseWriter; 7 import mockit.asm.annotations.AnnotationVisitor; 8 import mockit.asm.constantPool.ConstantPoolGeneration; 9 import mockit.asm.controlFlow.Label; 10 import mockit.asm.jvmConstants.ArrayElementType; 11 import mockit.asm.jvmConstants.Opcodes; 12 import mockit.asm.types.ArrayType; 13 import mockit.asm.types.JavaType; 14 import mockit.asm.types.MethodType; 15 import mockit.asm.types.ObjectType; 16 import mockit.asm.util.MethodHandle; 17 18 import org.checkerframework.checker.index.qual.NonNegative; 19 20 /** 21 * A visitor to visit a Java method, in the following order:<br> 22 * ({@link #visitAnnotation})* ({@link #visitParameterAnnotation})* [(<code>visit<i>X</i>Insn</code> | 23 * {@link #visitLabel} | {@link #visitTryCatchBlock} | {@link #visitLocalVariable} | {@link #visitLineNumber})* 24 * {@link #visitMaxStack}] {@link #visitEnd}. 25 * <p> 26 * In addition, the <code>visit<i>X</i>Insn</code> and <code>visitLabel</code> methods are called in the sequential 27 * order of the bytecode instructions of the visited code, <code>visitTryCatchBlock</code> is called <i>before</i> the 28 * labels passed as arguments have been visited, and the <code>visitLocalVariable</code> and 29 * <code>visitLineNumber</code> methods are called <i>after</i> the labels passed as arguments have been visited. 30 */ 31 public class MethodVisitor extends BaseWriter { 32 protected MethodVisitor() { 33 } 34 35 protected MethodVisitor(@NonNull ConstantPoolGeneration cp, int methodAccess) { 36 super(cp, methodAccess); 37 } 38 39 /** 40 * Visits an annotation on a parameter of the method being visited. 41 * 42 * @param parameter 43 * the parameter index 44 * @param desc 45 * the descriptor of the annotation type 46 * 47 * @return a visitor to visit the annotation values, or <code>null</code> if this visitor is not interested in 48 * visiting this annotation 49 */ 50 @Nullable 51 public AnnotationVisitor visitParameterAnnotation(@NonNegative int parameter, @NonNull String desc) { 52 return null; 53 } 54 55 /** 56 * Visits a zero operand instruction. 57 * 58 * @param opcode 59 * the {@linkplain Opcodes opcode} of the instruction to be visited: NOP, ACONST_NULL, ICONST_M1, 60 * ICONST_0 ICONST_0 to ICONST_5, LCONST_0, LCONST_1, FCONST_0 to FCONST_2, DCONST_0, DCONST_1, IALOAD, 61 * LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, 62 * BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, 63 * FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, 64 * DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, 65 * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, 66 * DCMPG, IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or 67 * MONITOREXIT 68 */ 69 public void visitInsn(int opcode) { 70 } 71 72 /** 73 * Visits an instruction with a single <code>int</code> operand. 74 * 75 * @param opcode 76 * the {@linkplain Opcodes opcode} of the instruction to be visited: BIPUSH, SIPUSH, or NEWARRAY 77 * @param operand 78 * the operand of the instruction to be visited: when opcode is BIPUSH, it's between 79 * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE}; when opcode is SIPUSH, it's between 80 * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE}; when opcode is NEWARRAY, the operand value is one 81 * of the {@link ArrayElementType} values 82 */ 83 public void visitIntInsn(int opcode, int operand) { 84 } 85 86 /** 87 * Visits a local variable instruction, which loads or stores the value of a local variable. 88 * 89 * @param opcode 90 * the {@linkplain Opcodes opcode} of the local variable instruction to be visited: ILOAD, LLOAD, FLOAD, 91 * DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET 92 * @param varIndex 93 * the operand of the instruction to be visited, which is the index of a local variable 94 */ 95 public void visitVarInsn(int opcode, @NonNegative int varIndex) { 96 } 97 98 /** 99 * Visits a type instruction, which takes the internal name of a class as parameter. 100 * 101 * @param opcode 102 * the {@linkplain Opcodes opcode} of the instruction to be visited: NEW, ANEWARRAY, CHECKCAST, or 103 * INSTANCEOF 104 * @param typeDesc 105 * the operand of the instruction, which is the internal name of an object or array class 106 */ 107 public void visitTypeInsn(int opcode, @NonNull String typeDesc) { 108 } 109 110 /** 111 * Visits a field access instruction, which loads or stores the value of a field of an object or a class. 112 * 113 * @param opcode 114 * the {@linkplain Opcodes opcode} of the instruction to be visited: GETSTATIC, PUTSTATIC, GETFIELD, or 115 * PUTFIELD 116 * @param owner 117 * the internal name of the field's owner class 118 * @param name 119 * the field's name 120 * @param desc 121 * the field's descriptor (see {@link JavaType}) 122 */ 123 public void visitFieldInsn(int opcode, @NonNull String owner, @NonNull String name, @NonNull String desc) { 124 } 125 126 /** 127 * Visits a method invocation instruction, which invokes a method or constructor. 128 * 129 * @param opcode 130 * the {@linkplain Opcodes opcode} of the instruction: INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, or 131 * INVOKEINTERFACE 132 * @param owner 133 * the internal name of the method's owner class 134 * @param name 135 * the method's name 136 * @param desc 137 * the method's descriptor (see {@link JavaType}) 138 * @param itf 139 * whether the method's owner class is an interface or not 140 */ 141 public void visitMethodInsn(int opcode, @NonNull String owner, @NonNull String name, @NonNull String desc, 142 boolean itf) { 143 } 144 145 /** 146 * Visits an {@link Opcodes#INVOKEDYNAMIC INVOKEDYNAMIC} instruction. 147 * 148 * @param name 149 * the method's name 150 * @param desc 151 * the method's descriptor (see {@link JavaType}) 152 * @param bsm 153 * the bootstrap method 154 * @param bsmArgs 155 * the bootstrap method constant arguments, where each argument must be an {@link Integer}, 156 * {@link Float}, {@link Long}, {@link Double}, {@link String}, {@link JavaType}, or {@link MethodHandle} 157 * value 158 */ 159 public void visitInvokeDynamicInsn(@NonNull String name, @NonNull String desc, @NonNull MethodHandle bsm, 160 @NonNull Object... bsmArgs) { 161 } 162 163 /** 164 * Visits a jump instruction. 165 * 166 * @param opcode 167 * the {@linkplain Opcodes opcode} of the jump instruction to be visited: IFEQ, IFNE, IFLT, IFGE, IFGT, 168 * IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, 169 * JSR, IFNULL, or IFNONNULL 170 * @param label 171 * the operand of the instruction to be visited, which is a label that designates the instruction to 172 * which the jump instruction may jump 173 */ 174 public void visitJumpInsn(int opcode, @NonNull Label label) { 175 } 176 177 /** 178 * Visits a label, which designates the instruction that will be visited just after it. 179 */ 180 public void visitLabel(@NonNull Label label) { 181 } 182 183 /** 184 * Visits a {@link Opcodes#LDC LDC} instruction. 185 * 186 * @param cst 187 * the constant to be loaded on the stack, which must be a non null 188 * {@link Integer}/{@link Float}/{@link Long}/{@link Double}/{@link String}, an {@link ObjectType} or 189 * {@link ArrayType} for <code>.class</code> constants, a {@link MethodType}, or a {@link MethodHandle} 190 */ 191 public void visitLdcInsn(@NonNull Object cst) { 192 } 193 194 /** 195 * Visits an {@link Opcodes#IINC IINC} instruction. 196 * 197 * @param varIndex 198 * index of the local variable to be incremented 199 * @param increment 200 * amount to increment the local variable by 201 */ 202 public void visitIincInsn(@NonNegative int varIndex, int increment) { 203 } 204 205 /** 206 * Visits a {@link Opcodes#TABLESWITCH TABLESWITCH} instruction. 207 * 208 * @param min 209 * the minimum key value 210 * @param max 211 * the maximum key value 212 * @param dflt 213 * beginning of the default handler block 214 * @param labels 215 * beginnings of the handler blocks; <code>labels[i]</code> is the beginning of the handler block for the 216 * <code>min + i</code> key 217 */ 218 public void visitTableSwitchInsn(int min, int max, @NonNull Label dflt, @NonNull Label... labels) { 219 } 220 221 /** 222 * Visits a {@link Opcodes#LOOKUPSWITCH LOOKUPSWITCH} instruction. 223 * 224 * @param dflt 225 * beginning of the default handler block 226 * @param keys 227 * the values of the keys 228 * @param labels 229 * beginnings of the handler blocks; <code>labels[i]</code> is the beginning of the handler block for the 230 * <code>keys[i]</code> 231 */ 232 public void visitLookupSwitchInsn(@NonNull Label dflt, @NonNull int[] keys, @NonNull Label[] labels) { 233 } 234 235 /** 236 * Visits a {@link Opcodes#MULTIANEWARRAY MULTIANEWARRAY} instruction. 237 * 238 * @param desc 239 * an array type descriptor (see {@link ArrayType}) 240 * @param dims 241 * number of dimensions of the array to allocate 242 */ 243 public void visitMultiANewArrayInsn(@NonNull String desc, @NonNegative int dims) { 244 } 245 246 /** 247 * Visits a <code>try..catch</code> block. 248 * 249 * @param start 250 * beginning of the exception handler's scope (inclusive) 251 * @param end 252 * end of the exception handler's scope (exclusive) 253 * @param handler 254 * beginning of the exception handler's code 255 * @param type 256 * internal name of the type of exceptions handled by the handler, or <code>null</code> to catch any 257 * exceptions (for "finally" blocks) 258 */ 259 public void visitTryCatchBlock(@NonNull Label start, @NonNull Label end, @NonNull Label handler, 260 @Nullable String type) { 261 } 262 263 /** 264 * Visits a local variable declaration. 265 * 266 * @param name 267 * the name of the local variable 268 * @param desc 269 * the type descriptor of the local variable 270 * @param signature 271 * the type signature of the local variable; <code>null</code> when the local variable type does not use 272 * generic types 273 * @param start 274 * the first instruction corresponding to the scope of this local variable (inclusive) 275 * @param end 276 * the last instruction corresponding to the scope of this local variable (exclusive) 277 * @param index 278 * the local variable's index 279 */ 280 public void visitLocalVariable(@NonNull String name, @NonNull String desc, @Nullable String signature, 281 @NonNull Label start, @NonNull Label end, @NonNegative int index) { 282 } 283 284 /** 285 * Visits a line number within the body of the method. 286 * 287 * @param line 288 * a line number, which refers to the source file from which the class was compiled 289 * @param start 290 * the first instruction corresponding to this line number 291 */ 292 public void visitLineNumber(@NonNegative int line, @NonNull Label start) { 293 } 294 295 /** 296 * Visits the maximum stack size of the method. 297 */ 298 public void visitMaxStack(@NonNegative int maxStack) { 299 } 300 }