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.List; 31 import java.util.Map; 32 import org.objectweb.asm.Label; 33 import org.objectweb.asm.MethodVisitor; 34 import org.objectweb.asm.Opcodes; 35 36 /** 37 * A node that represents a TABLESWITCH instruction. 38 * 39 * @author Eric Bruneton 40 */ 41 public class TableSwitchInsnNode extends AbstractInsnNode { 42 43 /** The minimum key value. */ 44 public int min; 45 46 /** The maximum key value. */ 47 public int max; 48 49 /** Beginning of the default handler block. */ 50 public LabelNode dflt; 51 52 /** Beginnings of the handler blocks. This list is a list of {@link LabelNode} objects. */ 53 public List<LabelNode> labels; 54 55 /** 56 * Constructs a new {@link TableSwitchInsnNode}. 57 * 58 * @param min the minimum key value. 59 * @param max the maximum key value. 60 * @param dflt beginning of the default handler block. 61 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the 62 * handler block for the {@code min + i} key. 63 */ TableSwitchInsnNode( final int min, final int max, final LabelNode dflt, final LabelNode... labels)64 public TableSwitchInsnNode( 65 final int min, final int max, final LabelNode dflt, final LabelNode... labels) { 66 super(Opcodes.TABLESWITCH); 67 this.min = min; 68 this.max = max; 69 this.dflt = dflt; 70 this.labels = Util.asArrayList(labels); 71 } 72 73 @Override getType()74 public int getType() { 75 return TABLESWITCH_INSN; 76 } 77 78 @Override accept(final MethodVisitor methodVisitor)79 public void accept(final MethodVisitor methodVisitor) { 80 Label[] labelsArray = new Label[this.labels.size()]; 81 for (int i = 0, n = labelsArray.length; i < n; ++i) { 82 labelsArray[i] = this.labels.get(i).getLabel(); 83 } 84 methodVisitor.visitTableSwitchInsn(min, max, dflt.getLabel(), labelsArray); 85 acceptAnnotations(methodVisitor); 86 } 87 88 @Override clone(final Map<LabelNode, LabelNode> clonedLabels)89 public AbstractInsnNode clone(final Map<LabelNode, LabelNode> clonedLabels) { 90 return new TableSwitchInsnNode(min, max, clone(dflt, clonedLabels), clone(labels, clonedLabels)) 91 .cloneAnnotations(this); 92 } 93 } 94