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