fr.umlv.corosol.classfile.attribute.impl
Class DefaultJCodeAttribute

java.lang.Object
  extended by fr.umlv.corosol.classfile.attribute.impl.AbstractJAttribute
      extended by fr.umlv.corosol.classfile.attribute.impl.DefaultJCodeAttribute
All Implemented Interfaces:
JAttribute, JCodeAttribute, JClassFileItem, JObject

public class DefaultJCodeAttribute
extends AbstractJAttribute
implements JCodeAttribute

The default implementation of the JCodeAttribute interface.

Author:
Christophe Deleray

Field Summary
 
Fields inherited from interface fr.umlv.corosol.classfile.attribute.JAttribute
CODE, CONSTANT_VALUE, DEPRECATED, EXCEPTIONS, INNER_CLASSES, LINE_NUMBER_TABLE, LOCAL_VARIABLE_TABLE, SOURCE_FILE, SYNTHETIC
 
Constructor Summary
DefaultJCodeAttribute()
          The default constructor.
DefaultJCodeAttribute(int maxStack, int maxLocals, byte[] byteCode)
          Creates a new Code attribute.
DefaultJCodeAttribute(int maxStack, int maxLocals, byte[] bytes, JExceptionHandler[] handlers, JAttribute[] attributes)
          Creates a new Code attribute.
 
Method Summary
 void addBytecode(int opcode)
          Adds the specified byte code to the byte code handled by this Code attribute.
 void addBytecodes(byte[] b, int off, int len)
          Adds len bytes from the specified byte array starting at offset off to the byte code handled by this Code attribute.
 void addByteOpBytecode(int opcode, int operand)
          Adds the specified byte code and its byte operand to the byte code handled by this Code attribute.
 void addClassOpBytecode(int opcode, java.lang.String className)
          Adds the specified byte code and its short operand determined by the name of a class.
 void addFieldOpBytecode(int opcode, java.lang.String className, java.lang.String name, java.lang.String desc)
          Adds the specified byte code and its short operand determined by the declaring class, the name and the descriptor of a field.
 void addIntOpBytecode(int opcode, int operand)
          Adds the specified byte code and its int operand to the byte code handled by this Code attribute.
 void addInvokeinterface(java.lang.String className, java.lang.String name, java.lang.String desc)
          Adds the invokeinterface byte code and its short operand determined by the declaring class, the name and the descriptor of an interface method.
 void addMethodOpBytecode(int opcode, java.lang.String className, java.lang.String name, java.lang.String desc)
          Adds the specified byte code and its short operand determined by the declaring class, the name and the descriptor of a method.
 void addShortOpBytecode(int opcode, int operand)
          Adds the specified byte code and its short operand to the byte code handled by this Code attribute.
 JAttribute[] getAttributes()
          Returns an array of attributes associated with this Code attribute.
 byte[] getByteCode()
          Returns the bytes code of a method.
 JExceptionHandler[] getExceptionHandlers()
          Returns an array containg the exception handlers in the byte code array of a method.
 int getMaxLocals()
          Returns the number of local variables in the local variable array allocated upon invocation of a method, including the local variables used to pass parameters to this method on its invocation.
 int getMaxStack()
          Returns the maximum depth of the operand stack at any point during execution of a method.
 java.lang.String getName()
          Returns the attribute name.
 int getSize()
          Returns the size of the attribute in bytes.
 void readItem(JClassFileInput in)
          Extracts the data of this classfile part from the specified input stream.
 void setAttributes(JAttribute[] attributes)
          Sets the optional attributes associated with this Code attribute.
 void setByteCode(byte[] bytes)
          Sets the bytecode of a method whith the specified byte array.
 void setExceptionHandlers(JExceptionHandler[] handlers)
          Sets the exception handlers in the byte code of a method.
 void setMaxLocals(int maxLocals)
          Sets the number of local variables in the local variable array allocated upon invocation of a method, including the local variables used to pass parameters to this method on its invocation.
 void setMaxStack(int maxStack)
          Sets the maximum depth of the operand stack at any point during execution of a method.
 java.lang.String toString()
          Returns a string representation of this attribute.
 void writeItem(JClassFileOutput out)
          Writes the data of this attribute into a file via the specified output stream.
 
Methods inherited from class fr.umlv.corosol.classfile.attribute.impl.AbstractJAttribute
getConstantPool, setConstantPool
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fr.umlv.corosol.classfile.JClassFileItem
getConstantPool, setConstantPool
 

Constructor Detail

DefaultJCodeAttribute

public DefaultJCodeAttribute()
The default constructor.


DefaultJCodeAttribute

public DefaultJCodeAttribute(int maxStack,
                             int maxLocals,
                             byte[] bytes,
                             JExceptionHandler[] handlers,
                             JAttribute[] attributes)
Creates a new Code attribute.

Parameters:
maxStack - the max depth of the operand stack
maxLocals - the length of the local variables array
bytes - the byte code of the method
handlers - an array of exception handlers
attributes - an array of optional attributes

DefaultJCodeAttribute

public DefaultJCodeAttribute(int maxStack,
                             int maxLocals,
                             byte[] byteCode)
Creates a new Code attribute.

Parameters:
maxStack - the max depth of the operand stack
maxLocals - the length of the local variables array
byteCode - the byte code of the method
Method Detail

getMaxStack

public int getMaxStack()
Returns the maximum depth of the operand stack at any point during execution of a method.

Specified by:
getMaxStack in interface JCodeAttribute

getMaxLocals

public int getMaxLocals()
Returns the number of local variables in the local variable array allocated upon invocation of a method, including the local variables used to pass parameters to this method on its invocation.

Specified by:
getMaxLocals in interface JCodeAttribute

getByteCode

public byte[] getByteCode()
Returns the bytes code of a method.

Specified by:
getByteCode in interface JCodeAttribute

getExceptionHandlers

public JExceptionHandler[] getExceptionHandlers()
Returns an array containg the exception handlers in the byte code array of a method.

Specified by:
getExceptionHandlers in interface JCodeAttribute

getAttributes

public JAttribute[] getAttributes()
Returns an array of attributes associated with this Code attribute.

Specified by:
getAttributes in interface JCodeAttribute

getName

public java.lang.String getName()
Returns the attribute name.

Specified by:
getName in interface JAttribute
Overrides:
getName in class AbstractJAttribute

getSize

public int getSize()
Returns the size of the attribute in bytes.

Specified by:
getSize in interface JAttribute
Specified by:
getSize in class AbstractJAttribute

setMaxStack

public void setMaxStack(int maxStack)
Sets the maximum depth of the operand stack at any point during execution of a method.

Specified by:
setMaxStack in interface JCodeAttribute
Parameters:
maxStack - the max size of the operand stack of a frame

setMaxLocals

public void setMaxLocals(int maxLocals)
Sets the number of local variables in the local variable array allocated upon invocation of a method, including the local variables used to pass parameters to this method on its invocation.

Specified by:
setMaxLocals in interface JCodeAttribute
Parameters:
maxLocals - the max size of the local variable array of a frame

setByteCode

public void setByteCode(byte[] bytes)
Sets the bytecode of a method whith the specified byte array.

Specified by:
setByteCode in interface JCodeAttribute
Parameters:
bytes - the bytecode of a method

setExceptionHandlers

public void setExceptionHandlers(JExceptionHandler[] handlers)
Sets the exception handlers in the byte code of a method.

Specified by:
setExceptionHandlers in interface JCodeAttribute
Parameters:
handlers - the exception handlers of the byte code of a method

setAttributes

public void setAttributes(JAttribute[] attributes)
Sets the optional attributes associated with this Code attribute.

Specified by:
setAttributes in interface JCodeAttribute
Parameters:
attributes - an array of optional attributes

toString

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

Specified by:
toString in interface JAttribute
Specified by:
toString in class AbstractJAttribute
Returns:
a string representing this classfile attribute

readItem

public void readItem(JClassFileInput in)
              throws java.io.IOException
Extracts the data of this classfile part from 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 the datas of this attribute

writeItem

public void writeItem(JClassFileOutput out)
               throws java.io.IOException
Writes the data of this attribute 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

addBytecode

public void addBytecode(int opcode)
Adds the specified byte code to the byte code handled by this Code attribute.

Specified by:
addBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction

addByteOpBytecode

public void addByteOpBytecode(int opcode,
                              int operand)
Adds the specified byte code and its byte operand to the byte code handled by this Code attribute.

Specified by:
addByteOpBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction
operand - the byte operand of the instruction

addShortOpBytecode

public void addShortOpBytecode(int opcode,
                               int operand)
Adds the specified byte code and its short operand to the byte code handled by this Code attribute.

Specified by:
addShortOpBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction
operand - the short operand of the instruction

addIntOpBytecode

public void addIntOpBytecode(int opcode,
                             int operand)
Adds the specified byte code and its int operand to the byte code handled by this Code attribute.

Specified by:
addIntOpBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction
operand - the int operand of the instruction

addBytecodes

public void addBytecodes(byte[] b,
                         int off,
                         int len)
Adds len bytes from the specified byte array starting at offset off to the byte code handled by this Code attribute.

Specified by:
addBytecodes in interface JCodeAttribute
Parameters:
b - the byte code data.
off - the start offset in the data.
len - the number of bytes to write.

addClassOpBytecode

public void addClassOpBytecode(int opcode,
                               java.lang.String className)
Adds the specified byte code and its short operand determined by the name of a class. This operand is an index of a Constant\_Class\_info constant pool entry.

Specified by:
addClassOpBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction
className - the name of a class

addMethodOpBytecode

public void addMethodOpBytecode(int opcode,
                                java.lang.String className,
                                java.lang.String name,
                                java.lang.String desc)
Adds the specified byte code and its short operand determined by the declaring class, the name and the descriptor of a method. This operand is an index of a Constant\_Methodref\_info constant pool entry.

Specified by:
addMethodOpBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction
className - the declaring class of a method
name - the name of a method
desc - the name of a method

addInvokeinterface

public void addInvokeinterface(java.lang.String className,
                               java.lang.String name,
                               java.lang.String desc)
Adds the invokeinterface byte code and its short operand determined by the declaring class, the name and the descriptor of an interface method. This operand is an index of a Constant\_InterfaceMethodref\_info constant pool entry.

Specified by:
addInvokeinterface in interface JCodeAttribute
Parameters:
className - the declaring class of an interface method
name - the name of an interface method
desc - the name of an interface method

addFieldOpBytecode

public void addFieldOpBytecode(int opcode,
                               java.lang.String className,
                               java.lang.String name,
                               java.lang.String desc)
Adds the specified byte code and its short operand determined by the declaring class, the name and the descriptor of a field. This operand is an index of a Constant\_Fieldref\_info constant pool entry.

Specified by:
addFieldOpBytecode in interface JCodeAttribute
Parameters:
opcode - the opcode of a byte code instruction
className - the declaring class of a field
name - the name of a field
desc - the name of a field