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 * Class representing a class reference in the constant pool
26 */
27 public class ConstClass extends ConstBasic {
28
29 public static final int MyTag = CONSTANTClass;
30
31
32 private ConstUtf8 theClassName;
33
34
35
36 private int theClassNameIndex;
37
38
39
40 /***
41 * Return the tag for this constant
42 */
43 public int tag() { return MyTag; }
44
45 /***
46 * Return the class name
47 */
48 public ConstUtf8 className() {
49 return theClassName;
50 }
51
52 /***
53 * Return the class name in simple string form
54 */
55 public String asString() {
56 return theClassName.asString();
57 }
58
59 /***
60 * A printable representation
61 */
62 public String toString() {
63 return "CONSTANTClass(" + indexAsString() + "): " +
64 "className(" + theClassName.toString() + ")";
65 }
66
67 /***
68 * Change the class reference (not to be done lightly)
69 */
70 public void changeClass(ConstUtf8 newName) {
71 theClassName = newName;
72 theClassNameIndex = newName.getIndex();
73 }
74
75 /***
76 * Construct a ConstClass
77 */
78 public ConstClass(ConstUtf8 cname) {
79 theClassName = cname;
80 }
81
82 /***
83 * Compares this instance with another for structural equality.
84 */
85
86 public boolean isEqual(Stack msg, Object obj) {
87 if (!(obj instanceof ConstClass)) {
88 msg.push("obj/obj.getClass() = "
89 + (obj == null ? null : obj.getClass()));
90 msg.push("this.getClass() = "
91 + this.getClass());
92 return false;
93 }
94 ConstClass other = (ConstClass)obj;
95
96 if (!super.isEqual(msg, other)) {
97 return false;
98 }
99
100 if (!this.theClassName.isEqual(msg, other.theClassName)) {
101 msg.push(String.valueOf("theClassName = "
102 + other.theClassName));
103 msg.push(String.valueOf("theClassName = "
104 + this.theClassName));
105 return false;
106 }
107 return true;
108 }
109
110 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
111
112 ConstClass(int cname) {
113 theClassNameIndex = cname;
114 }
115
116 void formatData(DataOutputStream b) throws IOException {
117 b.writeShort(theClassName.getIndex());
118 }
119
120 static ConstClass read(DataInputStream input) throws IOException {
121 return new ConstClass(input.readUnsignedShort());
122 }
123
124 void resolve(ConstantPool p) {
125 theClassName = (ConstUtf8)p.constantAt(theClassNameIndex);
126 }
127 }