Path: blob/master/src/java.base/share/classes/jdk/internal/org/objectweb/asm/MethodVisitor.java
42362 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* This file is available under and governed by the GNU General Public26* License version 2 only, as published by the Free Software Foundation.27* However, the following notice accompanied the original version of this28* file:29*30* ASM: a very small and fast Java bytecode manipulation framework31* Copyright (c) 2000-2011 INRIA, France Telecom32* All rights reserved.33*34* Redistribution and use in source and binary forms, with or without35* modification, are permitted provided that the following conditions36* are met:37* 1. Redistributions of source code must retain the above copyright38* notice, this list of conditions and the following disclaimer.39* 2. Redistributions in binary form must reproduce the above copyright40* notice, this list of conditions and the following disclaimer in the41* documentation and/or other materials provided with the distribution.42* 3. Neither the name of the copyright holders nor the names of its43* contributors may be used to endorse or promote products derived from44* this software without specific prior written permission.45*46* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"47* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE48* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE49* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE50* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR51* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF52* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS53* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN54* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)55* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF56* THE POSSIBILITY OF SUCH DAMAGE.57*/58package jdk.internal.org.objectweb.asm;5960/**61* A visitor to visit a Java method. The methods of this class must be called in the following62* order: ( {@code visitParameter} )* [ {@code visitAnnotationDefault} ] ( {@code visitAnnotation} |63* {@code visitAnnotableParameterCount} | {@code visitParameterAnnotation} {@code64* visitTypeAnnotation} | {@code visitAttribute} )* [ {@code visitCode} ( {@code visitFrame} |65* {@code visit<i>X</i>Insn} | {@code visitLabel} | {@code visitInsnAnnotation} | {@code66* visitTryCatchBlock} | {@code visitTryCatchAnnotation} | {@code visitLocalVariable} | {@code67* visitLocalVariableAnnotation} | {@code visitLineNumber} )* {@code visitMaxs} ] {@code visitEnd}.68* In addition, the {@code visit<i>X</i>Insn} and {@code visitLabel} methods must be called in the69* sequential order of the bytecode instructions of the visited code, {@code visitInsnAnnotation}70* must be called <i>after</i> the annotated instruction, {@code visitTryCatchBlock} must be called71* <i>before</i> the labels passed as arguments have been visited, {@code72* visitTryCatchBlockAnnotation} must be called <i>after</i> the corresponding try catch block has73* been visited, and the {@code visitLocalVariable}, {@code visitLocalVariableAnnotation} and {@code74* visitLineNumber} methods must be called <i>after</i> the labels passed as arguments have been75* visited.76*77* @author Eric Bruneton78*/79public abstract class MethodVisitor {8081private static final String REQUIRES_ASM5 = "This feature requires ASM5";8283/**84* The ASM API version implemented by this visitor. The value of this field must be one of {@link85* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.86*/87protected final int api;8889/**90* The method visitor to which this visitor must delegate method calls. May be {@literal null}.91*/92protected MethodVisitor mv;9394/**95* Constructs a new {@link MethodVisitor}.96*97* @param api the ASM API version implemented by this visitor. Must be one of {@link98* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.99*/100public MethodVisitor(final int api) {101this(api, null);102}103104/**105* Constructs a new {@link MethodVisitor}.106*107* @param api the ASM API version implemented by this visitor. Must be one of {@link108* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.109* @param methodVisitor the method visitor to which this visitor must delegate method calls. May110* be null.111*/112@SuppressWarnings("deprecation")113public MethodVisitor(final int api, final MethodVisitor methodVisitor) {114if (api != Opcodes.ASM8115&& api != Opcodes.ASM7116&& api != Opcodes.ASM6117&& api != Opcodes.ASM5118&& api != Opcodes.ASM4119&& api != Opcodes.ASM9_EXPERIMENTAL) {120throw new IllegalArgumentException("Unsupported api " + api);121}122if (api == Opcodes.ASM9_EXPERIMENTAL) {123Constants.checkAsmExperimental(this);124}125this.api = api;126this.mv = methodVisitor;127}128129// -----------------------------------------------------------------------------------------------130// Parameters, annotations and non standard attributes131// -----------------------------------------------------------------------------------------------132133/**134* Visits a parameter of this method.135*136* @param name parameter name or {@literal null} if none is provided.137* @param access the parameter's access flags, only {@code ACC_FINAL}, {@code ACC_SYNTHETIC}138* or/and {@code ACC_MANDATED} are allowed (see {@link Opcodes}).139*/140public void visitParameter(final String name, final int access) {141if (api < Opcodes.ASM5) {142throw new UnsupportedOperationException(REQUIRES_ASM5);143}144if (mv != null) {145mv.visitParameter(name, access);146}147}148149/**150* Visits the default value of this annotation interface method.151*152* @return a visitor to the visit the actual default value of this annotation interface method, or153* {@literal null} if this visitor is not interested in visiting this default value. The154* 'name' parameters passed to the methods of this annotation visitor are ignored. Moreover,155* exacly one visit method must be called on this annotation visitor, followed by visitEnd.156*/157public AnnotationVisitor visitAnnotationDefault() {158if (mv != null) {159return mv.visitAnnotationDefault();160}161return null;162}163164/**165* Visits an annotation of this method.166*167* @param descriptor the class descriptor of the annotation class.168* @param visible {@literal true} if the annotation is visible at runtime.169* @return a visitor to visit the annotation values, or {@literal null} if this visitor is not170* interested in visiting this annotation.171*/172public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {173if (mv != null) {174return mv.visitAnnotation(descriptor, visible);175}176return null;177}178179/**180* Visits an annotation on a type in the method signature.181*182* @param typeRef a reference to the annotated type. The sort of this type reference must be183* {@link TypeReference#METHOD_TYPE_PARAMETER}, {@link184* TypeReference#METHOD_TYPE_PARAMETER_BOUND}, {@link TypeReference#METHOD_RETURN}, {@link185* TypeReference#METHOD_RECEIVER}, {@link TypeReference#METHOD_FORMAL_PARAMETER} or {@link186* TypeReference#THROWS}. See {@link TypeReference}.187* @param typePath the path to the annotated type argument, wildcard bound, array element type, or188* static inner type within 'typeRef'. May be {@literal null} if the annotation targets189* 'typeRef' as a whole.190* @param descriptor the class descriptor of the annotation class.191* @param visible {@literal true} if the annotation is visible at runtime.192* @return a visitor to visit the annotation values, or {@literal null} if this visitor is not193* interested in visiting this annotation.194*/195public AnnotationVisitor visitTypeAnnotation(196final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {197if (api < Opcodes.ASM5) {198throw new UnsupportedOperationException(REQUIRES_ASM5);199}200if (mv != null) {201return mv.visitTypeAnnotation(typeRef, typePath, descriptor, visible);202}203return null;204}205206/**207* Visits the number of method parameters that can have annotations. By default (i.e. when this208* method is not called), all the method parameters defined by the method descriptor can have209* annotations.210*211* @param parameterCount the number of method parameters than can have annotations. This number212* must be less or equal than the number of parameter types in the method descriptor. It can213* be strictly less when a method has synthetic parameters and when these parameters are214* ignored when computing parameter indices for the purpose of parameter annotations (see215* https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.18).216* @param visible {@literal true} to define the number of method parameters that can have217* annotations visible at runtime, {@literal false} to define the number of method parameters218* that can have annotations invisible at runtime.219*/220public void visitAnnotableParameterCount(final int parameterCount, final boolean visible) {221if (mv != null) {222mv.visitAnnotableParameterCount(parameterCount, visible);223}224}225226/**227* Visits an annotation of a parameter this method.228*229* @param parameter the parameter index. This index must be strictly smaller than the number of230* parameters in the method descriptor, and strictly smaller than the parameter count231* specified in {@link #visitAnnotableParameterCount}. Important note: <i>a parameter index i232* is not required to correspond to the i'th parameter descriptor in the method233* descriptor</i>, in particular in case of synthetic parameters (see234* https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.18).235* @param descriptor the class descriptor of the annotation class.236* @param visible {@literal true} if the annotation is visible at runtime.237* @return a visitor to visit the annotation values, or {@literal null} if this visitor is not238* interested in visiting this annotation.239*/240public AnnotationVisitor visitParameterAnnotation(241final int parameter, final String descriptor, final boolean visible) {242if (mv != null) {243return mv.visitParameterAnnotation(parameter, descriptor, visible);244}245return null;246}247248/**249* Visits a non standard attribute of this method.250*251* @param attribute an attribute.252*/253public void visitAttribute(final Attribute attribute) {254if (mv != null) {255mv.visitAttribute(attribute);256}257}258259/** Starts the visit of the method's code, if any (i.e. non abstract method). */260public void visitCode() {261if (mv != null) {262mv.visitCode();263}264}265266/**267* Visits the current state of the local variables and operand stack elements. This method must(*)268* be called <i>just before</i> any instruction <b>i</b> that follows an unconditional branch269* instruction such as GOTO or THROW, that is the target of a jump instruction, or that starts an270* exception handler block. The visited types must describe the values of the local variables and271* of the operand stack elements <i>just before</i> <b>i</b> is executed.<br>272* <br>273* (*) this is mandatory only for classes whose version is greater than or equal to {@link274* Opcodes#V1_6}. <br>275* <br>276* The frames of a method must be given either in expanded form, or in compressed form (all frames277* must use the same format, i.e. you must not mix expanded and compressed frames within a single278* method):279*280* <ul>281* <li>In expanded form, all frames must have the F_NEW type.282* <li>In compressed form, frames are basically "deltas" from the state of the previous frame:283* <ul>284* <li>{@link Opcodes#F_SAME} representing frame with exactly the same locals as the285* previous frame and with the empty stack.286* <li>{@link Opcodes#F_SAME1} representing frame with exactly the same locals as the287* previous frame and with single value on the stack ( <code>numStack</code> is 1 and288* <code>stack[0]</code> contains value for the type of the stack item).289* <li>{@link Opcodes#F_APPEND} representing frame with current locals are the same as the290* locals in the previous frame, except that additional locals are defined (<code>291* numLocal</code> is 1, 2 or 3 and <code>local</code> elements contains values292* representing added types).293* <li>{@link Opcodes#F_CHOP} representing frame with current locals are the same as the294* locals in the previous frame, except that the last 1-3 locals are absent and with295* the empty stack (<code>numLocal</code> is 1, 2 or 3).296* <li>{@link Opcodes#F_FULL} representing complete frame data.297* </ul>298* </ul>299*300* <br>301* In both cases the first frame, corresponding to the method's parameters and access flags, is302* implicit and must not be visited. Also, it is illegal to visit two or more frames for the same303* code location (i.e., at least one instruction must be visited between two calls to visitFrame).304*305* @param type the type of this stack map frame. Must be {@link Opcodes#F_NEW} for expanded306* frames, or {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND}, {@link Opcodes#F_CHOP}, {@link307* Opcodes#F_SAME} or {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed frames.308* @param numLocal the number of local variables in the visited frame.309* @param local the local variable types in this frame. This array must not be modified. Primitive310* types are represented by {@link Opcodes#TOP}, {@link Opcodes#INTEGER}, {@link311* Opcodes#FLOAT}, {@link Opcodes#LONG}, {@link Opcodes#DOUBLE}, {@link Opcodes#NULL} or312* {@link Opcodes#UNINITIALIZED_THIS} (long and double are represented by a single element).313* Reference types are represented by String objects (representing internal names), and314* uninitialized types by Label objects (this label designates the NEW instruction that315* created this uninitialized value).316* @param numStack the number of operand stack elements in the visited frame.317* @param stack the operand stack types in this frame. This array must not be modified. Its318* content has the same format as the "local" array.319* @throws IllegalStateException if a frame is visited just after another one, without any320* instruction between the two (unless this frame is a Opcodes#F_SAME frame, in which case it321* is silently ignored).322*/323public void visitFrame(324final int type,325final int numLocal,326final Object[] local,327final int numStack,328final Object[] stack) {329if (mv != null) {330mv.visitFrame(type, numLocal, local, numStack, stack);331}332}333334// -----------------------------------------------------------------------------------------------335// Normal instructions336// -----------------------------------------------------------------------------------------------337338/**339* Visits a zero operand instruction.340*341* @param opcode the opcode of the instruction to be visited. This opcode is either NOP,342* ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5,343* LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD,344* FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE,345* AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2,346* SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,347* FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR,348* LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I,349* D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN,350* DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.351*/352public void visitInsn(final int opcode) {353if (mv != null) {354mv.visitInsn(opcode);355}356}357358/**359* Visits an instruction with a single int operand.360*361* @param opcode the opcode of the instruction to be visited. This opcode is either BIPUSH, SIPUSH362* or NEWARRAY.363* @param operand the operand of the instruction to be visited.<br>364* When opcode is BIPUSH, operand value should be between Byte.MIN_VALUE and Byte.MAX_VALUE.365* <br>366* When opcode is SIPUSH, operand value should be between Short.MIN_VALUE and Short.MAX_VALUE.367* <br>368* When opcode is NEWARRAY, operand value should be one of {@link Opcodes#T_BOOLEAN}, {@link369* Opcodes#T_CHAR}, {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE}, {@link Opcodes#T_BYTE},370* {@link Opcodes#T_SHORT}, {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.371*/372public void visitIntInsn(final int opcode, final int operand) {373if (mv != null) {374mv.visitIntInsn(opcode, operand);375}376}377378/**379* Visits a local variable instruction. A local variable instruction is an instruction that loads380* or stores the value of a local variable.381*382* @param opcode the opcode of the local variable instruction to be visited. This opcode is either383* ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.384* @param var the operand of the instruction to be visited. This operand is the index of a local385* variable.386*/387public void visitVarInsn(final int opcode, final int var) {388if (mv != null) {389mv.visitVarInsn(opcode, var);390}391}392393/**394* Visits a type instruction. A type instruction is an instruction that takes the internal name of395* a class as parameter.396*397* @param opcode the opcode of the type instruction to be visited. This opcode is either NEW,398* ANEWARRAY, CHECKCAST or INSTANCEOF.399* @param type the operand of the instruction to be visited. This operand must be the internal400* name of an object or array class (see {@link Type#getInternalName()}).401*/402public void visitTypeInsn(final int opcode, final String type) {403if (mv != null) {404mv.visitTypeInsn(opcode, type);405}406}407408/**409* Visits a field instruction. A field instruction is an instruction that loads or stores the410* value of a field of an object.411*412* @param opcode the opcode of the type instruction to be visited. This opcode is either413* GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.414* @param owner the internal name of the field's owner class (see {@link Type#getInternalName()}).415* @param name the field's name.416* @param descriptor the field's descriptor (see {@link Type}).417*/418public void visitFieldInsn(419final int opcode, final String owner, final String name, final String descriptor) {420if (mv != null) {421mv.visitFieldInsn(opcode, owner, name, descriptor);422}423}424425/**426* Visits a method instruction. A method instruction is an instruction that invokes a method.427*428* @param opcode the opcode of the type instruction to be visited. This opcode is either429* INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.430* @param owner the internal name of the method's owner class (see {@link431* Type#getInternalName()}).432* @param name the method's name.433* @param descriptor the method's descriptor (see {@link Type}).434* @deprecated use {@link #visitMethodInsn(int, String, String, String, boolean)} instead.435*/436@Deprecated437public void visitMethodInsn(438final int opcode, final String owner, final String name, final String descriptor) {439int opcodeAndSource = opcode | (api < Opcodes.ASM5 ? Opcodes.SOURCE_DEPRECATED : 0);440visitMethodInsn(opcodeAndSource, owner, name, descriptor, opcode == Opcodes.INVOKEINTERFACE);441}442443/**444* Visits a method instruction. A method instruction is an instruction that invokes a method.445*446* @param opcode the opcode of the type instruction to be visited. This opcode is either447* INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.448* @param owner the internal name of the method's owner class (see {@link449* Type#getInternalName()}).450* @param name the method's name.451* @param descriptor the method's descriptor (see {@link Type}).452* @param isInterface if the method's owner class is an interface.453*/454public void visitMethodInsn(455final int opcode,456final String owner,457final String name,458final String descriptor,459final boolean isInterface) {460if (api < Opcodes.ASM5 && (opcode & Opcodes.SOURCE_DEPRECATED) == 0) {461if (isInterface != (opcode == Opcodes.INVOKEINTERFACE)) {462throw new UnsupportedOperationException("INVOKESPECIAL/STATIC on interfaces requires ASM5");463}464visitMethodInsn(opcode, owner, name, descriptor);465return;466}467if (mv != null) {468mv.visitMethodInsn(opcode & ~Opcodes.SOURCE_MASK, owner, name, descriptor, isInterface);469}470}471472/**473* Visits an invokedynamic instruction.474*475* @param name the method's name.476* @param descriptor the method's descriptor (see {@link Type}).477* @param bootstrapMethodHandle the bootstrap method.478* @param bootstrapMethodArguments the bootstrap method constant arguments. Each argument must be479* an {@link Integer}, {@link Float}, {@link Long}, {@link Double}, {@link String}, {@link480* Type}, {@link Handle} or {@link ConstantDynamic} value. This method is allowed to modify481* the content of the array so a caller should expect that this array may change.482*/483public void visitInvokeDynamicInsn(484final String name,485final String descriptor,486final Handle bootstrapMethodHandle,487final Object... bootstrapMethodArguments) {488if (api < Opcodes.ASM5) {489throw new UnsupportedOperationException(REQUIRES_ASM5);490}491if (mv != null) {492mv.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);493}494}495496/**497* Visits a jump instruction. A jump instruction is an instruction that may jump to another498* instruction.499*500* @param opcode the opcode of the type instruction to be visited. This opcode is either IFEQ,501* IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT,502* IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.503* @param label the operand of the instruction to be visited. This operand is a label that504* designates the instruction to which the jump instruction may jump.505*/506public void visitJumpInsn(final int opcode, final Label label) {507if (mv != null) {508mv.visitJumpInsn(opcode, label);509}510}511512/**513* Visits a label. A label designates the instruction that will be visited just after it.514*515* @param label a {@link Label} object.516*/517public void visitLabel(final Label label) {518if (mv != null) {519mv.visitLabel(label);520}521}522523// -----------------------------------------------------------------------------------------------524// Special instructions525// -----------------------------------------------------------------------------------------------526527/**528* Visits a LDC instruction. Note that new constant types may be added in future versions of the529* Java Virtual Machine. To easily detect new constant types, implementations of this method530* should check for unexpected constant types, like this:531*532* <pre>533* if (cst instanceof Integer) {534* // ...535* } else if (cst instanceof Float) {536* // ...537* } else if (cst instanceof Long) {538* // ...539* } else if (cst instanceof Double) {540* // ...541* } else if (cst instanceof String) {542* // ...543* } else if (cst instanceof Type) {544* int sort = ((Type) cst).getSort();545* if (sort == Type.OBJECT) {546* // ...547* } else if (sort == Type.ARRAY) {548* // ...549* } else if (sort == Type.METHOD) {550* // ...551* } else {552* // throw an exception553* }554* } else if (cst instanceof Handle) {555* // ...556* } else if (cst instanceof ConstantDynamic) {557* // ...558* } else {559* // throw an exception560* }561* </pre>562*563* @param value the constant to be loaded on the stack. This parameter must be a non null {@link564* Integer}, a {@link Float}, a {@link Long}, a {@link Double}, a {@link String}, a {@link565* Type} of OBJECT or ARRAY sort for {@code .class} constants, for classes whose version is566* 49, a {@link Type} of METHOD sort for MethodType, a {@link Handle} for MethodHandle567* constants, for classes whose version is 51 or a {@link ConstantDynamic} for a constant568* dynamic for classes whose version is 55.569*/570public void visitLdcInsn(final Object value) {571if (api < Opcodes.ASM5572&& (value instanceof Handle573|| (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) {574throw new UnsupportedOperationException(REQUIRES_ASM5);575}576if (api < Opcodes.ASM7 && value instanceof ConstantDynamic) {577throw new UnsupportedOperationException("This feature requires ASM7");578}579if (mv != null) {580mv.visitLdcInsn(value);581}582}583584/**585* Visits an IINC instruction.586*587* @param var index of the local variable to be incremented.588* @param increment amount to increment the local variable by.589*/590public void visitIincInsn(final int var, final int increment) {591if (mv != null) {592mv.visitIincInsn(var, increment);593}594}595596/**597* Visits a TABLESWITCH instruction.598*599* @param min the minimum key value.600* @param max the maximum key value.601* @param dflt beginning of the default handler block.602* @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the603* handler block for the {@code min + i} key.604*/605public void visitTableSwitchInsn(606final int min, final int max, final Label dflt, final Label... labels) {607if (mv != null) {608mv.visitTableSwitchInsn(min, max, dflt, labels);609}610}611612/**613* Visits a LOOKUPSWITCH instruction.614*615* @param dflt beginning of the default handler block.616* @param keys the values of the keys.617* @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the618* handler block for the {@code keys[i]} key.619*/620public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) {621if (mv != null) {622mv.visitLookupSwitchInsn(dflt, keys, labels);623}624}625626/**627* Visits a MULTIANEWARRAY instruction.628*629* @param descriptor an array type descriptor (see {@link Type}).630* @param numDimensions the number of dimensions of the array to allocate.631*/632public void visitMultiANewArrayInsn(final String descriptor, final int numDimensions) {633if (mv != null) {634mv.visitMultiANewArrayInsn(descriptor, numDimensions);635}636}637638/**639* Visits an annotation on an instruction. This method must be called just <i>after</i> the640* annotated instruction. It can be called several times for the same instruction.641*642* @param typeRef a reference to the annotated type. The sort of this type reference must be643* {@link TypeReference#INSTANCEOF}, {@link TypeReference#NEW}, {@link644* TypeReference#CONSTRUCTOR_REFERENCE}, {@link TypeReference#METHOD_REFERENCE}, {@link645* TypeReference#CAST}, {@link TypeReference#CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT}, {@link646* TypeReference#METHOD_INVOCATION_TYPE_ARGUMENT}, {@link647* TypeReference#CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT}, or {@link648* TypeReference#METHOD_REFERENCE_TYPE_ARGUMENT}. See {@link TypeReference}.649* @param typePath the path to the annotated type argument, wildcard bound, array element type, or650* static inner type within 'typeRef'. May be {@literal null} if the annotation targets651* 'typeRef' as a whole.652* @param descriptor the class descriptor of the annotation class.653* @param visible {@literal true} if the annotation is visible at runtime.654* @return a visitor to visit the annotation values, or {@literal null} if this visitor is not655* interested in visiting this annotation.656*/657public AnnotationVisitor visitInsnAnnotation(658final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {659if (api < Opcodes.ASM5) {660throw new UnsupportedOperationException(REQUIRES_ASM5);661}662if (mv != null) {663return mv.visitInsnAnnotation(typeRef, typePath, descriptor, visible);664}665return null;666}667668// -----------------------------------------------------------------------------------------------669// Exceptions table entries, debug information, max stack and max locals670// -----------------------------------------------------------------------------------------------671672/**673* Visits a try catch block.674*675* @param start the beginning of the exception handler's scope (inclusive).676* @param end the end of the exception handler's scope (exclusive).677* @param handler the beginning of the exception handler's code.678* @param type the internal name of the type of exceptions handled by the handler, or {@literal679* null} to catch any exceptions (for "finally" blocks).680* @throws IllegalArgumentException if one of the labels has already been visited by this visitor681* (by the {@link #visitLabel} method).682*/683public void visitTryCatchBlock(684final Label start, final Label end, final Label handler, final String type) {685if (mv != null) {686mv.visitTryCatchBlock(start, end, handler, type);687}688}689690/**691* Visits an annotation on an exception handler type. This method must be called <i>after</i> the692* {@link #visitTryCatchBlock} for the annotated exception handler. It can be called several times693* for the same exception handler.694*695* @param typeRef a reference to the annotated type. The sort of this type reference must be696* {@link TypeReference#EXCEPTION_PARAMETER}. See {@link TypeReference}.697* @param typePath the path to the annotated type argument, wildcard bound, array element type, or698* static inner type within 'typeRef'. May be {@literal null} if the annotation targets699* 'typeRef' as a whole.700* @param descriptor the class descriptor of the annotation class.701* @param visible {@literal true} if the annotation is visible at runtime.702* @return a visitor to visit the annotation values, or {@literal null} if this visitor is not703* interested in visiting this annotation.704*/705public AnnotationVisitor visitTryCatchAnnotation(706final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {707if (api < Opcodes.ASM5) {708throw new UnsupportedOperationException(REQUIRES_ASM5);709}710if (mv != null) {711return mv.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible);712}713return null;714}715716/**717* Visits a local variable declaration.718*719* @param name the name of a local variable.720* @param descriptor the type descriptor of this local variable.721* @param signature the type signature of this local variable. May be {@literal null} if the local722* variable type does not use generic types.723* @param start the first instruction corresponding to the scope of this local variable724* (inclusive).725* @param end the last instruction corresponding to the scope of this local variable (exclusive).726* @param index the local variable's index.727* @throws IllegalArgumentException if one of the labels has not already been visited by this728* visitor (by the {@link #visitLabel} method).729*/730public void visitLocalVariable(731final String name,732final String descriptor,733final String signature,734final Label start,735final Label end,736final int index) {737if (mv != null) {738mv.visitLocalVariable(name, descriptor, signature, start, end, index);739}740}741742/**743* Visits an annotation on a local variable type.744*745* @param typeRef a reference to the annotated type. The sort of this type reference must be746* {@link TypeReference#LOCAL_VARIABLE} or {@link TypeReference#RESOURCE_VARIABLE}. See {@link747* TypeReference}.748* @param typePath the path to the annotated type argument, wildcard bound, array element type, or749* static inner type within 'typeRef'. May be {@literal null} if the annotation targets750* 'typeRef' as a whole.751* @param start the fist instructions corresponding to the continuous ranges that make the scope752* of this local variable (inclusive).753* @param end the last instructions corresponding to the continuous ranges that make the scope of754* this local variable (exclusive). This array must have the same size as the 'start' array.755* @param index the local variable's index in each range. This array must have the same size as756* the 'start' array.757* @param descriptor the class descriptor of the annotation class.758* @param visible {@literal true} if the annotation is visible at runtime.759* @return a visitor to visit the annotation values, or {@literal null} if this visitor is not760* interested in visiting this annotation.761*/762public AnnotationVisitor visitLocalVariableAnnotation(763final int typeRef,764final TypePath typePath,765final Label[] start,766final Label[] end,767final int[] index,768final String descriptor,769final boolean visible) {770if (api < Opcodes.ASM5) {771throw new UnsupportedOperationException(REQUIRES_ASM5);772}773if (mv != null) {774return mv.visitLocalVariableAnnotation(775typeRef, typePath, start, end, index, descriptor, visible);776}777return null;778}779780/**781* Visits a line number declaration.782*783* @param line a line number. This number refers to the source file from which the class was784* compiled.785* @param start the first instruction corresponding to this line number.786* @throws IllegalArgumentException if {@code start} has not already been visited by this visitor787* (by the {@link #visitLabel} method).788*/789public void visitLineNumber(final int line, final Label start) {790if (mv != null) {791mv.visitLineNumber(line, start);792}793}794795/**796* Visits the maximum stack size and the maximum number of local variables of the method.797*798* @param maxStack maximum stack size of the method.799* @param maxLocals maximum number of local variables for the method.800*/801public void visitMaxs(final int maxStack, final int maxLocals) {802if (mv != null) {803mv.visitMaxs(maxStack, maxLocals);804}805}806807/**808* Visits the end of the method. This method, which is the last one to be called, is used to809* inform the visitor that all the annotations and attributes of the method have been visited.810*/811public void visitEnd() {812if (mv != null) {813mv.visitEnd();814}815}816}817818819