Source code

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