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 */ 30 public abstract class ArrayInstruction extends Instruction implements ExceptionThrower, 31 TypedInstruction { 32 33 /** 34 * Empty constructor needed for Instruction.readInstruction. 35 * Not to be used otherwise. 36 */ ArrayInstruction()37 ArrayInstruction() { 38 } 39 40 41 /** 42 * @param opcode of instruction 43 */ ArrayInstruction(final short opcode)44 protected ArrayInstruction(final short opcode) { 45 super(opcode, (short) 1); 46 } 47 48 49 @Override getExceptions()50 public Class<?>[] getExceptions() { 51 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_ARRAY_EXCEPTION); 52 } 53 54 55 /** @return type associated with the instruction 56 */ 57 @Override getType( final ConstantPoolGen cp )58 public Type getType( final ConstantPoolGen cp ) { 59 final short _opcode = super.getOpcode(); 60 switch (_opcode) { 61 case com.sun.org.apache.bcel.internal.Const.IALOAD: 62 case com.sun.org.apache.bcel.internal.Const.IASTORE: 63 return Type.INT; 64 case com.sun.org.apache.bcel.internal.Const.CALOAD: 65 case com.sun.org.apache.bcel.internal.Const.CASTORE: 66 return Type.CHAR; 67 case com.sun.org.apache.bcel.internal.Const.BALOAD: 68 case com.sun.org.apache.bcel.internal.Const.BASTORE: 69 return Type.BYTE; 70 case com.sun.org.apache.bcel.internal.Const.SALOAD: 71 case com.sun.org.apache.bcel.internal.Const.SASTORE: 72 return Type.SHORT; 73 case com.sun.org.apache.bcel.internal.Const.LALOAD: 74 case com.sun.org.apache.bcel.internal.Const.LASTORE: 75 return Type.LONG; 76 case com.sun.org.apache.bcel.internal.Const.DALOAD: 77 case com.sun.org.apache.bcel.internal.Const.DASTORE: 78 return Type.DOUBLE; 79 case com.sun.org.apache.bcel.internal.Const.FALOAD: 80 case com.sun.org.apache.bcel.internal.Const.FASTORE: 81 return Type.FLOAT; 82 case com.sun.org.apache.bcel.internal.Const.AALOAD: 83 case com.sun.org.apache.bcel.internal.Const.AASTORE: 84 return Type.OBJECT; 85 default: 86 throw new ClassGenException("Oops: unknown case in switch" + _opcode); 87 } 88 } 89 } 90