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