1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import org.apache.bcel.Constants;
20
21 /***
22 * Returnaddress, the type JSR or JSR_W instructions push upon the stack.
23 *
24 * see vmspec2 ß3.3.3
25 * @version $Id: ReturnaddressType.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author Enver Haase
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(Constants.T_ADDRESS, "<return address>");
39 }
40
41
42 /***
43 * Creates a ReturnaddressType object with a target.
44 */
45 public ReturnaddressType(InstructionHandle returnTarget) {
46 super(Constants.T_ADDRESS, "<return address targeting " + returnTarget + ">");
47 this.returnTarget = returnTarget;
48 }
49
50
51 /*** @return a hash code value for the object.
52 */
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 public boolean equals( Object rat ) {
65 if (!(rat instanceof ReturnaddressType)) {
66 return false;
67 }
68 ReturnaddressType that = (ReturnaddressType) rat;
69 if (this.returnTarget == null || that.returnTarget == null) {
70 return that.returnTarget == this.returnTarget;
71 }
72 return that.returnTarget.equals(this.returnTarget);
73 }
74
75
76 /***
77 * @return the target of this ReturnaddressType
78 */
79 public InstructionHandle getTarget() {
80 return returnTarget;
81 }
82 }