1 | /*
|
---|
2 | * Copyright 2000-2002,2004 The Apache Software Foundation
|
---|
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.apache.tools.ant.taskdefs.optional.depend.constantpool;
|
---|
18 |
|
---|
19 | import java.io.DataInputStream;
|
---|
20 | import java.io.IOException;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * A MethodRef CP Info
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class MethodRefCPInfo extends ConstantPoolEntry {
|
---|
27 | /** the name of the class defining this method */
|
---|
28 | private String methodClassName;
|
---|
29 | /** the name of the method */
|
---|
30 | private String methodName;
|
---|
31 | /** the method's type descriptor */
|
---|
32 | private String methodType;
|
---|
33 | /** The index into the constant pool which defines the class of this method. */
|
---|
34 | private int classIndex;
|
---|
35 | /**
|
---|
36 | * the index into the constant pool which defined the name and type
|
---|
37 | * signature of the method
|
---|
38 | */
|
---|
39 | private int nameAndTypeIndex;
|
---|
40 |
|
---|
41 | /** Constructor. */
|
---|
42 | public MethodRefCPInfo() {
|
---|
43 | super(CONSTANT_METHODREF, 1);
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * read a constant pool entry from a class stream.
|
---|
48 | *
|
---|
49 | * @param cpStream the DataInputStream which contains the constant pool
|
---|
50 | * entry to be read.
|
---|
51 | * @exception IOException if there is a problem reading the entry from
|
---|
52 | * the stream.
|
---|
53 | */
|
---|
54 | public void read(DataInputStream cpStream) throws IOException {
|
---|
55 | classIndex = cpStream.readUnsignedShort();
|
---|
56 | nameAndTypeIndex = cpStream.readUnsignedShort();
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Print a readable version of the constant pool entry.
|
---|
61 | *
|
---|
62 | * @return the string representation of this constant pool entry.
|
---|
63 | */
|
---|
64 | public String toString() {
|
---|
65 | String value;
|
---|
66 |
|
---|
67 | if (isResolved()) {
|
---|
68 | value = "Method : Class = " + methodClassName + ", name = "
|
---|
69 | + methodName + ", type = " + methodType;
|
---|
70 | } else {
|
---|
71 | value = "Method : Class index = " + classIndex
|
---|
72 | + ", name and type index = " + nameAndTypeIndex;
|
---|
73 | }
|
---|
74 |
|
---|
75 | return value;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Resolve this constant pool entry with respect to its dependents in
|
---|
80 | * the constant pool.
|
---|
81 | *
|
---|
82 | * @param constantPool the constant pool of which this entry is a member
|
---|
83 | * and against which this entry is to be resolved.
|
---|
84 | */
|
---|
85 | public void resolve(ConstantPool constantPool) {
|
---|
86 | ClassCPInfo methodClass
|
---|
87 | = (ClassCPInfo) constantPool.getEntry(classIndex);
|
---|
88 |
|
---|
89 | methodClass.resolve(constantPool);
|
---|
90 |
|
---|
91 | methodClassName = methodClass.getClassName();
|
---|
92 |
|
---|
93 | NameAndTypeCPInfo nt
|
---|
94 | = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
|
---|
95 |
|
---|
96 | nt.resolve(constantPool);
|
---|
97 |
|
---|
98 | methodName = nt.getName();
|
---|
99 | methodType = nt.getType();
|
---|
100 |
|
---|
101 | super.resolve(constantPool);
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Get the name of the class defining the method
|
---|
106 | *
|
---|
107 | * @return the name of the class defining this method
|
---|
108 | */
|
---|
109 | public String getMethodClassName() {
|
---|
110 | return methodClassName;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Get the name of the method.
|
---|
115 | *
|
---|
116 | * @return the name of the method.
|
---|
117 | */
|
---|
118 | public String getMethodName() {
|
---|
119 | return methodName;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Get the type signature of the method.
|
---|
124 | *
|
---|
125 | * @return the type signature of the method.
|
---|
126 | */
|
---|
127 | public String getMethodType() {
|
---|
128 | return methodType;
|
---|
129 | }
|
---|
130 |
|
---|
131 | }
|
---|
132 |
|
---|