1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.*;
21 import java.util.Stack;
22
23 /***
24 * The abstract base class used to represent the various type of
25 * references to members (fields/methods) within the constant pool.
26 */
27 public abstract class ConstBasicMemberRef extends ConstBasic {
28
29 protected ConstClass theClassName;
30
31
32
33 protected int theClassNameIndex;
34
35
36 protected ConstNameAndType theNameAndType;
37
38
39
40 protected int theNameAndTypeIndex;
41
42
43
44 /***
45 * Return the name of the class defining the member
46 */
47 public ConstClass className() {
48 return theClassName;
49 }
50
51 /***
52 * Return the name and type of the member
53 */
54 public ConstNameAndType nameAndType() {
55 return theNameAndType;
56 }
57
58 public String toString () {
59 return "className(" + theClassName.toString() + ")" +
60 " nameAndType(" + theNameAndType.toString() + ")";
61 }
62
63 /***
64 * Compares this instance with another for structural equality.
65 */
66
67 public boolean isEqual(Stack msg, Object obj) {
68 if (!(obj instanceof ConstBasicMemberRef)) {
69 msg.push("obj/obj.getClass() = "
70 + (obj == null ? null : obj.getClass()));
71 msg.push("this.getClass() = "
72 + this.getClass());
73 return false;
74 }
75 ConstBasicMemberRef other = (ConstBasicMemberRef)obj;
76
77 if (!super.isEqual(msg, other)) {
78 return false;
79 }
80
81 if (!this.theClassName.isEqual(msg, other.theClassName)) {
82 msg.push(String.valueOf("theClassName = "
83 + other.theClassName));
84 msg.push(String.valueOf("theClassName = "
85 + this.theClassName));
86 return false;
87 }
88 if (!this.theNameAndType.isEqual(msg, other.theNameAndType)) {
89 msg.push(String.valueOf("theNameAndType = "
90 + other.theNameAndType));
91 msg.push(String.valueOf("theNameAndType = "
92 + this.theNameAndType));
93 return false;
94 }
95 return true;
96 }
97
98 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
99
100 /***
101 * Constructor for "from scratch" creation
102 */
103 ConstBasicMemberRef (ConstClass cname, ConstNameAndType NT) {
104 theClassName = cname;
105 theNameAndType = NT;
106 }
107
108 /***
109 * Constructor for reading from a class file
110 */
111 ConstBasicMemberRef (int cnameIndex, int NT_index) {
112 theClassNameIndex = cnameIndex;
113 theNameAndTypeIndex = NT_index;
114 }
115
116 void formatData (DataOutputStream b) throws IOException {
117 b.writeShort(theClassName.getIndex());
118 b.writeShort(theNameAndType.getIndex());
119 }
120 void resolve (ConstantPool p) {
121 theClassName = (ConstClass) p.constantAt(theClassNameIndex);
122 theNameAndType = (ConstNameAndType) p.constantAt(theNameAndTypeIndex);
123 }
124 }