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 InterfaceMethodRef CP Info
025: *
026: */
027: public class InterfaceMethodRefCPInfo extends ConstantPoolEntry {
028: /** the class name of the class defining the interface method */
029: private String interfaceMethodClassName;
030: /** the name of the interface nmethod */
031: private String interfaceMethodName;
032: /** the method signature of the interface method */
033: private String interfaceMethodType;
034: /**
035: * the index into the constant pool of the class entry for the interface
036: * class
037: */
038: private int classIndex;
039: /**
040: * the index into the constant pool of the name and type entry
041: * describing the method
042: */
043: private int nameAndTypeIndex;
044:
045: /** Constructor. */
046: public InterfaceMethodRefCPInfo() {
047: super (CONSTANT_INTERFACEMETHODREF, 1);
048: }
049:
050: /**
051: * read a constant pool entry from a class stream.
052: *
053: * @param cpStream the DataInputStream which contains the constant pool
054: * entry to be read.
055: * @exception IOException if there is a problem reading the entry from
056: * the stream.
057: */
058: public void read(DataInputStream cpStream) throws IOException {
059: classIndex = cpStream.readUnsignedShort();
060: nameAndTypeIndex = cpStream.readUnsignedShort();
061: }
062:
063: /**
064: * Resolve this constant pool entry with respect to its dependents in
065: * the constant pool.
066: *
067: * @param constantPool the constant pool of which this entry is a member
068: * and against which this entry is to be resolved.
069: */
070: public void resolve(ConstantPool constantPool) {
071: ClassCPInfo interfaceMethodClass = (ClassCPInfo) constantPool
072: .getEntry(classIndex);
073:
074: interfaceMethodClass.resolve(constantPool);
075:
076: interfaceMethodClassName = interfaceMethodClass.getClassName();
077:
078: NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool
079: .getEntry(nameAndTypeIndex);
080:
081: nt.resolve(constantPool);
082:
083: interfaceMethodName = nt.getName();
084: interfaceMethodType = nt.getType();
085:
086: super .resolve(constantPool);
087: }
088:
089: /**
090: * Print a readable version of the constant pool entry.
091: *
092: * @return the string representation of this constant pool entry.
093: */
094: public String toString() {
095: String value;
096:
097: if (isResolved()) {
098: value = "InterfaceMethod : Class = "
099: + interfaceMethodClassName + ", name = "
100: + interfaceMethodName + ", type = "
101: + interfaceMethodType;
102: } else {
103: value = "InterfaceMethod : Class index = " + classIndex
104: + ", name and type index = " + nameAndTypeIndex;
105: }
106:
107: return value;
108: }
109:
110: /**
111: * Gets the name of the class defining the interface method
112: *
113: * @return the name of the class defining the interface method
114: */
115: public String getInterfaceMethodClassName() {
116: return interfaceMethodClassName;
117: }
118:
119: /**
120: * Get the name of the interface method
121: *
122: * @return the name of the interface method
123: */
124: public String getInterfaceMethodName() {
125: return interfaceMethodName;
126: }
127:
128: /**
129: * Gets the type of the interface method
130: *
131: * @return the interface method's type signature
132: */
133: public String getInterfaceMethodType() {
134: return interfaceMethodType;
135: }
136:
137: }
|