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