001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
019:
020: import java.io.DataInputStream;
021: import java.io.IOException;
022:
023: /**
024: * A MethodRef CP Info
025: *
026: */
027: public class MethodRefCPInfo extends ConstantPoolEntry {
028: /** the name of the class defining this method */
029: private String methodClassName;
030: /** the name of the method */
031: private String methodName;
032: /** the method's type descriptor */
033: private String methodType;
034: /** The index into the constant pool which defines the class of this method. */
035: private int classIndex;
036: /**
037: * the index into the constant pool which defined the name and type
038: * signature of the method
039: */
040: private int nameAndTypeIndex;
041:
042: /** Constructor. */
043: public MethodRefCPInfo() {
044: super (CONSTANT_METHODREF, 1);
045: }
046:
047: /**
048: * read a constant pool entry from a class stream.
049: *
050: * @param cpStream the DataInputStream which contains the constant pool
051: * entry to be read.
052: * @exception IOException if there is a problem reading the entry from
053: * the stream.
054: */
055: public void read(DataInputStream cpStream) throws IOException {
056: classIndex = cpStream.readUnsignedShort();
057: nameAndTypeIndex = cpStream.readUnsignedShort();
058: }
059:
060: /**
061: * Print a readable version of the constant pool entry.
062: *
063: * @return the string representation of this constant pool entry.
064: */
065: public String toString() {
066: String value;
067:
068: if (isResolved()) {
069: value = "Method : Class = " + methodClassName + ", name = "
070: + methodName + ", type = " + methodType;
071: } else {
072: value = "Method : Class index = " + classIndex
073: + ", name and type index = " + nameAndTypeIndex;
074: }
075:
076: return value;
077: }
078:
079: /**
080: * Resolve this constant pool entry with respect to its dependents in
081: * the constant pool.
082: *
083: * @param constantPool the constant pool of which this entry is a member
084: * and against which this entry is to be resolved.
085: */
086: public void resolve(ConstantPool constantPool) {
087: ClassCPInfo methodClass = (ClassCPInfo) constantPool
088: .getEntry(classIndex);
089:
090: methodClass.resolve(constantPool);
091:
092: methodClassName = methodClass.getClassName();
093:
094: NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool
095: .getEntry(nameAndTypeIndex);
096:
097: nt.resolve(constantPool);
098:
099: 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 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 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 getMethodType() {
129: return methodType;
130: }
131:
132: }
|