01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package components;
28:
29: import java.io.DataInput;
30: import java.io.DataOutput;
31: import java.io.IOException;
32: import jcc.Const;
33:
34: // Class that represents a CONSTANT_UTF8 in a classfile's
35: // constant pool
36:
37: public class UnicodeConstant extends ConstantObject {
38: public String string;
39: public String UTFstring;
40: public int stringTableOffset; // used by in-core output writers
41: public boolean isSuffix = false; // used by in-core output writers
42:
43: private UnicodeConstant(int t, String s) {
44: tag = t;
45: string = s;
46: nSlots = 1;
47: }
48:
49: public UnicodeConstant(String s) {
50: this (Const.CONSTANT_UTF8, s);
51: }
52:
53: public static ConstantObject read(int t, DataInput i)
54: throws IOException {
55: return new UnicodeConstant(t, i.readUTF());
56: }
57:
58: public void write(DataOutput o) throws IOException {
59: o.writeByte(tag);
60: o.writeUTF(string);
61: }
62:
63: public int hashCode() {
64: return string.hashCode();
65: }
66:
67: public boolean equals(Object o) {
68: if (o instanceof UnicodeConstant) {
69: UnicodeConstant a = (UnicodeConstant) o;
70: return string.equals(a.string);
71: } else {
72: return false;
73: }
74: }
75:
76: public String toString() {
77: return string;
78: }
79:
80: public boolean isResolved() {
81: return true;
82: }
83: }
|