1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * This file is available under and governed by the GNU General Public
  27  * License version 2 only, as published by the Free Software Foundation.
  28  * However, the following notice accompanied the original version of this
  29  * file:
  30  *
  31  * ASM: a very small and fast Java bytecode manipulation framework
  32  * Copyright (c) 2000-2011 INRIA, France Telecom
  33  * All rights reserved.
  34  *
  35  * Redistribution and use in source and binary forms, with or without
  36  * modification, are permitted provided that the following conditions
  37  * are met:
  38  * 1. Redistributions of source code must retain the above copyright
  39  *    notice, this list of conditions and the following disclaimer.
  40  * 2. Redistributions in binary form must reproduce the above copyright
  41  *    notice, this list of conditions and the following disclaimer in the
  42  *    documentation and/or other materials provided with the distribution.
  43  * 3. Neither the name of the copyright holders nor the names of its
  44  *    contributors may be used to endorse or promote products derived from
  45  *    this software without specific prior written permission.
  46  *
  47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm;
  60 
  61 /**
  62  * A visitor to visit a Java method. The methods of this class must be called in
  63  * the following order: ( <tt>visitParameter</tt> )* [
  64  * <tt>visitAnnotationDefault</tt> ] ( <tt>visitAnnotation</tt> |
  65  * <tt>visitTypeAnnotation</tt> | <tt>visitAttribute</tt> )* [
  66  * <tt>visitCode</tt> ( <tt>visitFrame</tt> | <tt>visit<i>X</i>Insn</tt> |
  67  * <tt>visitLabel</tt> | <tt>visitInsnAnnotation</tt> |
  68  * <tt>visitTryCatchBlock</tt> | <tt>visitTryCatchBlockAnnotation</tt> |
  69  * <tt>visitLocalVariable</tt> | <tt>visitLocalVariableAnnotation</tt> |
  70  * <tt>visitLineNumber</tt> )* <tt>visitMaxs</tt> ] <tt>visitEnd</tt>. In
  71  * addition, the <tt>visit<i>X</i>Insn</tt> and <tt>visitLabel</tt> methods must
  72  * be called in the sequential order of the bytecode instructions of the visited
  73  * code, <tt>visitInsnAnnotation</tt> must be called <i>after</i> the annotated
  74  * instruction, <tt>visitTryCatchBlock</tt> must be called <i>before</i> the
  75  * labels passed as arguments have been visited,
  76  * <tt>visitTryCatchBlockAnnotation</tt> must be called <i>after</i> the
  77  * corresponding try catch block has been visited, and the
  78  * <tt>visitLocalVariable</tt>, <tt>visitLocalVariableAnnotation</tt> and
  79  * <tt>visitLineNumber</tt> methods must be called <i>after</i> the labels
  80  * passed as arguments have been visited.
  81  *
  82  * @author Eric Bruneton
  83  */
  84 public abstract class MethodVisitor {
  85 
  86     /**
  87      * The ASM API version implemented by this visitor. The value of this field
  88      * must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
  89      */
  90     protected final int api;
  91 
  92     /**
  93      * The method visitor to which this visitor must delegate method calls. May
  94      * be null.
  95      */
  96     protected MethodVisitor mv;
  97 
  98     /**
  99      * Constructs a new {@link MethodVisitor}.
 100      *
 101      * @param api
 102      *            the ASM API version implemented by this visitor. Must be one
 103      *            of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
 104      */
 105     public MethodVisitor(final int api) {
 106         this(api, null);
 107     }
 108 
 109     /**
 110      * Constructs a new {@link MethodVisitor}.
 111      *
 112      * @param api
 113      *            the ASM API version implemented by this visitor. Must be one
 114      *            of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
 115      * @param mv
 116      *            the method visitor to which this visitor must delegate method
 117      *            calls. May be null.
 118      */
 119     public MethodVisitor(final int api, final MethodVisitor mv) {
 120         if (api != Opcodes.ASM4 && api != Opcodes.ASM5) {
 121             throw new IllegalArgumentException();
 122         }
 123         this.api = api;
 124         this.mv = mv;
 125     }
 126 
 127     // -------------------------------------------------------------------------
 128     // Parameters, annotations and non standard attributes
 129     // -------------------------------------------------------------------------
 130 
 131     /**
 132      * Visits a parameter of this method.
 133      *
 134      * @param name
 135      *            parameter name or null if none is provided.
 136      * @param access
 137      *            the parameter's access flags, only <tt>ACC_FINAL</tt>,
 138      *            <tt>ACC_SYNTHETIC</tt> or/and <tt>ACC_MANDATED</tt> are
 139      *            allowed (see {@link Opcodes}).
 140      */
 141     public void visitParameter(String name, int access) {
 142         if (api < Opcodes.ASM5) {
 143             throw new RuntimeException();
 144         }
 145         if (mv != null) {
 146             mv.visitParameter(name, access);
 147         }
 148     }
 149 
 150     /**
 151      * Visits the default value of this annotation interface method.
 152      *
 153      * @return a visitor to the visit the actual default value of this
 154      *         annotation interface method, or <tt>null</tt> if this visitor is
 155      *         not interested in visiting this default value. The 'name'
 156      *         parameters passed to the methods of this annotation visitor are
 157      *         ignored. Moreover, exacly one visit method must be called on this
 158      *         annotation visitor, followed by visitEnd.
 159      */
 160     public AnnotationVisitor visitAnnotationDefault() {
 161         if (mv != null) {
 162             return mv.visitAnnotationDefault();
 163         }
 164         return null;
 165     }
 166 
 167     /**
 168      * Visits an annotation of this method.
 169      *
 170      * @param desc
 171      *            the class descriptor of the annotation class.
 172      * @param visible
 173      *            <tt>true</tt> if the annotation is visible at runtime.
 174      * @return a visitor to visit the annotation values, or <tt>null</tt> if
 175      *         this visitor is not interested in visiting this annotation.
 176      */
 177     public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
 178         if (mv != null) {
 179             return mv.visitAnnotation(desc, visible);
 180         }
 181         return null;
 182     }
 183 
 184     /**
 185      * Visits an annotation on a type in the method signature.
 186      *
 187      * @param typeRef
 188      *            a reference to the annotated type. The sort of this type
 189      *            reference must be {@link TypeReference#METHOD_TYPE_PARAMETER
 190      *            METHOD_TYPE_PARAMETER},
 191      *            {@link TypeReference#METHOD_TYPE_PARAMETER_BOUND
 192      *            METHOD_TYPE_PARAMETER_BOUND},
 193      *            {@link TypeReference#METHOD_RETURN METHOD_RETURN},
 194      *            {@link TypeReference#METHOD_RECEIVER METHOD_RECEIVER},
 195      *            {@link TypeReference#METHOD_FORMAL_PARAMETER
 196      *            METHOD_FORMAL_PARAMETER} or {@link TypeReference#THROWS
 197      *            THROWS}. See {@link TypeReference}.
 198      * @param typePath
 199      *            the path to the annotated type argument, wildcard bound, array
 200      *            element type, or static inner type within 'typeRef'. May be
 201      *            <tt>null</tt> if the annotation targets 'typeRef' as a whole.
 202      * @param desc
 203      *            the class descriptor of the annotation class.
 204      * @param visible
 205      *            <tt>true</tt> if the annotation is visible at runtime.
 206      * @return a visitor to visit the annotation values, or <tt>null</tt> if
 207      *         this visitor is not interested in visiting this annotation.
 208      */
 209     public AnnotationVisitor visitTypeAnnotation(int typeRef,
 210             TypePath typePath, String desc, boolean visible) {
 211         if (api < Opcodes.ASM5) {
 212             throw new RuntimeException();
 213         }
 214         if (mv != null) {
 215             return mv.visitTypeAnnotation(typeRef, typePath, desc, visible);
 216         }
 217         return null;
 218     }
 219 
 220     /**
 221      * Visits an annotation of a parameter this method.
 222      *
 223      * @param parameter
 224      *            the parameter index.
 225      * @param desc
 226      *            the class descriptor of the annotation class.
 227      * @param visible
 228      *            <tt>true</tt> if the annotation is visible at runtime.
 229      * @return a visitor to visit the annotation values, or <tt>null</tt> if
 230      *         this visitor is not interested in visiting this annotation.
 231      */
 232     public AnnotationVisitor visitParameterAnnotation(int parameter,
 233             String desc, boolean visible) {
 234         if (mv != null) {
 235             return mv.visitParameterAnnotation(parameter, desc, visible);
 236         }
 237         return null;
 238     }
 239 
 240     /**
 241      * Visits a non standard attribute of this method.
 242      *
 243      * @param attr
 244      *            an attribute.
 245      */
 246     public void visitAttribute(Attribute attr) {
 247         if (mv != null) {
 248             mv.visitAttribute(attr);
 249         }
 250     }
 251 
 252     /**
 253      * Starts the visit of the method's code, if any (i.e. non abstract method).
 254      */
 255     public void visitCode() {
 256         if (mv != null) {
 257             mv.visitCode();
 258         }
 259     }
 260 
 261     /**
 262      * Visits the current state of the local variables and operand stack
 263      * elements. This method must(*) be called <i>just before</i> any
 264      * instruction <b>i</b> that follows an unconditional branch instruction
 265      * such as GOTO or THROW, that is the target of a jump instruction, or that
 266      * starts an exception handler block. The visited types must describe the
 267      * values of the local variables and of the operand stack elements <i>just
 268      * before</i> <b>i</b> is executed.<br>
 269      * <br>
 270      * (*) this is mandatory only for classes whose version is greater than or
 271      * equal to {@link Opcodes#V1_6 V1_6}. <br>
 272      * <br>
 273      * The frames of a method must be given either in expanded form, or in
 274      * compressed form (all frames must use the same format, i.e. you must not
 275      * mix expanded and compressed frames within a single method):
 276      * <ul>
 277      * <li>In expanded form, all frames must have the F_NEW type.</li>
 278      * <li>In compressed form, frames are basically "deltas" from the state of
 279      * the previous frame:
 280      * <ul>
 281      * <li>{@link Opcodes#F_SAME} representing frame with exactly the same
 282      * locals as the previous frame and with the empty stack.</li>
 283      * <li>{@link Opcodes#F_SAME1} representing frame with exactly the same
 284      * locals as the previous frame and with single value on the stack (
 285      * <code>nStack</code> is 1 and <code>stack[0]</code> contains value for the
 286      * type of the stack item).</li>
 287      * <li>{@link Opcodes#F_APPEND} representing frame with current locals are
 288      * the same as the locals in the previous frame, except that additional
 289      * locals are defined (<code>nLocal</code> is 1, 2 or 3 and
 290      * <code>local</code> elements contains values representing added types).</li>
 291      * <li>{@link Opcodes#F_CHOP} representing frame with current locals are the
 292      * same as the locals in the previous frame, except that the last 1-3 locals
 293      * are absent and with the empty stack (<code>nLocals</code> is 1, 2 or 3).</li>
 294      * <li>{@link Opcodes#F_FULL} representing complete frame data.</li>
 295      * </ul>
 296      * </li>
 297      * </ul>
 298      * <br>
 299      * In both cases the first frame, corresponding to the method's parameters
 300      * and access flags, is implicit and must not be visited. Also, it is
 301      * illegal to visit two or more frames for the same code location (i.e., at
 302      * least one instruction must be visited between two calls to visitFrame).
 303      *
 304      * @param type
 305      *            the type of this stack map frame. Must be
 306      *            {@link Opcodes#F_NEW} for expanded frames, or
 307      *            {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
 308      *            {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
 309      *            {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for
 310      *            compressed frames.
 311      * @param nLocal
 312      *            the number of local variables in the visited frame.
 313      * @param local
 314      *            the local variable types in this frame. This array must not be
 315      *            modified. Primitive types are represented by
 316      *            {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
 317      *            {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
 318      *            {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
 319      *            {@link Opcodes#UNINITIALIZED_THIS} (long and double are
 320      *            represented by a single element). Reference types are
 321      *            represented by String objects (representing internal names),
 322      *            and uninitialized types by Label objects (this label
 323      *            designates the NEW instruction that created this uninitialized
 324      *            value).
 325      * @param nStack
 326      *            the number of operand stack elements in the visited frame.
 327      * @param stack
 328      *            the operand stack types in this frame. This array must not be
 329      *            modified. Its content has the same format as the "local"
 330      *            array.
 331      * @throws IllegalStateException
 332      *             if a frame is visited just after another one, without any
 333      *             instruction between the two (unless this frame is a
 334      *             Opcodes#F_SAME frame, in which case it is silently ignored).
 335      */
 336     public void visitFrame(int type, int nLocal, Object[] local, int nStack,
 337             Object[] stack) {
 338         if (mv != null) {
 339             mv.visitFrame(type, nLocal, local, nStack, stack);
 340         }
 341     }
 342 
 343     // -------------------------------------------------------------------------
 344     // Normal instructions
 345     // -------------------------------------------------------------------------
 346 
 347     /**
 348      * Visits a zero operand instruction.
 349      *
 350      * @param opcode
 351      *            the opcode of the instruction to be visited. This opcode is
 352      *            either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1,
 353      *            ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1,
 354      *            FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD,
 355      *            LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
 356      *            IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
 357      *            SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1,
 358      *            DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB,
 359      *            IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM,
 360      *            FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR,
 361      *            IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D,
 362      *            L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S,
 363      *            LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN,
 364      *            DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER,
 365      *            or MONITOREXIT.
 366      */
 367     public void visitInsn(int opcode) {
 368         if (mv != null) {
 369             mv.visitInsn(opcode);
 370         }
 371     }
 372 
 373     /**
 374      * Visits an instruction with a single int operand.
 375      *
 376      * @param opcode
 377      *            the opcode of the instruction to be visited. This opcode is
 378      *            either BIPUSH, SIPUSH or NEWARRAY.
 379      * @param operand
 380      *            the operand of the instruction to be visited.<br>
 381      *            When opcode is BIPUSH, operand value should be between
 382      *            Byte.MIN_VALUE and Byte.MAX_VALUE.<br>
 383      *            When opcode is SIPUSH, operand value should be between
 384      *            Short.MIN_VALUE and Short.MAX_VALUE.<br>
 385      *            When opcode is NEWARRAY, operand value should be one of
 386      *            {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
 387      *            {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
 388      *            {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
 389      *            {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
 390      */
 391     public void visitIntInsn(int opcode, int operand) {
 392         if (mv != null) {
 393             mv.visitIntInsn(opcode, operand);
 394         }
 395     }
 396 
 397     /**
 398      * Visits a local variable instruction. A local variable instruction is an
 399      * instruction that loads or stores the value of a local variable.
 400      *
 401      * @param opcode
 402      *            the opcode of the local variable instruction to be visited.
 403      *            This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD,
 404      *            ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
 405      * @param var
 406      *            the operand of the instruction to be visited. This operand is
 407      *            the index of a local variable.
 408      */
 409     public void visitVarInsn(int opcode, int var) {
 410         if (mv != null) {
 411             mv.visitVarInsn(opcode, var);
 412         }
 413     }
 414 
 415     /**
 416      * Visits a type instruction. A type instruction is an instruction that
 417      * takes the internal name of a class as parameter.
 418      *
 419      * @param opcode
 420      *            the opcode of the type instruction to be visited. This opcode
 421      *            is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
 422      * @param type
 423      *            the operand of the instruction to be visited. This operand
 424      *            must be the internal name of an object or array class (see
 425      *            {@link Type#getInternalName() getInternalName}).
 426      */
 427     public void visitTypeInsn(int opcode, String type) {
 428         if (mv != null) {
 429             mv.visitTypeInsn(opcode, type);
 430         }
 431     }
 432 
 433     /**
 434      * Visits a field instruction. A field instruction is an instruction that
 435      * loads or stores the value of a field of an object.
 436      *
 437      * @param opcode
 438      *            the opcode of the type instruction to be visited. This opcode
 439      *            is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
 440      * @param owner
 441      *            the internal name of the field's owner class (see
 442      *            {@link Type#getInternalName() getInternalName}).
 443      * @param name
 444      *            the field's name.
 445      * @param desc
 446      *            the field's descriptor (see {@link Type Type}).
 447      */
 448     public void visitFieldInsn(int opcode, String owner, String name,
 449             String desc) {
 450         if (mv != null) {
 451             mv.visitFieldInsn(opcode, owner, name, desc);
 452         }
 453     }
 454 
 455     /**
 456      * Visits a method instruction. A method instruction is an instruction that
 457      * invokes a method.
 458      *
 459      * @param opcode
 460      *            the opcode of the type instruction to be visited. This opcode
 461      *            is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
 462      *            INVOKEINTERFACE.
 463      * @param owner
 464      *            the internal name of the method's owner class (see
 465      *            {@link Type#getInternalName() getInternalName}).
 466      * @param name
 467      *            the method's name.
 468      * @param desc
 469      *            the method's descriptor (see {@link Type Type}).
 470      */
 471     @Deprecated
 472     public void visitMethodInsn(int opcode, String owner, String name,
 473             String desc) {
 474         if (api >= Opcodes.ASM5) {
 475             boolean itf = opcode == Opcodes.INVOKEINTERFACE;
 476             visitMethodInsn(opcode, owner, name, desc, itf);
 477             return;
 478         }
 479         if (mv != null) {
 480             mv.visitMethodInsn(opcode, owner, name, desc);
 481         }
 482     }
 483 
 484     /**
 485      * Visits a method instruction. A method instruction is an instruction that
 486      * invokes a method.
 487      *
 488      * @param opcode
 489      *            the opcode of the type instruction to be visited. This opcode
 490      *            is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
 491      *            INVOKEINTERFACE.
 492      * @param owner
 493      *            the internal name of the method's owner class (see
 494      *            {@link Type#getInternalName() getInternalName}).
 495      * @param name
 496      *            the method's name.
 497      * @param desc
 498      *            the method's descriptor (see {@link Type Type}).
 499      * @param itf
 500      *            if the method's owner class is an interface.
 501      */
 502     public void visitMethodInsn(int opcode, String owner, String name,
 503             String desc, boolean itf) {
 504         if (api < Opcodes.ASM5) {
 505             if (itf != (opcode == Opcodes.INVOKEINTERFACE)) {
 506                 throw new IllegalArgumentException(
 507                         "INVOKESPECIAL/STATIC on interfaces require ASM 5");
 508             }
 509             visitMethodInsn(opcode, owner, name, desc);
 510             return;
 511         }
 512         if (mv != null) {
 513             mv.visitMethodInsn(opcode, owner, name, desc, itf);
 514         }
 515     }
 516 
 517     /**
 518      * Visits an invokedynamic instruction.
 519      *
 520      * @param name
 521      *            the method's name.
 522      * @param desc
 523      *            the method's descriptor (see {@link Type Type}).
 524      * @param bsm
 525      *            the bootstrap method.
 526      * @param bsmArgs
 527      *            the bootstrap method constant arguments. Each argument must be
 528      *            an {@link Integer}, {@link Float}, {@link Long},
 529      *            {@link Double}, {@link String}, {@link Type} or {@link Handle}
 530      *            value. This method is allowed to modify the content of the
 531      *            array so a caller should expect that this array may change.
 532      */
 533     public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
 534             Object... bsmArgs) {
 535         if (mv != null) {
 536             mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
 537         }
 538     }
 539 
 540     /**
 541      * Visits a jump instruction. A jump instruction is an instruction that may
 542      * jump to another instruction.
 543      *
 544      * @param opcode
 545      *            the opcode of the type instruction to be visited. This opcode
 546      *            is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
 547      *            IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
 548      *            IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
 549      * @param label
 550      *            the operand of the instruction to be visited. This operand is
 551      *            a label that designates the instruction to which the jump
 552      *            instruction may jump.
 553      */
 554     public void visitJumpInsn(int opcode, Label label) {
 555         if (mv != null) {
 556             mv.visitJumpInsn(opcode, label);
 557         }
 558     }
 559 
 560     /**
 561      * Visits a label. A label designates the instruction that will be visited
 562      * just after it.
 563      *
 564      * @param label
 565      *            a {@link Label Label} object.
 566      */
 567     public void visitLabel(Label label) {
 568         if (mv != null) {
 569             mv.visitLabel(label);
 570         }
 571     }
 572 
 573     // -------------------------------------------------------------------------
 574     // Special instructions
 575     // -------------------------------------------------------------------------
 576 
 577     /**
 578      * Visits a LDC instruction. Note that new constant types may be added in
 579      * future versions of the Java Virtual Machine. To easily detect new
 580      * constant types, implementations of this method should check for
 581      * unexpected constant types, like this:
 582      *
 583      * <pre>
 584      * if (cst instanceof Integer) {
 585      *     // ...
 586      * } else if (cst instanceof Float) {
 587      *     // ...
 588      * } else if (cst instanceof Long) {
 589      *     // ...
 590      * } else if (cst instanceof Double) {
 591      *     // ...
 592      * } else if (cst instanceof String) {
 593      *     // ...
 594      * } else if (cst instanceof Type) {
 595      *     int sort = ((Type) cst).getSort();
 596      *     if (sort == Type.OBJECT) {
 597      *         // ...
 598      *     } else if (sort == Type.ARRAY) {
 599      *         // ...
 600      *     } else if (sort == Type.METHOD) {
 601      *         // ...
 602      *     } else {
 603      *         // throw an exception
 604      *     }
 605      * } else if (cst instanceof Handle) {
 606      *     // ...
 607      * } else {
 608      *     // throw an exception
 609      * }
 610      * </pre>
 611      *
 612      * @param cst
 613      *            the constant to be loaded on the stack. This parameter must be
 614      *            a non null {@link Integer}, a {@link Float}, a {@link Long}, a
 615      *            {@link Double}, a {@link String}, a {@link Type} of OBJECT or
 616      *            ARRAY sort for <tt>.class</tt> constants, for classes whose
 617      *            version is 49.0, a {@link Type} of METHOD sort or a
 618      *            {@link Handle} for MethodType and MethodHandle constants, for
 619      *            classes whose version is 51.0.
 620      */
 621     public void visitLdcInsn(Object cst) {
 622         if (mv != null) {
 623             mv.visitLdcInsn(cst);
 624         }
 625     }
 626 
 627     /**
 628      * Visits an IINC instruction.
 629      *
 630      * @param var
 631      *            index of the local variable to be incremented.
 632      * @param increment
 633      *            amount to increment the local variable by.
 634      */
 635     public void visitIincInsn(int var, int increment) {
 636         if (mv != null) {
 637             mv.visitIincInsn(var, increment);
 638         }
 639     }
 640 
 641     /**
 642      * Visits a TABLESWITCH instruction.
 643      *
 644      * @param min
 645      *            the minimum key value.
 646      * @param max
 647      *            the maximum key value.
 648      * @param dflt
 649      *            beginning of the default handler block.
 650      * @param labels
 651      *            beginnings of the handler blocks. <tt>labels[i]</tt> is the
 652      *            beginning of the handler block for the <tt>min + i</tt> key.
 653      */
 654     public void visitTableSwitchInsn(int min, int max, Label dflt,
 655             Label... labels) {
 656         if (mv != null) {
 657             mv.visitTableSwitchInsn(min, max, dflt, labels);
 658         }
 659     }
 660 
 661     /**
 662      * Visits a LOOKUPSWITCH instruction.
 663      *
 664      * @param dflt
 665      *            beginning of the default handler block.
 666      * @param keys
 667      *            the values of the keys.
 668      * @param labels
 669      *            beginnings of the handler blocks. <tt>labels[i]</tt> is the
 670      *            beginning of the handler block for the <tt>keys[i]</tt> key.
 671      */
 672     public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
 673         if (mv != null) {
 674             mv.visitLookupSwitchInsn(dflt, keys, labels);
 675         }
 676     }
 677 
 678     /**
 679      * Visits a MULTIANEWARRAY instruction.
 680      *
 681      * @param desc
 682      *            an array type descriptor (see {@link Type Type}).
 683      * @param dims
 684      *            number of dimensions of the array to allocate.
 685      */
 686     public void visitMultiANewArrayInsn(String desc, int dims) {
 687         if (mv != null) {
 688             mv.visitMultiANewArrayInsn(desc, dims);
 689         }
 690     }
 691 
 692     /**
 693      * Visits an annotation on an instruction. This method must be called just
 694      * <i>after</i> the annotated instruction. It can be called several times
 695      * for the same instruction.
 696      *
 697      * @param typeRef
 698      *            a reference to the annotated type. The sort of this type
 699      *            reference must be {@link TypeReference#INSTANCEOF INSTANCEOF},
 700      *            {@link TypeReference#NEW NEW},
 701      *            {@link TypeReference#CONSTRUCTOR_REFERENCE
 702      *            CONSTRUCTOR_REFERENCE}, {@link TypeReference#METHOD_REFERENCE
 703      *            METHOD_REFERENCE}, {@link TypeReference#CAST CAST},
 704      *            {@link TypeReference#CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
 705      *            CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT},
 706      *            {@link TypeReference#METHOD_INVOCATION_TYPE_ARGUMENT
 707      *            METHOD_INVOCATION_TYPE_ARGUMENT},
 708      *            {@link TypeReference#CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
 709      *            CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT}, or
 710      *            {@link TypeReference#METHOD_REFERENCE_TYPE_ARGUMENT
 711      *            METHOD_REFERENCE_TYPE_ARGUMENT}. See {@link TypeReference}.
 712      * @param typePath
 713      *            the path to the annotated type argument, wildcard bound, array
 714      *            element type, or static inner type within 'typeRef'. May be
 715      *            <tt>null</tt> if the annotation targets 'typeRef' as a whole.
 716      * @param desc
 717      *            the class descriptor of the annotation class.
 718      * @param visible
 719      *            <tt>true</tt> if the annotation is visible at runtime.
 720      * @return a visitor to visit the annotation values, or <tt>null</tt> if
 721      *         this visitor is not interested in visiting this annotation.
 722      */
 723     public AnnotationVisitor visitInsnAnnotation(int typeRef,
 724             TypePath typePath, String desc, boolean visible) {
 725         if (api < Opcodes.ASM5) {
 726             throw new RuntimeException();
 727         }
 728         if (mv != null) {
 729             return mv.visitInsnAnnotation(typeRef, typePath, desc, visible);
 730         }
 731         return null;
 732     }
 733 
 734     // -------------------------------------------------------------------------
 735     // Exceptions table entries, debug information, max stack and max locals
 736     // -------------------------------------------------------------------------
 737 
 738     /**
 739      * Visits a try catch block.
 740      *
 741      * @param start
 742      *            beginning of the exception handler's scope (inclusive).
 743      * @param end
 744      *            end of the exception handler's scope (exclusive).
 745      * @param handler
 746      *            beginning of the exception handler's code.
 747      * @param type
 748      *            internal name of the type of exceptions handled by the
 749      *            handler, or <tt>null</tt> to catch any exceptions (for
 750      *            "finally" blocks).
 751      * @throws IllegalArgumentException
 752      *             if one of the labels has already been visited by this visitor
 753      *             (by the {@link #visitLabel visitLabel} method).
 754      */
 755     public void visitTryCatchBlock(Label start, Label end, Label handler,
 756             String type) {
 757         if (mv != null) {
 758             mv.visitTryCatchBlock(start, end, handler, type);
 759         }
 760     }
 761 
 762     /**
 763      * Visits an annotation on an exception handler type. This method must be
 764      * called <i>after</i> the {@link #visitTryCatchBlock} for the annotated
 765      * exception handler. It can be called several times for the same exception
 766      * handler.
 767      *
 768      * @param typeRef
 769      *            a reference to the annotated type. The sort of this type
 770      *            reference must be {@link TypeReference#EXCEPTION_PARAMETER
 771      *            EXCEPTION_PARAMETER}. See {@link TypeReference}.
 772      * @param typePath
 773      *            the path to the annotated type argument, wildcard bound, array
 774      *            element type, or static inner type within 'typeRef'. May be
 775      *            <tt>null</tt> if the annotation targets 'typeRef' as a whole.
 776      * @param desc
 777      *            the class descriptor of the annotation class.
 778      * @param visible
 779      *            <tt>true</tt> if the annotation is visible at runtime.
 780      * @return a visitor to visit the annotation values, or <tt>null</tt> if
 781      *         this visitor is not interested in visiting this annotation.
 782      */
 783     public AnnotationVisitor visitTryCatchAnnotation(int typeRef,
 784             TypePath typePath, String desc, boolean visible) {
 785         if (api < Opcodes.ASM5) {
 786             throw new RuntimeException();
 787         }
 788         if (mv != null) {
 789             return mv.visitTryCatchAnnotation(typeRef, typePath, desc, visible);
 790         }
 791         return null;
 792     }
 793 
 794     /**
 795      * Visits a local variable declaration.
 796      *
 797      * @param name
 798      *            the name of a local variable.
 799      * @param desc
 800      *            the type descriptor of this local variable.
 801      * @param signature
 802      *            the type signature of this local variable. May be
 803      *            <tt>null</tt> if the local variable type does not use generic
 804      *            types.
 805      * @param start
 806      *            the first instruction corresponding to the scope of this local
 807      *            variable (inclusive).
 808      * @param end
 809      *            the last instruction corresponding to the scope of this local
 810      *            variable (exclusive).
 811      * @param index
 812      *            the local variable's index.
 813      * @throws IllegalArgumentException
 814      *             if one of the labels has not already been visited by this
 815      *             visitor (by the {@link #visitLabel visitLabel} method).
 816      */
 817     public void visitLocalVariable(String name, String desc, String signature,
 818             Label start, Label end, int index) {
 819         if (mv != null) {
 820             mv.visitLocalVariable(name, desc, signature, start, end, index);
 821         }
 822     }
 823 
 824     /**
 825      * Visits an annotation on a local variable type.
 826      *
 827      * @param typeRef
 828      *            a reference to the annotated type. The sort of this type
 829      *            reference must be {@link TypeReference#LOCAL_VARIABLE
 830      *            LOCAL_VARIABLE} or {@link TypeReference#RESOURCE_VARIABLE
 831      *            RESOURCE_VARIABLE}. See {@link TypeReference}.
 832      * @param typePath
 833      *            the path to the annotated type argument, wildcard bound, array
 834      *            element type, or static inner type within 'typeRef'. May be
 835      *            <tt>null</tt> if the annotation targets 'typeRef' as a whole.
 836      * @param start
 837      *            the fist instructions corresponding to the continuous ranges
 838      *            that make the scope of this local variable (inclusive).
 839      * @param end
 840      *            the last instructions corresponding to the continuous ranges
 841      *            that make the scope of this local variable (exclusive). This
 842      *            array must have the same size as the 'start' array.
 843      * @param index
 844      *            the local variable's index in each range. This array must have
 845      *            the same size as the 'start' array.
 846      * @param desc
 847      *            the class descriptor of the annotation class.
 848      * @param visible
 849      *            <tt>true</tt> if the annotation is visible at runtime.
 850      * @return a visitor to visit the annotation values, or <tt>null</tt> if
 851      *         this visitor is not interested in visiting this annotation.
 852      */
 853     public AnnotationVisitor visitLocalVariableAnnotation(int typeRef,
 854             TypePath typePath, Label[] start, Label[] end, int[] index,
 855             String desc, boolean visible) {
 856         if (api < Opcodes.ASM5) {
 857             throw new RuntimeException();
 858         }
 859         if (mv != null) {
 860             return mv.visitLocalVariableAnnotation(typeRef, typePath, start,
 861                     end, index, desc, visible);
 862         }
 863         return null;
 864     }
 865 
 866     /**
 867      * Visits a line number declaration.
 868      *
 869      * @param line
 870      *            a line number. This number refers to the source file from
 871      *            which the class was compiled.
 872      * @param start
 873      *            the first instruction corresponding to this line number.
 874      * @throws IllegalArgumentException
 875      *             if <tt>start</tt> has not already been visited by this
 876      *             visitor (by the {@link #visitLabel visitLabel} method).
 877      */
 878     public void visitLineNumber(int line, Label start) {
 879         if (mv != null) {
 880             mv.visitLineNumber(line, start);
 881         }
 882     }
 883 
 884     /**
 885      * Visits the maximum stack size and the maximum number of local variables
 886      * of the method.
 887      *
 888      * @param maxStack
 889      *            maximum stack size of the method.
 890      * @param maxLocals
 891      *            maximum number of local variables for the method.
 892      */
 893     public void visitMaxs(int maxStack, int maxLocals) {
 894         if (mv != null) {
 895             mv.visitMaxs(maxStack, maxLocals);
 896         }
 897     }
 898 
 899     /**
 900      * Visits the end of the method. This method, which is the last one to be
 901      * called, is used to inform the visitor that all the annotations and
 902      * attributes of the method have been visited.
 903      */
 904     public void visitEnd() {
 905         if (mv != null) {
 906             mv.visitEnd();
 907         }
 908     }
 909 }