1 // ASM: a very small and fast Java bytecode manipulation framework 2 // Copyright (c) 2000-2011 INRIA, France Telecom 3 // All rights reserved. 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions 7 // are met: 8 // 1. Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // 2. Redistributions in binary form must reproduce the above copyright 11 // notice, this list of conditions and the following disclaimer in the 12 // documentation and/or other materials provided with the distribution. 13 // 3. Neither the name of the copyright holders nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 // THE POSSIBILITY OF SUCH DAMAGE. 28 package org.objectweb.asm.tree; 29 30 import java.util.Map; 31 import org.objectweb.asm.MethodVisitor; 32 import org.objectweb.asm.Opcodes; 33 34 /** 35 * A node that represents a method instruction. A method instruction is an instruction that invokes 36 * a method. 37 * 38 * @author Eric Bruneton 39 */ 40 public class MethodInsnNode extends AbstractInsnNode { 41 42 /** 43 * The internal name of the method's owner class (see {@link 44 * org.objectweb.asm.Type#getInternalName()}). 45 * 46 * <p>For methods of arrays, e.g., {@code clone()}, the array type descriptor. 47 */ 48 public String owner; 49 50 /** The method's name. */ 51 public String name; 52 53 /** The method's descriptor (see {@link org.objectweb.asm.Type}). */ 54 public String desc; 55 56 /** Whether the method's owner class if an interface. */ 57 public boolean itf; 58 59 /** 60 * Constructs a new {@link MethodInsnNode}. 61 * 62 * @param opcode the opcode of the type instruction to be constructed. This opcode must be 63 * INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE. 64 * @param owner the internal name of the method's owner class (see {@link 65 * org.objectweb.asm.Type#getInternalName()}). 66 * @param name the method's name. 67 * @param descriptor the method's descriptor (see {@link org.objectweb.asm.Type}). 68 */ MethodInsnNode( final int opcode, final String owner, final String name, final String descriptor)69 public MethodInsnNode( 70 final int opcode, final String owner, final String name, final String descriptor) { 71 this(opcode, owner, name, descriptor, opcode == Opcodes.INVOKEINTERFACE); 72 } 73 74 /** 75 * Constructs a new {@link MethodInsnNode}. 76 * 77 * @param opcode the opcode of the type instruction to be constructed. This opcode must be 78 * INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE. 79 * @param owner the internal name of the method's owner class (see {@link 80 * org.objectweb.asm.Type#getInternalName()}). 81 * @param name the method's name. 82 * @param descriptor the method's descriptor (see {@link org.objectweb.asm.Type}). 83 * @param isInterface if the method's owner class is an interface. 84 */ MethodInsnNode( final int opcode, final String owner, final String name, final String descriptor, final boolean isInterface)85 public MethodInsnNode( 86 final int opcode, 87 final String owner, 88 final String name, 89 final String descriptor, 90 final boolean isInterface) { 91 super(opcode); 92 this.owner = owner; 93 this.name = name; 94 this.desc = descriptor; 95 this.itf = isInterface; 96 } 97 98 /** 99 * Sets the opcode of this instruction. 100 * 101 * @param opcode the new instruction opcode. This opcode must be INVOKEVIRTUAL, INVOKESPECIAL, 102 * INVOKESTATIC or INVOKEINTERFACE. 103 */ setOpcode(final int opcode)104 public void setOpcode(final int opcode) { 105 this.opcode = opcode; 106 } 107 108 @Override getType()109 public int getType() { 110 return METHOD_INSN; 111 } 112 113 @Override accept(final MethodVisitor methodVisitor)114 public void accept(final MethodVisitor methodVisitor) { 115 methodVisitor.visitMethodInsn(opcode, owner, name, desc, itf); 116 acceptAnnotations(methodVisitor); 117 } 118 119 @Override clone(final Map<LabelNode, LabelNode> clonedLabels)120 public AbstractInsnNode clone(final Map<LabelNode, LabelNode> clonedLabels) { 121 return new MethodInsnNode(opcode, owner, name, desc, itf).cloneAnnotations(this); 122 } 123 } 124