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