source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 6.6 KB
Line 
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 */
17package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
18
19import java.io.DataInputStream;
20import java.io.IOException;
21
22/**
23 * An entry in the constant pool. This class contains a representation of the
24 * constant pool entries. It is an abstract base class for all the different
25 * forms of constant pool entry.
26 *
27 * @see ConstantPool
28 */
29public abstract class ConstantPoolEntry {
30
31 /** Tag value for UTF8 entries. */
32 public static final int CONSTANT_UTF8 = 1;
33
34 /** Tag value for Integer entries. */
35 public static final int CONSTANT_INTEGER = 3;
36
37 /** Tag value for Float entries. */
38 public static final int CONSTANT_FLOAT = 4;
39
40 /** Tag value for Long entries. */
41 public static final int CONSTANT_LONG = 5;
42
43 /** Tag value for Double entries. */
44 public static final int CONSTANT_DOUBLE = 6;
45
46 /** Tag value for Class entries. */
47 public static final int CONSTANT_CLASS = 7;
48
49 /** Tag value for String entries. */
50 public static final int CONSTANT_STRING = 8;
51
52 /** Tag value for Field Reference entries. */
53 public static final int CONSTANT_FIELDREF = 9;
54
55 /** Tag value for Method Reference entries. */
56 public static final int CONSTANT_METHODREF = 10;
57
58 /** Tag value for Interface Method Reference entries. */
59 public static final int CONSTANT_INTERFACEMETHODREF = 11;
60
61 /** Tag value for Name and Type entries. */
62 public static final int CONSTANT_NAMEANDTYPE = 12;
63
64 /**
65 * This entry's tag which identifies the type of this constant pool
66 * entry.
67 */
68 private int tag;
69
70 /**
71 * The number of slots in the constant pool, occupied by this entry.
72 */
73 private int numEntries;
74
75 /**
76 * A flag which indicates if this entry has been resolved or not.
77 */
78 private boolean resolved;
79
80 /**
81 * Initialise the constant pool entry.
82 *
83 * @param tagValue the tag value which identifies which type of constant
84 * pool entry this is.
85 * @param entries the number of constant pool entry slots this entry
86 * occupies.
87 */
88 public ConstantPoolEntry(int tagValue, int entries) {
89 tag = tagValue;
90 numEntries = entries;
91 resolved = false;
92 }
93
94 /**
95 * Read a constant pool entry from a stream. This is a factory method
96 * which reads a constant pool entry form a stream and returns the
97 * appropriate subclass for the entry.
98 *
99 * @param cpStream the stream from which the constant pool entry is to
100 * be read.
101 * @return the appropriate ConstantPoolEntry subclass representing the
102 * constant pool entry from the stream.
103 * @exception IOException if the constant pool entry cannot be read
104 * from the stream
105 */
106 public static ConstantPoolEntry readEntry(DataInputStream cpStream)
107 throws IOException {
108 ConstantPoolEntry cpInfo = null;
109 int cpTag = cpStream.readUnsignedByte();
110
111 switch (cpTag) {
112
113 case CONSTANT_UTF8:
114 cpInfo = new Utf8CPInfo();
115
116 break;
117 case CONSTANT_INTEGER:
118 cpInfo = new IntegerCPInfo();
119
120 break;
121 case CONSTANT_FLOAT:
122 cpInfo = new FloatCPInfo();
123
124 break;
125 case CONSTANT_LONG:
126 cpInfo = new LongCPInfo();
127
128 break;
129 case CONSTANT_DOUBLE:
130 cpInfo = new DoubleCPInfo();
131
132 break;
133 case CONSTANT_CLASS:
134 cpInfo = new ClassCPInfo();
135
136 break;
137 case CONSTANT_STRING:
138 cpInfo = new StringCPInfo();
139
140 break;
141 case CONSTANT_FIELDREF:
142 cpInfo = new FieldRefCPInfo();
143
144 break;
145 case CONSTANT_METHODREF:
146 cpInfo = new MethodRefCPInfo();
147
148 break;
149 case CONSTANT_INTERFACEMETHODREF:
150 cpInfo = new InterfaceMethodRefCPInfo();
151
152 break;
153 case CONSTANT_NAMEANDTYPE:
154 cpInfo = new NameAndTypeCPInfo();
155
156 break;
157 default:
158 throw new ClassFormatError("Invalid Constant Pool entry Type "
159 + cpTag);
160 }
161
162 cpInfo.read(cpStream);
163
164 return cpInfo;
165 }
166
167 /**
168 * Indicates whether this entry has been resolved. In general a constant
169 * pool entry can reference another constant pool entry by its index
170 * value. Resolution involves replacing this index value with the
171 * constant pool entry at that index.
172 *
173 * @return true if this entry has been resolved.
174 */
175 public boolean isResolved() {
176 return resolved;
177 }
178
179 /**
180 * Resolve this constant pool entry with respect to its dependents in
181 * the constant pool.
182 *
183 * @param constantPool the constant pool of which this entry is a member
184 * and against which this entry is to be resolved.
185 */
186 public void resolve(ConstantPool constantPool) {
187 resolved = true;
188 }
189
190 /**
191 * read a constant pool entry from a class stream.
192 *
193 * @param cpStream the DataInputStream which contains the constant pool
194 * entry to be read.
195 * @exception IOException if there is a problem reading the entry from
196 * the stream.
197 */
198 public abstract void read(DataInputStream cpStream) throws IOException;
199
200 /**
201 * Get the Entry's type tag.
202 *
203 * @return The Tag value of this entry
204 */
205 public int getTag() {
206 return tag;
207 }
208
209 /**
210 * Get the number of Constant Pool Entry slots within the constant pool
211 * occupied by this entry.
212 *
213 * @return the number of slots used.
214 */
215 public final int getNumEntries() {
216 return numEntries;
217 }
218
219}
220
Note: See TracBrowser for help on using the repository browser.