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   */
27  public class ReturnaddressType extends Type {
28  
29      public static final ReturnaddressTypehtml#ReturnaddressType">ReturnaddressType NO_TARGET = new ReturnaddressType();
30      private InstructionHandle returnTarget;
31  
32  
33      /**
34       * A Returnaddress [that doesn't know where to return to].
35       */
36      private ReturnaddressType() {
37          super(Const.T_ADDRESS, "<return address>");
38      }
39  
40  
41      /**
42       * Creates a ReturnaddressType object with a target.
43       */
44      public ReturnaddressType(final InstructionHandle returnTarget) {
45          super(Const.T_ADDRESS, "<return address targeting " + returnTarget + ">");
46          this.returnTarget = returnTarget;
47      }
48  
49  
50      /** @return a hash code value for the object.
51       */
52      @Override
53      public int hashCode() {
54          if (returnTarget == null) {
55              return 0;
56          }
57          return returnTarget.hashCode();
58      }
59  
60  
61      /**
62       * Returns if the two Returnaddresses refer to the same target.
63       */
64      @Override
65      public boolean equals( final Object rat ) {
66          if (!(rat instanceof ReturnaddressType)) {
67              return false;
68          }
69          final ReturnaddressType../org/apache/bcel/generic/ReturnaddressType.html#ReturnaddressType">ReturnaddressType that = (ReturnaddressType) rat;
70          if (this.returnTarget == null || that.returnTarget == null) {
71              return that.returnTarget == this.returnTarget;
72          }
73          return that.returnTarget.equals(this.returnTarget);
74      }
75  
76  
77      /**
78       * @return the target of this ReturnaddressType
79       */
80      public InstructionHandle getTarget() {
81          return returnTarget;
82      }
83  }