fr.umlv.corosol.classfile.impl
Class DefaultJClassFile

java.lang.Object
  extended by fr.umlv.corosol.classfile.impl.DefaultJClassFile
All Implemented Interfaces:
JClassFile, JClassFileItem, JObject

public class DefaultJClassFile
extends java.lang.Object
implements JClassFile

The default implementation of the fr.umlv.corosol.classfile.JClassFile interface.

Author:
Christophe Deleray

Constructor Summary
DefaultJClassFile()
          The default constructor.
 
Method Summary
 void addAttribute(JAttribute attribute)
          Adds an attributes of this class file.
 void addConstructor(JClassMember constructor)
          Adds and returns a new constructor to the class defined by this class file.
 JClassMember addConstructor(java.lang.String descriptor, int accessFlags, JAttribute[] attributes)
          Adds and returns a new constructor to the class defined by this class file.
 JClassMember addDefaultConstructor(int accessFlags)
          Adds and returns a default constructor to the class defined by this class file.
 void addField(JClassMember field)
          Adds and returns a new field to the class defined by this class file.
 JClassMember addField(java.lang.String name, java.lang.String descriptor, int accessFlags, JAttribute[] attributes)
          Adds and returns a new field to the class defined by this class file.
 void addInterface(java.lang.String name)
          Adds the specified super interface to the class defined by this class file.
 void addMethod(JClassMember method)
          Adds and returns a new method to the class defined by this class file.
 JClassMember addMethod(java.lang.String name, java.lang.String descriptor, int accessFlags, JAttribute[] attributes)
          Adds and returns a new method to the class defined by this class file.
 int getAccessFlags()
          Returns the mask of flags used to denote access permissions to and properties of the class or interface represented by this JClassFile object.
 JAttribute[] getAttributes()
          Returns an array of attributes of this class file.
 JConstantPool getConstantPool()
          Returns the constant pool of the class represented by this JClassFile object.
 JClassMember getDeclaredConstructor(java.lang.String desc)
          Returns the constructor with the specified descriptor.
 JClassMember[] getDeclaredConstructors()
          Returns an array of JClassMember object, corresponding to the constructors declared by the class defined by this class file.
 JClassMember getDeclaredField(java.lang.String name)
          Returns the field with the specified name.
 JClassMember[] getDeclaredFields()
          Returns an array of JClassMember object, corresponding to the fields declared by the class defined by this class file.
 JClassMember getDeclaredMethod(java.lang.String name, java.lang.String desc)
          Returns the method with the specified name and descriptor.
 JClassMember[] getDeclaredMethods()
          Returns an array of JClassMember object, corresponding to the methods declared by the class defined by this class file.
 int[] getInterfaceIndex()
          Returns an array containing index of constant pool entry describing a super interface of the class defined by this class file.
 java.lang.String[] getInterfaceNames()
          Returns an array of String object, corresponding to the name of super interface of the class defined by this class file.
 int getMajorVersion()
          Returns the major version of the classfile.
 int getMinorVersion()
          Returns the minor version of the classfile.
 java.lang.String getName()
          Returns the name of the class represented by this class file.
 int getSuperclassIndex()
          Returns the index into a CONSTANT_Class_info constant pool entry representing the superclass of the class defined by this class file.
 java.lang.String getSuperclassName()
          Returns the name of the superclass of the class represented by this class file.
 int getThisClassIndex()
          Returns the index of the CONSTANT_Class_info constant pool entry representing the class or interface defined by this class file.
 void readItem(JClassFileInput in)
          Extracts the data of this classfile item via the specified input stream.
 void removeDefaultConstructor()
          Removes the default constructor of the class defined by this class file.
 void setAccessFlags(int accessFlags)
          Sets the mask of flags used to denote access permissions to and properties of the class or interface represented by this JClassFile object.
 void setConstantPool(JConstantPool constantPool)
          Sets the constant pool of the class represented by this JClassFile object.
 void setDeclaredConstructors(JClassMember[] constructors)
          Sets the constructors of the class defined by this class file.
 void setDeclaredFields(JClassMember[] fields)
          Sets the declared fields of the class defined by this class file.
 void setDeclaredMethods(JClassMember[] methods)
          Sets the methods of the class defined by this class file.
 void setInterfaceIndex(int[] interfaceIndex)
          Sets the array containing index of constant pool entry describing a super interface of the class defined by this class file.
 void setMajorVersion(int majorVersion)
          Sets the major version of the classfile.
 void setMinorVersion(int minorVersion)
          Sets the minor version of the classfile.
 void setName(java.lang.String name)
          Sets the name of the class represented by this class file.
 void setSuperclassIndex(int superclassIndex)
          Sets the index into a CONSTANT_Class_info constant pool entry representing the superclass of the class defined by this class file.
 void setSuperclassName(java.lang.String name)
          Sets the name of the superclass of the class represented by this class file.
 void setThisClassIndex(int thisClassIndex)
          Sets the index into a CONSTANT_Class_info constant pool entry representing the class or interface defined by this class file.
 java.lang.String toString()
          Returns a string representation of this classfile.
 void writeItem(JClassFileOutput out)
          Writes the data of this classfile 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

DefaultJClassFile

public DefaultJClassFile()
The default constructor.

Method Detail

getMinorVersion

public int getMinorVersion()
Returns the minor version of the classfile.

Specified by:
getMinorVersion in interface JClassFile

setMinorVersion

public void setMinorVersion(int minorVersion)
Sets the minor version of the classfile.

Specified by:
setMinorVersion in interface JClassFile
Parameters:
minorVersion - the minor version of the classfile.

getMajorVersion

public int getMajorVersion()
Returns the major version of the classfile.

Specified by:
getMajorVersion in interface JClassFile

setMajorVersion

public void setMajorVersion(int majorVersion)
Sets the major version of the classfile.

Specified by:
setMajorVersion in interface JClassFile
Parameters:
majorVersion - the major version of the classfile.

getConstantPool

public JConstantPool getConstantPool()
Returns the constant pool of the class represented by this JClassFile object.

Specified by:
getConstantPool in interface JClassFileItem
Returns:
the constant pool

setConstantPool

public void setConstantPool(JConstantPool constantPool)
Sets the constant pool of the class represented by this JClassFile object.

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

getAccessFlags

public int getAccessFlags()
Returns the mask of flags used to denote access permissions to and properties of the class or interface represented by this JClassFile object.

Specified by:
getAccessFlags in interface JClassFile
Returns:
the access flags of the class

setAccessFlags

public void setAccessFlags(int accessFlags)
Sets the mask of flags used to denote access permissions to and properties of the class or interface represented by this JClassFile object.

Specified by:
setAccessFlags in interface JClassFile
Parameters:
accessFlags - the access flags of the class

getThisClassIndex

public int getThisClassIndex()
Returns the index of the CONSTANT_Class_info constant pool entry representing the class or interface defined by this class file.

Specified by:
getThisClassIndex in interface JClassFile
Returns:
the index of a constant pool entry representing the class

setThisClassIndex

public void setThisClassIndex(int thisClassIndex)
Sets the index into a CONSTANT_Class_info constant pool entry representing the class or interface defined by this class file.

Specified by:
setThisClassIndex in interface JClassFile
Parameters:
thisClassIndex - the index of a constant pool entry representing the class

getSuperclassIndex

public int getSuperclassIndex()
Returns the index into a CONSTANT_Class_info constant pool entry representing the superclass of the class defined by this class file. The index which is returned may be zero, and then the class has not superclass.

Specified by:
getSuperclassIndex in interface JClassFile
Returns:
the index of a constant pool entry representing the superclass of the class

setSuperclassIndex

public void setSuperclassIndex(int superclassIndex)
Sets the index into a CONSTANT_Class_info constant pool entry representing the superclass of the class defined by this class file. The index which is returned may be zero, and then the class has not superclass.

Specified by:
setSuperclassIndex in interface JClassFile
Parameters:
superclassIndex - the index of a constant pool entry representing the superclass of the class

getInterfaceIndex

public int[] getInterfaceIndex()
Returns an array containing index of constant pool entry describing a super interface of the class defined by this class file.

Specified by:
getInterfaceIndex in interface JClassFile
Returns:
an array of constant pool entry index describing super interfaces

setInterfaceIndex

public void setInterfaceIndex(int[] interfaceIndex)
Sets the array containing index of constant pool entry describing a super interface of the class defined by this class file.

Specified by:
setInterfaceIndex in interface JClassFile
Parameters:
interfaceIndex - an array of index describing the super interfaces

getName

public java.lang.String getName()
Returns the name of the class represented by this class file.

Specified by:
getName in interface JClassFile
Returns:
the name of the class

setName

public void setName(java.lang.String name)
Sets the name of the class represented by this class file.

Specified by:
setName in interface JClassFile
Parameters:
name - the name of the class

getSuperclassName

public java.lang.String getSuperclassName()
Returns the name of the superclass of the class represented by this class file.

Specified by:
getSuperclassName in interface JClassFile
Returns:
the name of the superclass

setSuperclassName

public void setSuperclassName(java.lang.String name)
Sets the name of the superclass of the class represented by this class file.

Specified by:
setSuperclassName in interface JClassFile
Parameters:
name - the name of the superclass

getInterfaceNames

public java.lang.String[] getInterfaceNames()
Returns an array of String object, corresponding to the name of super interface of the class defined by this class file.

Specified by:
getInterfaceNames in interface JClassFile
Returns:
an array of String, describing the name of the super interfaces

addInterface

public void addInterface(java.lang.String name)
Adds the specified super interface to the class defined by this class file.

Specified by:
addInterface in interface JClassFile
Parameters:
name - the name of the super interface

getDeclaredFields

public JClassMember[] getDeclaredFields()
Returns an array of JClassMember object, corresponding to the fields declared by the class defined by this class file.

Specified by:
getDeclaredFields in interface JClassFile
Returns:
an array of JClassMember representing fields

getDeclaredMethods

public JClassMember[] getDeclaredMethods()
Returns an array of JClassMember object, corresponding to the methods declared by the class defined by this class file.

Specified by:
getDeclaredMethods in interface JClassFile
Returns:
an array of JClassMember representing methods

getDeclaredConstructors

public JClassMember[] getDeclaredConstructors()
Returns an array of JClassMember object, corresponding to the constructors declared by the class defined by this class file.

Specified by:
getDeclaredConstructors in interface JClassFile
Returns:
an array of JClassMember representing constructors

setDeclaredFields

public void setDeclaredFields(JClassMember[] fields)
Sets the declared fields of the class defined by this class file.

Specified by:
setDeclaredFields in interface JClassFile
Parameters:
fields - an array of new fields

setDeclaredMethods

public void setDeclaredMethods(JClassMember[] methods)
Sets the methods of the class defined by this class file.

Specified by:
setDeclaredMethods in interface JClassFile
Parameters:
methods - an array of new methods

setDeclaredConstructors

public void setDeclaredConstructors(JClassMember[] constructors)
Sets the constructors of the class defined by this class file.

Specified by:
setDeclaredConstructors in interface JClassFile
Parameters:
constructors - an array of new constructors

getDeclaredField

public JClassMember getDeclaredField(java.lang.String name)
Returns the field with the specified name.

Specified by:
getDeclaredField in interface JClassFile
Parameters:
name - the field name
Returns:
a JClassMember object representing the specified field or null if it is not declared by this class.

getDeclaredMethod

public JClassMember getDeclaredMethod(java.lang.String name,
                                      java.lang.String desc)
Returns the method with the specified name and descriptor.

Specified by:
getDeclaredMethod in interface JClassFile
Parameters:
name - the method name
desc - the method descriptor
Returns:
a JClassMember object representing the specified method or null if it is not declared by this class.

getDeclaredConstructor

public JClassMember getDeclaredConstructor(java.lang.String desc)
Returns the constructor with the specified descriptor.

Specified by:
getDeclaredConstructor in interface JClassFile
Parameters:
desc - the constructor descriptor
Returns:
a JClassMember object representing the specified constructor or null if it is not declared by this class.

removeDefaultConstructor

public void removeDefaultConstructor()
Removes the default constructor of the class defined by this class file.

Specified by:
removeDefaultConstructor in interface JClassFile

addField

public JClassMember addField(java.lang.String name,
                             java.lang.String descriptor,
                             int accessFlags,
                             JAttribute[] attributes)
Adds and returns a new field to the class defined by this class file.

Specified by:
addField in interface JClassFile
Parameters:
name - the field name
descriptor - the field descriptor
accessFlags - the access flag of the field
attributes - the field attributes
Returns:
the new field

addField

public void addField(JClassMember field)
Adds and returns a new field to the class defined by this class file.

Specified by:
addField in interface JClassFile
Parameters:
field - a new field

addMethod

public JClassMember addMethod(java.lang.String name,
                              java.lang.String descriptor,
                              int accessFlags,
                              JAttribute[] attributes)
Adds and returns a new method to the class defined by this class file.

Specified by:
addMethod in interface JClassFile
Parameters:
name - the method name
descriptor - the method descriptor
accessFlags - the access flag of the method
attributes - the method attributes
Returns:
the new method

addMethod

public void addMethod(JClassMember method)
Adds and returns a new method to the class defined by this class file.

Specified by:
addMethod in interface JClassFile
Parameters:
method - a new method

addConstructor

public JClassMember addConstructor(java.lang.String descriptor,
                                   int accessFlags,
                                   JAttribute[] attributes)
Adds and returns a new constructor to the class defined by this class file.

Specified by:
addConstructor in interface JClassFile
Parameters:
descriptor - the constructor descriptor
accessFlags - the access flag of the constructor
attributes - the constructor attributes
Returns:
the new constructor

addConstructor

public void addConstructor(JClassMember constructor)
Adds and returns a new constructor to the class defined by this class file.

Specified by:
addConstructor in interface JClassFile
Parameters:
constructor - a new constructor

addDefaultConstructor

public JClassMember addDefaultConstructor(int accessFlags)
Adds and returns a default constructor to the class defined by this class file.

Specified by:
addDefaultConstructor in interface JClassFile
Parameters:
accessFlags - the access flag of the default constructor
Returns:
the new default constructor

getAttributes

public JAttribute[] getAttributes()
Returns an array of attributes of this class file.

Specified by:
getAttributes in interface JClassFile
Returns:
an array of attributes

addAttribute

public void addAttribute(JAttribute attribute)
Adds an attributes of this class file.

Specified by:
addAttribute in interface JClassFile
Parameters:
attribute - an attribute

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.lang.ClassFormatError - if an I/O error occurs when readind the datas of thi classfile
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 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

toString

public java.lang.String toString()
Returns a string representation of this classfile.

Specified by:
toString in interface JClassFile
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this classfile