1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.generic; 23 24 import com.sun.org.apache.bcel.internal.ExceptionConst; 25 26 /** 27 * Super class for instructions dealing with array access such as IALOAD. 28 * 29 * @version $Id: ArrayInstruction.java 1747278 2016-06-07 17:28:43Z britter $ 30 */ 31 public abstract class ArrayInstruction extends Instruction implements ExceptionThrower, 32 TypedInstruction { 33 34 /** 35 * Empty constructor needed for the Class.newInstance() statement in 36 * Instruction.readInstruction(). Not to be used otherwise. 37 */ 38 ArrayInstruction() { 39 } 40 41 42 /** 43 * @param opcode of instruction 44 */ 45 protected ArrayInstruction(final short opcode) { 46 super(opcode, (short) 1); 47 } 48 49 50 @Override 51 public Class<?>[] getExceptions() { 52 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_ARRAY_EXCEPTION); 53 } 54 55 56 /** @return type associated with the instruction 57 */ 58 @Override 59 public Type getType( final ConstantPoolGen cp ) { 60 final short _opcode = super.getOpcode(); 61 switch (_opcode) { 62 case com.sun.org.apache.bcel.internal.Const.IALOAD: 63 case com.sun.org.apache.bcel.internal.Const.IASTORE: 64 return Type.INT; 65 case com.sun.org.apache.bcel.internal.Const.CALOAD: 66 case com.sun.org.apache.bcel.internal.Const.CASTORE: 67 return Type.CHAR; 68 case com.sun.org.apache.bcel.internal.Const.BALOAD: 69 case com.sun.org.apache.bcel.internal.Const.BASTORE: 70 return Type.BYTE; 71 case com.sun.org.apache.bcel.internal.Const.SALOAD: 72 case com.sun.org.apache.bcel.internal.Const.SASTORE: 73 return Type.SHORT; 74 case com.sun.org.apache.bcel.internal.Const.LALOAD: 75 case com.sun.org.apache.bcel.internal.Const.LASTORE: 76 return Type.LONG; 77 case com.sun.org.apache.bcel.internal.Const.DALOAD: 78 case com.sun.org.apache.bcel.internal.Const.DASTORE: 79 return Type.DOUBLE; 80 case com.sun.org.apache.bcel.internal.Const.FALOAD: 81 case com.sun.org.apache.bcel.internal.Const.FASTORE: 82 return Type.FLOAT; 83 case com.sun.org.apache.bcel.internal.Const.AALOAD: 84 case com.sun.org.apache.bcel.internal.Const.AASTORE: 85 return Type.OBJECT; 86 default: 87 throw new ClassGenException("Oops: unknown case in switch" + _opcode); 88 } 89 } 90 }