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