KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cojen > classfile > constant > ConstantInterfaceMethodInfo


1 /*
2  * Copyright 2004 Brian S O'Neill
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import java.io.IOException JavaDoc;
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 JavaDoc obj) {
54         if (obj instanceof ConstantInterfaceMethodInfo) {
55             ConstantInterfaceMethodInfo other =
56                 (ConstantInterfaceMethodInfo)obj;
57             return (mParentClass.equals(other.mParentClass) &&
58                     mNameAndType.equals(other.mNameAndType));
59         }
60         
61         return false;
62     }
63     
64     public void writeTo(DataOutput JavaDoc dout) throws IOException JavaDoc {
65         super.writeTo(dout);
66         dout.writeShort(mParentClass.getIndex());
67         dout.writeShort(mNameAndType.getIndex());
68     }
69
70     public String JavaDoc toString() {
71         StringBuffer JavaDoc buf =
72             new StringBuffer JavaDoc("CONSTANT_InterfaceMethodref_info: ");
73         buf.append(getParentClass().getType().getFullName());
74
75         ConstantNameAndTypeInfo cnati = getNameAndType();
76
77         buf.append(' ');
78         buf.append(cnati.getName());
79         buf.append(' ');
80         buf.append(cnati.getType());
81
82         return buf.toString();
83     }
84 }
85
Popular Tags