KickJava   Java API By Example, From Geeks To Geeks.

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


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_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 JavaDoc obj) {
54         if (obj instanceof ConstantMethodInfo) {
55             ConstantMethodInfo other = (ConstantMethodInfo)obj;
56             return (mParentClass.equals(other.mParentClass) &&
57                     mNameAndType.equals(other.mNameAndType));
58         }
59         
60         return false;
61     }
62     
63     public void writeTo(DataOutput JavaDoc dout) throws IOException JavaDoc {
64         super.writeTo(dout);
65         dout.writeShort(mParentClass.getIndex());
66         dout.writeShort(mNameAndType.getIndex());
67     }
68
69     public String JavaDoc toString() {
70         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("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 }
83
Popular Tags