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 specification in the constant pool
25 *
26 * ConstString strictly speaking is not a ConstantValue in the
27 * Java VM sense. However, the compiler generates ConstantValue attributes
28 * which refer to ConstString entries. This occurs for initialized static
29 * final String fields. I've changed ConstString to be a ConstValue for
30 * now as a simplification.
31 */
32 public class ConstString extends ConstValue {
33
34 public static final int MyTag = CONSTANTString;
35
36
37 private ConstUtf8 stringValue;
38
39
40
41 private int stringValueIndex;
42
43
44
45 /***
46 * Return the tag for this constant
47 */
48 public int tag() { return MyTag; }
49
50 /***
51 * Return the utf8 string calue
52 */
53 public ConstUtf8 value() {
54 return stringValue;
55 }
56
57 /***
58 * Return the descriptor string for the constant type.
59 */
60 public String descriptor() {
61 return "Ljava/lang/String;";
62 }
63
64 /***
65 * A printable representation
66 */
67 public String toString() {
68 return "CONSTANTString(" + indexAsString() + "): " +
69 "string(" + stringValue.asString() + ")";
70 }
71
72 /***
73 * Compares this instance with another for structural equality.
74 */
75
76 public boolean isEqual(Stack msg, Object obj) {
77 if (!(obj instanceof ConstString)) {
78 msg.push("obj/obj.getClass() = "
79 + (obj == null ? null : obj.getClass()));
80 msg.push("this.getClass() = "
81 + this.getClass());
82 return false;
83 }
84 ConstString other = (ConstString)obj;
85
86 if (!super.isEqual(msg, other)) {
87 return false;
88 }
89
90 if (!this.stringValue.isEqual(msg, other.stringValue)) {
91 msg.push(String.valueOf("stringValue = "
92 + other.stringValue));
93 msg.push(String.valueOf("stringValue = "
94 + this.stringValue));
95 return false;
96 }
97 return true;
98 }
99
100 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
101
102 ConstString(ConstUtf8 s) {
103 stringValue = s;
104 }
105
106 ConstString(int sIndex) {
107 stringValueIndex = sIndex;
108 }
109
110 void formatData(DataOutputStream b) throws IOException {
111 b.writeShort(stringValue.getIndex());
112 }
113 static ConstString read(DataInputStream input) throws IOException {
114 return new ConstString(input.readUnsignedShort());
115 }
116 void resolve(ConstantPool p) {
117 stringValue = (ConstUtf8) p.constantAt(stringValueIndex);
118 }
119 }