fr.umlv.corosol.classfile.constant.impl
Class DefaultJConstantPool

java.lang.Object
  extended by fr.umlv.corosol.classfile.constant.impl.DefaultJConstantPool
All Implemented Interfaces:
JConstantPool, JClassFileItem, JObject

public class DefaultJConstantPool
extends java.lang.Object
implements JConstantPool

The default implementation of the fr.umlv.corosol.classfile.constant.JConstantPool interface.

Author:
Christophe Deleray

Constructor Summary
DefaultJConstantPool()
          Default constructor.
 
Method Summary
 int addConstant(JConstant constant)
          Adds the specified constant in this constant pool.
 int addConstantClass(java.lang.String className)
          Adds a new CONSTANT_Class_info entry corresponding to the specified class name.
 int addConstantDouble(double doubleValue)
          Adds a new CONSTANT_Double_info entry initialized with the specified value.
 int addConstantFieldref(java.lang.String className, java.lang.String name, java.lang.String desc)
          Adds a new CONSTANT_Fieldref_info entry.
 int addConstantFloat(float floatValue)
          Adds a new CONSTANT_Float_info entry initialized with the specified value.
 int addConstantInteger(int intValue)
          Adds a new CONSTANT_Integer_info entry initialized with the specified value.
 int addConstantInterfaceMethodref(java.lang.String className, java.lang.String name, java.lang.String desc)
          Adds a new CONSTANT_InterfaceMethodref_info entry.
 int addConstantLong(long longValue)
          Adds a new CONSTANT_Long_info entry initialized with the specified value.
 int addConstantMethodref(java.lang.String className, java.lang.String name, java.lang.String desc)
          Adds a new CONSTANT_Methodref_info entry.
 int addConstantNameAndType(java.lang.String name, java.lang.String descriptor)
          Adds a new CONSTANT_NameAndType_info entry.
 int addConstantString(java.lang.String string)
          Adds a new CONSTANT_String_info entry initialized with the specified string value.
 int addConstantUtf8(java.lang.String string)
          Adds a new CONSTANT_Utf8_info entry initialized with the specified string value.
 JConstant getConstant(int index)
          Returns the entry at the specified position in this constant pool.
 JConstantPool getConstantPool()
          Returns the constant pool of this classfile item.
 JConstant[] getConstants()
          Returns an array containing all the constant pool entries.
 int length()
          Returns the number of entries in this constant pool.
 void readItem(JClassFileInput in)
          Extracts the data of this classfile item via the specified input stream.
 void setConstantPool(JConstantPool constantPool)
          Sets the constant pool of this classfile item.
 java.lang.String toString()
          Returns a string representation of this constant pool, containing the String representation of each entry.
 void writeItem(JClassFileOutput out)
          Writes the data of this classfile part into a file via the specified output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultJConstantPool

public DefaultJConstantPool()
Default constructor.

Method Detail

addConstant

public int addConstant(JConstant constant)
Adds the specified constant in this constant pool.

Specified by:
addConstant in interface JConstantPool
Parameters:
constant - entry to be added to this constant pool
Returns:
the index of this entry int this constant pool

addConstantUtf8

public int addConstantUtf8(java.lang.String string)
Adds a new CONSTANT_Utf8_info entry initialized with the specified string value.

Specified by:
addConstantUtf8 in interface JConstantPool
Parameters:
string - the string to be stored in the new entry
Returns:
the index of this new constant pool entry

addConstantString

public int addConstantString(java.lang.String string)
Adds a new CONSTANT_String_info entry initialized with the specified string value.

Specified by:
addConstantString in interface JConstantPool
Parameters:
string - the string to be stored in the new entry
Returns:
the index of this new constant pool entry

addConstantClass

public int addConstantClass(java.lang.String className)
Adds a new CONSTANT_Class_info entry corresponding to the specified class name.

Specified by:
addConstantClass in interface JConstantPool
Parameters:
className - a class name
Returns:
the index of this new constant pool entry

addConstantFieldref

public int addConstantFieldref(java.lang.String className,
                               java.lang.String name,
                               java.lang.String desc)
Adds a new CONSTANT_Fieldref_info entry.

Specified by:
addConstantFieldref in interface JConstantPool
Parameters:
className - the name of a class
name - the name of the field
desc - the descriptor of the field
Returns:
the index of this new constant pool entry

addConstantMethodref

public int addConstantMethodref(java.lang.String className,
                                java.lang.String name,
                                java.lang.String desc)
Adds a new CONSTANT_Methodref_info entry.

Specified by:
addConstantMethodref in interface JConstantPool
Parameters:
className - the name of a class
name - the name of the field
desc - the descriptor of the field
Returns:
the index of this new constant pool entry

addConstantInterfaceMethodref

public int addConstantInterfaceMethodref(java.lang.String className,
                                         java.lang.String name,
                                         java.lang.String desc)
Adds a new CONSTANT_InterfaceMethodref_info entry.

Specified by:
addConstantInterfaceMethodref in interface JConstantPool
Parameters:
className - the name of a class
name - the name of the interface method
desc - the descriptor of the interface method
Returns:
the index of this new constant pool entry

addConstantNameAndType

public int addConstantNameAndType(java.lang.String name,
                                  java.lang.String descriptor)
Adds a new CONSTANT_NameAndType_info entry.

Specified by:
addConstantNameAndType in interface JConstantPool
Parameters:
name - the name of a field or a method
descriptor - the descriptor of a field or a method
Returns:
the index of this new constant pool entry

addConstantInteger

public int addConstantInteger(int intValue)
Adds a new CONSTANT_Integer_info entry initialized with the specified value.

Specified by:
addConstantInteger in interface JConstantPool
Parameters:
intValue - the value to be stored in the new entry
Returns:
the index of this new constant pool entry

addConstantFloat

public int addConstantFloat(float floatValue)
Adds a new CONSTANT_Float_info entry initialized with the specified value.

Specified by:
addConstantFloat in interface JConstantPool
Parameters:
floatValue - the value to be stored in the new entry
Returns:
the index of this new constant pool entry

addConstantLong

public int addConstantLong(long longValue)
Adds a new CONSTANT_Long_info entry initialized with the specified value.

Specified by:
addConstantLong in interface JConstantPool
Parameters:
longValue - the value to be stored in the new entry
Returns:
the index of this new constant pool entry

addConstantDouble

public int addConstantDouble(double doubleValue)
Adds a new CONSTANT_Double_info entry initialized with the specified value.

Specified by:
addConstantDouble in interface JConstantPool
Parameters:
doubleValue - the value to be stored in the new entry
Returns:
the index of this new constant pool entry

length

public int length()
Returns the number of entries in this constant pool.

Specified by:
length in interface JConstantPool
Returns:
the number of entries in this constant pool

getConstant

public JConstant getConstant(int index)
Returns the entry at the specified position in this constant pool.

Specified by:
getConstant in interface JConstantPool
Parameters:
index - index of entry to return
Returns:
the entry at the specified position

getConstants

public JConstant[] getConstants()
Returns an array containing all the constant pool entries.

Specified by:
getConstants in interface JConstantPool
Returns:
an array containing all the constant pool entries.

toString

public java.lang.String toString()
Returns a string representation of this constant pool, containing the String representation of each entry.

Specified by:
toString in interface JConstantPool
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this constant pool

getConstantPool

public JConstantPool getConstantPool()
Returns the constant pool of this classfile item.

Specified by:
getConstantPool in interface JClassFileItem

setConstantPool

public void setConstantPool(JConstantPool constantPool)
Sets the constant pool of this classfile item.

Specified by:
setConstantPool in interface JClassFileItem
Parameters:
constantPool - the constant Pool

readItem

public void readItem(JClassFileInput in)
              throws java.io.IOException
Extracts the data of this classfile item via the specified input stream.

Specified by:
readItem in interface JClassFileItem
Parameters:
in - a class file input stream
Throws:
java.io.IOException - if an I/O error occurs when reading this classfile item datas

writeItem

public void writeItem(JClassFileOutput out)
               throws java.io.IOException
Writes the data of this classfile part into a file via the specified output stream.

Specified by:
writeItem in interface JClassFileItem
Parameters:
out - a class file output stream
Throws:
java.io.IOException - if an I/O error occurs when writing into the classfile