View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   *
17   */
18  package org.apache.bcel.generic;
19  
20  import org.apache.bcel.Const;
21  
22  /**
23   * Returnaddress, the type JSR or JSR_W instructions push upon the stack.
24   *
25   * see vmspec2 �3.3.3
26   * @version $Id: ReturnaddressType.html 1018313 2017-09-18 09:03:04Z britter $
27   */
28  public class ReturnaddressType extends Type {
29  
30      public static final ReturnaddressType NO_TARGET = new ReturnaddressType();
31      private InstructionHandle returnTarget;
32  
33  
34      /**
35       * A Returnaddress [that doesn't know where to return to].
36       */
37      private ReturnaddressType() {
38          super(Const.T_ADDRESS, "<return address>");
39      }
40  
41  
42      /**
43       * Creates a ReturnaddressType object with a target.
44       */
45      public ReturnaddressType(final InstructionHandle returnTarget) {
46          super(Const.T_ADDRESS, "<return address targeting " + returnTarget + ">");
47          this.returnTarget = returnTarget;
48      }
49  
50  
51      /** @return a hash code value for the object.
52       */
53      @Override
54      public int hashCode() {
55          if (returnTarget == null) {
56              return 0;
57          }
58          return returnTarget.hashCode();
59      }
60  
61  
62      /**
63       * Returns if the two Returnaddresses refer to the same target.
64       */
65      @Override
66      public boolean equals( final Object rat ) {
67          if (!(rat instanceof ReturnaddressType)) {
68              return false;
69          }
70          final ReturnaddressType that = (ReturnaddressType) rat;
71          if (this.returnTarget == null || that.returnTarget == null) {
72              return that.returnTarget == this.returnTarget;
73          }
74          return that.returnTarget.equals(this.returnTarget);
75      }
76  
77  
78      /**
79       * @return the target of this ReturnaddressType
80       */
81      public InstructionHandle getTarget() {
82          return returnTarget;
83      }
84  }