    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;
    021
    022/**
    023 * Returnaddress, the type JSR or JSR_W instructions push upon the stack.
    024 *
    025 * see vmspec2 �3.3.3
    026 * @version $Id$
    027 */
    028public class ReturnaddressType extends Type {
    029
    030    public static final ReturnaddressType NO_TARGET = new ReturnaddressType();
    031    private InstructionHandle returnTarget;
    032
    033
    034    /**
    035     * A Returnaddress [that doesn't know where to return to].
    036     */
    037    private ReturnaddressType() {
    038        super(Const.T_ADDRESS, "<return address>");
    039    }
    040
    041
    042    /**
    043     * Creates a ReturnaddressType object with a target.
    044     */
    045    public ReturnaddressType(final InstructionHandle returnTarget) {
    046        super(Const.T_ADDRESS, "<return address targeting " + returnTarget + ">");
    047        this.returnTarget = returnTarget;
    048    }
    049
    050
    051    /** @return a hash code value for the object.
    052     */
    053    @Override
    054    public int hashCode() {
    055        if (returnTarget == null) {
    056            return 0;
    057        }
    058        return returnTarget.hashCode();
    059    }
    060
    061
    062    /**
    063     * Returns if the two Returnaddresses refer to the same target.
    064     */
    065    @Override
    066    public boolean equals( final Object rat ) {
    067        if (!(rat instanceof ReturnaddressType)) {
    068            return false;
    069        }
    070        final ReturnaddressType that = (ReturnaddressType) rat;
    071        if (this.returnTarget == null || that.returnTarget == null) {
    072            return that.returnTarget == this.returnTarget;
    073        }
    074        return that.returnTarget.equals(this.returnTarget);
    075    }
    076
    077
    078    /**
    079     * @return the target of this ReturnaddressType
    080     */
    081    public InstructionHandle getTarget() {
    082        return returnTarget;
    083    }
    084}