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_Methodref_info structure as defined
26: * in section 4.4.2 of <i>The Java Virtual Machine Specification</i>.
27: *
28: * @author Brian S O'Neill
29: */
30: public class ConstantMethodInfo extends ConstantInfo {
31: private final ConstantClassInfo mParentClass;
32: private final ConstantNameAndTypeInfo mNameAndType;
33:
34: public ConstantMethodInfo(ConstantClassInfo parentClass,
35: ConstantNameAndTypeInfo nameAndType) {
36: super (TAG_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 ConstantMethodInfo) {
55: ConstantMethodInfo other = (ConstantMethodInfo) 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("CONSTANT_Methodref_info: ");
71: buf.append(getParentClass().getType().getFullName());
72:
73: ConstantNameAndTypeInfo cnati = getNameAndType();
74:
75: buf.append(' ');
76: buf.append(cnati.getName());
77: buf.append(' ');
78: buf.append(cnati.getType());
79:
80: return buf.toString();
81: }
82: }
|