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 name and an associated type in the constant pool
25 * of a class file
26 */
27 public class ConstNameAndType extends ConstBasic {
28
29 public static final int MyTag = CONSTANTNameAndType;
30
31
32 private ConstUtf8 theName;
33
34
35
36 private int theNameIndex;
37
38
39 private ConstUtf8 typeSignature;
40
41
42
43 private int typeSignatureIndex;
44
45
46
47 /***
48 * The tag of this constant entry
49 */
50 public int tag () { return MyTag; }
51
52 /***
53 * Return the name
54 */
55 public ConstUtf8 name() {
56 return theName;
57 }
58
59 /***
60 * Return the type signature associated with the name
61 */
62 public ConstUtf8 signature() {
63 return typeSignature;
64 }
65
66 /***
67 * Modify the signature
68 */
69 public void changeSignature(ConstUtf8 newSig) {
70 typeSignature = newSig;
71 }
72
73 /***
74 * A printable representation
75 */
76 public String toString () {
77 return "CONSTANTNameAndType(" + indexAsString() + "): " +
78 "name(" + theName.toString() + ") " +
79 " type(" + typeSignature.toString() + ")";
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 ConstNameAndType)) {
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 ConstNameAndType other = (ConstNameAndType)obj;
95
96 if (!super.isEqual(msg, other)) {
97 return false;
98 }
99
100 if (!this.theName.isEqual(msg, other.theName)) {
101 msg.push(String.valueOf("theName = "
102 + other.theName));
103 msg.push(String.valueOf("theName = "
104 + this.theName));
105 return false;
106 }
107 if (!this.typeSignature.isEqual(msg, other.typeSignature)) {
108 msg.push(String.valueOf("typeSignature = "
109 + other.typeSignature));
110 msg.push(String.valueOf("typeSignature = "
111 + this.typeSignature));
112 return false;
113 }
114 return true;
115 }
116
117 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
118
119 ConstNameAndType (ConstUtf8 n, ConstUtf8 sig) {
120 theName = n; typeSignature = sig;
121 }
122
123 ConstNameAndType (int n, int sig) {
124 theNameIndex = n; typeSignatureIndex = sig;
125 }
126
127 void formatData (DataOutputStream b) throws IOException {
128 b.writeShort(theName.getIndex());
129 b.writeShort(typeSignature.getIndex());
130 }
131
132 static ConstNameAndType read (DataInputStream input) throws IOException {
133 int cname = input.readUnsignedShort();
134 int sig = input.readUnsignedShort();
135
136 return new ConstNameAndType (cname, sig);
137 }
138
139 void resolve (ConstantPool p) {
140 theName = (ConstUtf8) p.constantAt(theNameIndex);
141 typeSignature = (ConstUtf8) p.constantAt(typeSignatureIndex);
142 }
143 }