1 | /*
|
---|
2 | * Copyright 2000-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 FieldRef CP Info
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class FieldRefCPInfo extends ConstantPoolEntry {
|
---|
27 | /** Name of the field's class */
|
---|
28 | private String fieldClassName;
|
---|
29 | /** name of the field in that class */
|
---|
30 | private String fieldName;
|
---|
31 | /** The type of the field */
|
---|
32 | private String fieldType;
|
---|
33 | /** Index into the constant pool for the class */
|
---|
34 | private int classIndex;
|
---|
35 | /** Index into the constant pool for the name and type entry */
|
---|
36 | private int nameAndTypeIndex;
|
---|
37 |
|
---|
38 | /** Constructor. */
|
---|
39 | public FieldRefCPInfo() {
|
---|
40 | super(CONSTANT_FIELDREF, 1);
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * read a constant pool entry from a class stream.
|
---|
45 | *
|
---|
46 | * @param cpStream the DataInputStream which contains the constant pool
|
---|
47 | * entry to be read.
|
---|
48 | * @exception IOException if there is a problem reading the entry from
|
---|
49 | * the stream.
|
---|
50 | */
|
---|
51 | public void read(DataInputStream cpStream) throws IOException {
|
---|
52 | classIndex = cpStream.readUnsignedShort();
|
---|
53 | nameAndTypeIndex = cpStream.readUnsignedShort();
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Resolve this constant pool entry with respect to its dependents in
|
---|
58 | * the constant pool.
|
---|
59 | *
|
---|
60 | * @param constantPool the constant pool of which this entry is a member
|
---|
61 | * and against which this entry is to be resolved.
|
---|
62 | */
|
---|
63 | public void resolve(ConstantPool constantPool) {
|
---|
64 | ClassCPInfo fieldClass
|
---|
65 | = (ClassCPInfo) constantPool.getEntry(classIndex);
|
---|
66 |
|
---|
67 | fieldClass.resolve(constantPool);
|
---|
68 |
|
---|
69 | fieldClassName = fieldClass.getClassName();
|
---|
70 |
|
---|
71 | NameAndTypeCPInfo nt
|
---|
72 | = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
|
---|
73 |
|
---|
74 | nt.resolve(constantPool);
|
---|
75 |
|
---|
76 | fieldName = nt.getName();
|
---|
77 | fieldType = nt.getType();
|
---|
78 |
|
---|
79 | super.resolve(constantPool);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Print a readable version of the constant pool entry.
|
---|
84 | *
|
---|
85 | * @return the string representation of this constant pool entry.
|
---|
86 | */
|
---|
87 | public String toString() {
|
---|
88 | String value;
|
---|
89 |
|
---|
90 | if (isResolved()) {
|
---|
91 | value = "Field : Class = " + fieldClassName + ", name = "
|
---|
92 | + fieldName + ", type = " + fieldType;
|
---|
93 | } else {
|
---|
94 | value = "Field : Class index = " + classIndex
|
---|
95 | + ", name and type index = " + nameAndTypeIndex;
|
---|
96 | }
|
---|
97 |
|
---|
98 | return value;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Gets the name of the class defining the field
|
---|
103 | *
|
---|
104 | * @return the name of the class defining the field
|
---|
105 | */
|
---|
106 | public String getFieldClassName() {
|
---|
107 | return fieldClassName;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Get the name of the field
|
---|
112 | *
|
---|
113 | * @return the field's name
|
---|
114 | */
|
---|
115 | public String getFieldName() {
|
---|
116 | return fieldName;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Get the type of the field
|
---|
121 | *
|
---|
122 | * @return the field's type in string format
|
---|
123 | */
|
---|
124 | public String getFieldType() {
|
---|
125 | return fieldType;
|
---|
126 | }
|
---|
127 |
|
---|
128 | }
|
---|
129 |
|
---|