001: /*
002:
003: Derby - Class org.apache.derby.iapi.services.classfile.ConstantPoolEntry
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.services.classfile;
023:
024: import org.apache.derby.iapi.services.classfile.VMDescriptor;
025:
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import java.io.IOException;
029:
030: /** Constant Pool class - pages 92-99 */
031: public abstract class ConstantPoolEntry /*implements PoolEntry*/
032: {
033:
034: protected int tag; // u1 (page 83)
035: protected boolean doubleSlot; // Some entries take up two slots! (see footnote page 98)
036:
037: /* Index within Vector */
038: protected int index;
039:
040: protected ConstantPoolEntry(int tag) {
041: this .tag = tag;
042: }
043:
044: int getIndex() {
045: if (SanityManager.DEBUG) {
046: if (index <= 0) {
047: SanityManager
048: .THROWASSERT("index is expected to be > 0, is "
049: + index);
050: }
051: }
052: return index;
053: }
054:
055: void setIndex(int index) {
056: this .index = index;
057: }
058:
059: boolean doubleSlot() {
060: return doubleSlot;
061: }
062:
063: /**
064: Return the key used to key this object in a hashtable
065: */
066: Object getKey() {
067: return this ;
068: }
069:
070: /**
071: Return an estimate of the size of the constant pool entry.
072: */
073: abstract int classFileSize();
074:
075: void put(ClassFormatOutput out) throws IOException {
076: out.putU1(tag);
077: }
078:
079: /*
080: ** Public API methods
081: */
082:
083: /**
084: Return the tag or type of the entry. Will be equal to one of the
085: constants above, e.g. CONSTANT_Class.
086: */
087: final int getTag() {
088: return tag;
089: }
090:
091: /**
092: Get the first index in a index type pool entry.
093: This call is valid when getTag() returns one of
094: <UL>
095: <LI> CONSTANT_Class
096: <LI> CONSTANT_Fieldref
097: <LI> CONSTANT_Methodref
098: <LI> CONSTANT_InterfaceMethodref
099: <LI> CONSTANT_String
100: <LI> CONSTANT_NameAndType
101: </UL>
102: */
103: int getI1() {
104: return 0;
105: }
106:
107: /**
108: Get the second index in a index type pool entry.
109: This call is valid when getTag() returns one of
110: <UL>
111: <LI> CONSTANT_Fieldref
112: <LI> CONSTANT_Methodref
113: <LI> CONSTANT_InterfaceMethodref
114: <LI> CONSTANT_NameAndType
115: </UL>
116: */
117: int getI2() {
118: return 0;
119: };
120: }
|