1/* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu) 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21package proguard.classfile.instruction; 22 23/** 24 * This Instruction represents a simple instruction without variable arguments 25 * or constant pool references. 26 * 27 * @author Eric Lafortune 28 */ 29public abstract class SwitchInstruction extends Instruction 30{ 31 public int defaultOffset; 32 public int[] jumpOffsets; 33 34 35 /** 36 * Creates an uninitialized SwitchInstruction. 37 */ 38 public SwitchInstruction() {} 39 40 41 /** 42 * Creates a new SwitchInstruction with the given arguments. 43 */ 44 public SwitchInstruction(byte opcode, 45 int defaultOffset, 46 int[] jumpOffsets) 47 { 48 this.opcode = opcode; 49 this.defaultOffset = defaultOffset; 50 this.jumpOffsets = jumpOffsets; 51 } 52 53 54 /** 55 * Copies the given instruction into this instruction. 56 * @param switchInstruction the instruction to be copied. 57 * @return this instruction. 58 */ 59 public SwitchInstruction copy(SwitchInstruction switchInstruction) 60 { 61 this.opcode = switchInstruction.opcode; 62 this.defaultOffset = switchInstruction.defaultOffset; 63 this.jumpOffsets = switchInstruction.jumpOffsets; 64 65 return this; 66 } 67 68 69 // Implementations for Instruction. 70 71 public String toString(int offset) 72 { 73 return "["+offset+"] "+toString()+" (target="+(offset+defaultOffset)+")"; 74 } 75 76 77 // Implementations for Object. 78 79 public String toString() 80 { 81 return getName()+" ("+jumpOffsets.length+" offsets, default="+defaultOffset+")"; 82 } 83} 84