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
22package com.sun.org.apache.bcel.internal.generic;
23
24import com.sun.org.apache.bcel.internal.Constants;
25import java.util.Objects;
26
27/**
28 * Returnaddress, the type JSR or JSR_W instructions push upon the stack.
29 *
30 * see vmspec2 3.3.3
31 * @author  <A HREF="http://www.inf.fu-berlin.de/~ehaase">Enver Haase</A>
32 */
33public class ReturnaddressType extends Type {
34
35  public static final ReturnaddressType NO_TARGET = new ReturnaddressType();
36  private InstructionHandle returnTarget;
37
38  /**
39   * A Returnaddress [that doesn't know where to return to].
40   */
41  private ReturnaddressType(){
42    super(Constants.T_ADDRESS, "<return address>");
43  }
44
45  /**
46   * Creates a ReturnaddressType object with a target.
47   */
48  public ReturnaddressType(InstructionHandle returnTarget) {
49    super(Constants.T_ADDRESS, "<return address targeting "+returnTarget+">");
50        this.returnTarget = returnTarget;
51  }
52
53  @Override
54  public int hashCode() {
55      return Objects.hashCode(this.returnTarget);
56  }
57
58  /**
59   * Returns if the two Returnaddresses refer to the same target.
60   */
61  @Override
62  public boolean equals(Object rat){
63    if(!(rat instanceof ReturnaddressType))
64      return false;
65
66    return ((ReturnaddressType)rat).returnTarget.equals(this.returnTarget);
67  }
68
69  /**
70   * @return the target of this ReturnaddressType
71   */
72  public InstructionHandle getTarget(){
73    return returnTarget;
74  }
75}
76