    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.generic;
    019
    020import org.apache.bcel.ExceptionConst;
    021
    022/**
    023 * Super class for instructions dealing with array access such as IALOAD.
    024 *
    025 * @version $Id: ArrayInstruction.java 1812166 2017-10-13 23:48:11Z ggregory $
    026 */
    027public abstract class ArrayInstruction extends Instruction implements ExceptionThrower,
    028        TypedInstruction {
    029
    030    /**
    031     * Empty constructor needed for Instruction.readInstruction.
    032     * Not to be used otherwise.
    033     */
    034    ArrayInstruction() {
    035    }
    036
    037
    038    /**
    039     * @param opcode of instruction
    040     */
    041    protected ArrayInstruction(final short opcode) {
    042        super(opcode, (short) 1);
    043    }
    044
    045
    046    @Override
    047    public Class<?>[] getExceptions() {
    048        return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_ARRAY_EXCEPTION);
    049    }
    050
    051
    052    /** @return type associated with the instruction
    053     */
    054    @Override
    055    public Type getType( final ConstantPoolGen cp ) {
    056        final short _opcode = super.getOpcode();
    057        switch (_opcode) {
    058            case org.apache.bcel.Const.IALOAD:
    059            case org.apache.bcel.Const.IASTORE:
    060                return Type.INT;
    061            case org.apache.bcel.Const.CALOAD:
    062            case org.apache.bcel.Const.CASTORE:
    063                return Type.CHAR;
    064            case org.apache.bcel.Const.BALOAD:
    065            case org.apache.bcel.Const.BASTORE:
    066                return Type.BYTE;
    067            case org.apache.bcel.Const.SALOAD:
    068            case org.apache.bcel.Const.SASTORE:
    069                return Type.SHORT;
    070            case org.apache.bcel.Const.LALOAD:
    071            case org.apache.bcel.Const.LASTORE:
    072                return Type.LONG;
    073            case org.apache.bcel.Const.DALOAD:
    074            case org.apache.bcel.Const.DASTORE:
    075                return Type.DOUBLE;
    076            case org.apache.bcel.Const.FALOAD:
    077            case org.apache.bcel.Const.FASTORE:
    078                return Type.FLOAT;
    079            case org.apache.bcel.Const.AALOAD:
    080            case org.apache.bcel.Const.AASTORE:
    081                return Type.OBJECT;
    082            default:
    083                throw new ClassGenException("Oops: unknown case in switch" + _opcode);
    084        }
    085    }
    086}