Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.bytecode
Class GrowableConstantPool

java.lang.Object
  extended bynet.sf.jode.bytecode.ConstantPool
      extended bynet.sf.jode.bytecode.GrowableConstantPool

public class GrowableConstantPool
extends ConstantPool

This class represent a constant pool, where new constants can be added to. Normally you wont need to touch this class, as ClassInfo already does all the hard work. You will only need it if you want to add your own custom attributes that use the constant pool.

Author:
Jochen Hoenicke

Field Summary
 
Fields inherited from class net.sf.jode.bytecode.ConstantPool
CLASS, DOUBLE, FIELDREF, FLOAT, INTEGER, INTERFACEMETHODREF, LONG, METHODREF, NAMEANDTYPE, STRING, UTF8
 
Constructor Summary
GrowableConstantPool()
          Create a new growable constant pool
 
Method Summary
 int putClassName(java.lang.String name)
          Adds a new class name entry to the constant pool and returns the index.
 int putClassType(java.lang.String name)
          Adds a new class entry to the constant pool and returns the index.
 int putConstant(java.lang.Object c)
          Puts a "one slot" constant into this constant pool.
 int putLongConstant(java.lang.Object c)
          Puts a "double slot" constant into this constant pool.
 int putRef(int tag, Reference ref)
          Adds a new field/method or interface reference to the constant pool and returns the index.
 int putUTF8(java.lang.String utf)
          Adds a new UTF8 entry to the constant pool and returns the index.
 int reserveConstant(java.lang.Object c)
          Reserves an entry in this constant pool for a constant (for ldc).
 void write(java.io.DataOutputStream stream)
          Writes the constant pool to the stream.
 
Methods inherited from class net.sf.jode.bytecode.ConstantPool
getClassName, getClassType, getConstant, getRef, getTag, getUTF8, iterateClassNames, read, size, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GrowableConstantPool

public GrowableConstantPool()
Create a new growable constant pool

Method Detail

putUTF8

public final int putUTF8(java.lang.String utf)
Adds a new UTF8 entry to the constant pool and returns the index. If it already exists it will reuse the previous entry.

Parameters:
utf - the UTF8 string.
Returns:
the index of the pool entry.
Throws:
java.lang.IllegalStateException - if the pool was already written, but the entry was not added before.

putClassName

public int putClassName(java.lang.String name)
Adds a new class name entry to the constant pool and returns the index. If it already exists it will reuse the previous entry.

Parameters:
name - the dot separated full qualified class name.
Returns:
the index of the pool entry.
Throws:
java.lang.IllegalArgumentException - if the class name is illegal.
java.lang.IllegalStateException - if the pool was already written, but the entry was not added before.

putClassType

public int putClassType(java.lang.String name)
Adds a new class entry to the constant pool and returns the index. If it already exists it will reuse the previous entry. This is the same as putClassName, except for the format of the parameter and that it can also handle arrays.

Parameters:
name - the type signature of the class to add.
Returns:
the index of the pool entry.
Throws:
java.lang.IllegalArgumentException - if the class name is illegal.
java.lang.IllegalStateException - if the pool was already written, but the entry was not added before.

putRef

public int putRef(int tag,
                  Reference ref)
Adds a new field/method or interface reference to the constant pool and returns the index. If it already exists it will reuse the previous entry.

Parameters:
tag - the tag of the reference, one of FIELDREF, METHODREF or INTERFACEMETHODREF.
ref - the reference.
Returns:
the index of the pool entry.
Throws:
java.lang.IllegalArgumentException - if the reference type or class name is illegal.
java.lang.IllegalStateException - if the pool was already written, but the entry was not added before.

putConstant

public int putConstant(java.lang.Object c)
Puts a "one slot" constant into this constant pool. If it already exists it will reuse the previous entry.

Parameters:
c - the constant; must be of type Integer, Float or String
Returns:
the index of the pool entry.
Throws:
java.lang.IllegalArgumentException - if the constant is of wrong type.
java.lang.IllegalStateException - if the pool was already written, but the entry was not added before.

putLongConstant

public int putLongConstant(java.lang.Object c)
Puts a "double slot" constant into this constant pool. If it already exists it will reuse the previous entry.

Parameters:
c - the constant; must be of type Long or Double
Returns:
the index of the pool entry.
Throws:
java.lang.IllegalArgumentException - if the constant is of wrong type.
java.lang.IllegalStateException - if the pool was already written, but the entry was not added before.

reserveConstant

public int reserveConstant(java.lang.Object c)
Reserves an entry in this constant pool for a constant (for ldc). The constant must still be put into the pool, before the pool may be written.

Parameters:
c - the constant, must be of type Integer, Float or String
Returns:
the reserved index into the pool of this constant.

write

public void write(java.io.DataOutputStream stream)
           throws java.io.IOException
Writes the constant pool to the stream. This is normally called by ClassInfo.write(java.io.DataOutputStream).

Parameters:
stream - the stream to write to.
Throws:
java.io.IOException - if it occured while writing.

Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.