01: /*
02: * Copyright 2004 Brian S O'Neill
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.cojen.classfile.constant;
18:
19: import java.io.DataOutput;
20: import java.io.IOException;
21: import org.cojen.classfile.ConstantInfo;
22: import org.cojen.classfile.ConstantPool;
23:
24: /**
25: * This class corresponds to the CONSTANT_Fieldref_info structure as defined in
26: * section 4.4.2 of <i>The Java Virtual Machine Specification</i>.
27: *
28: * @author Brian S O'Neill
29: */
30: public class ConstantFieldInfo extends ConstantInfo {
31: private final ConstantClassInfo mParentClass;
32: private final ConstantNameAndTypeInfo mNameAndType;
33:
34: public ConstantFieldInfo(ConstantClassInfo parentClass,
35: ConstantNameAndTypeInfo nameAndType) {
36: super (TAG_FIELD);
37:
38: mParentClass = parentClass;
39: mNameAndType = nameAndType;
40: }
41:
42: public ConstantClassInfo getParentClass() {
43: return mParentClass;
44: }
45:
46: public ConstantNameAndTypeInfo getNameAndType() {
47: return mNameAndType;
48: }
49:
50: public int hashCode() {
51: return mNameAndType.hashCode();
52: }
53:
54: public boolean equals(Object obj) {
55: if (obj instanceof ConstantFieldInfo) {
56: ConstantFieldInfo other = (ConstantFieldInfo) obj;
57: return (mParentClass.equals(other.mParentClass) && mNameAndType
58: .equals(other.mNameAndType));
59: }
60:
61: return false;
62: }
63:
64: public void writeTo(DataOutput dout) throws IOException {
65: super .writeTo(dout);
66: dout.writeShort(mParentClass.getIndex());
67: dout.writeShort(mNameAndType.getIndex());
68: }
69:
70: public String toString() {
71: StringBuffer buf = new StringBuffer("CONSTANT_Fieldref_info: ");
72: buf.append(getParentClass().getType().getFullName());
73:
74: ConstantNameAndTypeInfo cnati = getNameAndType();
75:
76: buf.append(' ');
77: buf.append(cnati.getName());
78: buf.append(' ');
79: buf.append(cnati.getType());
80:
81: return buf.toString();
82: }
83: }
|