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