    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.Const;
    021import org.apache.bcel.ExceptionConst;
    022
    023/**
    024 * Super class for the xRETURN family of instructions.
    025 *
    026 * @version $Id$
    027 */
    028public abstract class ReturnInstruction extends Instruction implements ExceptionThrower,
    029        TypedInstruction, StackConsumer {
    030
    031    /**
    032     * Empty constructor needed for Instruction.readInstruction.
    033     * Not to be used otherwise.
    034     */
    035    ReturnInstruction() {
    036    }
    037
    038
    039    /**
    040     * @param opcode of instruction
    041     */
    042    protected ReturnInstruction(final short opcode) {
    043        super(opcode, (short) 1);
    044    }
    045
    046
    047    public Type getType() {
    048        final short _opcode = super.getOpcode();
    049        switch (_opcode) {
    050            case Const.IRETURN:
    051                return Type.INT;
    052            case Const.LRETURN:
    053                return Type.LONG;
    054            case Const.FRETURN:
    055                return Type.FLOAT;
    056            case Const.DRETURN:
    057                return Type.DOUBLE;
    058            case Const.ARETURN:
    059                return Type.OBJECT;
    060            case Const.RETURN:
    061                return Type.VOID;
    062            default: // Never reached
    063                throw new ClassGenException("Unknown type " + _opcode);
    064        }
    065    }
    066
    067
    068    @Override
    069    public Class<?>[] getExceptions() {
    070        return new Class[] {
    071            ExceptionConst.ILLEGAL_MONITOR_STATE
    072        };
    073    }
    074
    075
    076    /** @return type associated with the instruction
    077     */
    078    @Override
    079    public Type getType( final ConstantPoolGen cp ) {
    080        return getType();
    081    }
    082}