KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > depend > constantpool > MethodRefCPInfo


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
19
20 import java.io.DataInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 /**
24  * A MethodRef CP Info
25  *
26  */

27 public class MethodRefCPInfo extends ConstantPoolEntry {
28     /** the name of the class defining this method */
29     private String JavaDoc methodClassName;
30     /** the name of the method */
31     private String JavaDoc methodName;
32     /** the method's type descriptor */
33     private String JavaDoc methodType;
34     /** The index into the constant pool which defines the class of this method. */
35     private int classIndex;
36     /**
37      * the index into the constant pool which defined the name and type
38      * signature of the method
39      */

40     private int nameAndTypeIndex;
41
42     /** Constructor. */
43     public MethodRefCPInfo() {
44         super(CONSTANT_METHODREF, 1);
45     }
46
47     /**
48      * read a constant pool entry from a class stream.
49      *
50      * @param cpStream the DataInputStream which contains the constant pool
51      * entry to be read.
52      * @exception IOException if there is a problem reading the entry from
53      * the stream.
54      */

55     public void read(DataInputStream JavaDoc cpStream) throws IOException JavaDoc {
56         classIndex = cpStream.readUnsignedShort();
57         nameAndTypeIndex = cpStream.readUnsignedShort();
58     }
59
60     /**
61      * Print a readable version of the constant pool entry.
62      *
63      * @return the string representation of this constant pool entry.
64      */

65     public String JavaDoc toString() {
66         String JavaDoc value;
67
68         if (isResolved()) {
69             value = "Method : Class = " + methodClassName + ", name = "
70                  + methodName + ", type = " + methodType;
71         } else {
72             value = "Method : Class index = " + classIndex
73                  + ", name and type index = " + nameAndTypeIndex;
74         }
75
76         return value;
77     }
78
79     /**
80      * Resolve this constant pool entry with respect to its dependents in
81      * the constant pool.
82      *
83      * @param constantPool the constant pool of which this entry is a member
84      * and against which this entry is to be resolved.
85      */

86     public void resolve(ConstantPool constantPool) {
87         ClassCPInfo methodClass
88              = (ClassCPInfo) constantPool.getEntry(classIndex);
89
90         methodClass.resolve(constantPool);
91
92         methodClassName = methodClass.getClassName();
93
94         NameAndTypeCPInfo nt
95              = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
96
97         nt.resolve(constantPool);
98
99         methodName = nt.getName();
100         methodType = nt.getType();
101
102         super.resolve(constantPool);
103     }
104
105     /**
106      * Get the name of the class defining the method
107      *
108      * @return the name of the class defining this method
109      */

110     public String JavaDoc getMethodClassName() {
111         return methodClassName;
112     }
113
114     /**
115      * Get the name of the method.
116      *
117      * @return the name of the method.
118      */

119     public String JavaDoc getMethodName() {
120         return methodName;
121     }
122
123     /**
124      * Get the type signature of the method.
125      *
126      * @return the type signature of the method.
127      */

128     public String JavaDoc getMethodType() {
129         return methodType;
130     }
131
132 }
133
134
Popular Tags