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_InterfaceMethodRef_info structure as
26: * defined in section 4.4.2 of <i>The Java Virtual Machine Specification</i>.
27: *
28: * @author Brian S O'Neill
29: */
30: public class ConstantInterfaceMethodInfo extends ConstantInfo {
31: private final ConstantClassInfo mParentClass;
32: private final ConstantNameAndTypeInfo mNameAndType;
33:
34: public ConstantInterfaceMethodInfo(ConstantClassInfo parentClass,
35: ConstantNameAndTypeInfo nameAndType) {
36: super (TAG_INTERFACE_METHOD);
37: mParentClass = parentClass;
38: mNameAndType = nameAndType;
39: }
40:
41: public ConstantClassInfo getParentClass() {
42: return mParentClass;
43: }
44:
45: public ConstantNameAndTypeInfo getNameAndType() {
46: return mNameAndType;
47: }
48:
49: public int hashCode() {
50: return mNameAndType.hashCode();
51: }
52:
53: public boolean equals(Object obj) {
54: if (obj instanceof ConstantInterfaceMethodInfo) {
55: ConstantInterfaceMethodInfo other = (ConstantInterfaceMethodInfo) obj;
56: return (mParentClass.equals(other.mParentClass) && mNameAndType
57: .equals(other.mNameAndType));
58: }
59:
60: return false;
61: }
62:
63: public void writeTo(DataOutput dout) throws IOException {
64: super .writeTo(dout);
65: dout.writeShort(mParentClass.getIndex());
66: dout.writeShort(mNameAndType.getIndex());
67: }
68:
69: public String toString() {
70: StringBuffer buf = new StringBuffer(
71: "CONSTANT_InterfaceMethodref_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: }
|