1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.services.classfile.ConstantPoolEntry |
4 | |
5 | Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.services.classfile; |
22 | |
23 | import org.apache.derby.iapi.services.classfile.VMDescriptor; |
24 | |
25 | import org.apache.derby.iapi.services.sanity.SanityManager; |
26 | |
27 | import java.io.IOException; |
28 | |
29 | /** Constant Pool class - pages 92-99 */ |
30 | public abstract class ConstantPoolEntry /*implements PoolEntry*/ |
31 | { |
32 | |
33 | protected int tag; // u1 (page 83) |
34 | protected boolean doubleSlot; // Some entries take up two slots! (see footnote page 98) |
35 | |
36 | /* Index within Vector */ |
37 | protected int index; |
38 | |
39 | protected ConstantPoolEntry(int tag) { |
40 | this.tag = tag; |
41 | } |
42 | |
43 | int getIndex() { |
44 | if (SanityManager.DEBUG) { |
45 | if (index <= 0) |
46 | { |
47 | SanityManager.THROWASSERT("index is expected to be > 0, is " + index); |
48 | } |
49 | } |
50 | return index; |
51 | } |
52 | |
53 | void setIndex(int index) { |
54 | this.index = index; |
55 | } |
56 | |
57 | boolean doubleSlot() { |
58 | return doubleSlot; |
59 | } |
60 | |
61 | /** |
62 | Return the key used to key this object in a hashtable |
63 | */ |
64 | Object getKey() { |
65 | return this; |
66 | } |
67 | |
68 | /** |
69 | Return an estimate of the size of the constant pool entry. |
70 | */ |
71 | abstract int classFileSize(); |
72 | |
73 | void put(ClassFormatOutput out) throws IOException { |
74 | out.putU1(tag); |
75 | } |
76 | |
77 | /* |
78 | ** Public API methods |
79 | */ |
80 | |
81 | /** |
82 | Return the tag or type of the entry. Will be equal to one of the |
83 | constants above, e.g. CONSTANT_Class. |
84 | */ |
85 | final int getTag() { |
86 | return tag; |
87 | } |
88 | |
89 | /** |
90 | Get the first index in a index type pool entry. |
91 | This call is valid when getTag() returns one of |
92 | <UL> |
93 | <LI> CONSTANT_Class |
94 | <LI> CONSTANT_Fieldref |
95 | <LI> CONSTANT_Methodref |
96 | <LI> CONSTANT_InterfaceMethodref |
97 | <LI> CONSTANT_String |
98 | <LI> CONSTANT_NameAndType |
99 | </UL> |
100 | */ |
101 | int getI1() { return 0; } |
102 | |
103 | /** |
104 | Get the second index in a index type pool entry. |
105 | This call is valid when getTag() returns one of |
106 | <UL> |
107 | <LI> CONSTANT_Fieldref |
108 | <LI> CONSTANT_Methodref |
109 | <LI> CONSTANT_InterfaceMethodref |
110 | <LI> CONSTANT_NameAndType |
111 | </UL> |
112 | */ |
113 | int getI2() { return 0; }; |
114 | } |
115 | |