sysModel.classFile.attributes
Class CodeAttributeInfo

java.lang.Object
  extended by sysModel.classFile.attributes.AAttributeInfo
      extended by sysModel.classFile.attributes.CodeAttributeInfo
All Implemented Interfaces:
java.lang.Cloneable

public class CodeAttributeInfo
extends AAttributeInfo

Represents the Code attribute in a class file.

Author:
Mathias Ricken

Nested Class Summary
static class CodeAttributeInfo.CodeProperties
          Storage class for code properties.
static class CodeAttributeInfo.ExceptionTableEntry
           
 
Field Summary
protected  CodeAttributeInfo.CodeProperties _props
          Properties read out from _data field.
 
Fields inherited from class sysModel.classFile.attributes.AAttributeInfo
_constantPool, _data, _name
 
Constructor Summary
CodeAttributeInfo(AUTFPoolInfo name, byte[] data, ConstantPool cp)
          Constructor.
CodeAttributeInfo(AUTFPoolInfo name, short maxStack, short maxLocals, byte[] code, CodeAttributeInfo.ExceptionTableEntry[] exceptionTableEntries, AAttributeInfo[] attributes, ConstantPool cp)
          Constructor.
 
Method Summary
 void adjustPC(short startPC, short deltaPC)
          Adjust program counter values contained in this attribute, starting at startPC, by adding deltaPC to them.
 java.lang.Object clone()
          Creates and returns a copy of this object.
<R,D> R
execute(IAttributeVisitor<R,D> visitor, D param)
          Execute a visitor on this attribute.
static java.lang.String getAttributeName()
          Returns the name of the attribute as it appears in the class file.
 AAttributeInfo[] getAttributes()
          Return a copy of the attributes.
 byte[] getCode()
          Return a copy of the code bytes.
 CodeAttributeInfo.ExceptionTableEntry[] getExceptionTableEntries()
          Return a copy of the exception table entries.
 CodeAttributeInfo.CodeProperties getProperties()
          Return a copy of the code properties.
 void setAttributes(AAttributeInfo[] a)
          Sets the attribute list.
 void setCode(byte[] code)
          Set the code bytes.
 void setData(byte[] data)
          Mutator for data.
 void setExceptionTableEntries(CodeAttributeInfo.ExceptionTableEntry[] e)
          Set the exception table entries.
 void setProperties(short maxStack, short maxLocals)
          Set the code properties.
 java.lang.String toString()
          Return a human-readable version of this attribute.
 void translatePC(short index, short deltaIndex, LineNumberTable oldLnt, LineNumberTable newLnt)
          Translate the program counter values contained in this attribute from an old line number table to a new one.
 
Methods inherited from class sysModel.classFile.attributes.AAttributeInfo
getData, getName, lone, read, setName, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_props

protected CodeAttributeInfo.CodeProperties _props
Properties read out from _data field.

Constructor Detail

CodeAttributeInfo

public CodeAttributeInfo(AUTFPoolInfo name,
                         byte[] data,
                         ConstantPool cp)
                  throws java.lang.ClassFormatError
Constructor.

Parameters:
name - attribute name
data - attribute data
cp - constant pool
Throws:
java.lang.ClassFormatError

CodeAttributeInfo

public CodeAttributeInfo(AUTFPoolInfo name,
                         short maxStack,
                         short maxLocals,
                         byte[] code,
                         CodeAttributeInfo.ExceptionTableEntry[] exceptionTableEntries,
                         AAttributeInfo[] attributes,
                         ConstantPool cp)
                  throws java.lang.ClassFormatError,
                         java.io.IOException
Constructor.

Parameters:
name - attribute name, must be a UTF item "Code"
maxStack - maximum state size
maxLocals - maximum number of locals
code - bytecode
exceptionTableEntries - exception table entries
attributes - attributes
cp - constant pool
Throws:
java.lang.ClassFormatError
java.io.IOException
Method Detail

setData

public void setData(byte[] data)
Mutator for data.

Overrides:
setData in class AAttributeInfo
Parameters:
data - data

getProperties

public CodeAttributeInfo.CodeProperties getProperties()
                                               throws java.lang.ClassFormatError
Return a copy of the code properties.

Returns:
code properties
Throws:
java.lang.ClassFormatError

setProperties

public void setProperties(short maxStack,
                          short maxLocals)
Set the code properties.

Parameters:
maxStack - new maximum state
maxLocals - new maximum locals
Throws:
java.lang.ClassFormatError

getCode

public byte[] getCode()
Return a copy of the code bytes.

Returns:
code bytes

setCode

public void setCode(byte[] code)
             throws java.lang.IllegalArgumentException
Set the code bytes.

Parameters:
code - new code bytes
Throws:
java.lang.IllegalArgumentException

getExceptionTableEntries

public CodeAttributeInfo.ExceptionTableEntry[] getExceptionTableEntries()
Return a copy of the exception table entries.

Returns:
entries

setExceptionTableEntries

public void setExceptionTableEntries(CodeAttributeInfo.ExceptionTableEntry[] e)
                              throws java.lang.IllegalArgumentException
Set the exception table entries.

Parameters:
e - entries
Throws:
java.lang.IllegalArgumentException

getAttributes

public AAttributeInfo[] getAttributes()
                               throws java.lang.ClassFormatError
Return a copy of the attributes.

Returns:
attributes
Throws:
java.lang.ClassFormatError

setAttributes

public void setAttributes(AAttributeInfo[] a)
                   throws java.lang.ClassFormatError,
                          java.lang.IllegalArgumentException
Sets the attribute list.

Parameters:
a - attributes
Throws:
java.lang.ClassFormatError
java.lang.IllegalArgumentException

execute

public <R,D> R execute(IAttributeVisitor<R,D> visitor,
                       D param)
Execute a visitor on this attribute.

Specified by:
execute in class AAttributeInfo
Parameters:
visitor - visitor
param - visitor-specific parameter
Returns:
visitor-specific return value

toString

public java.lang.String toString()
Return a human-readable version of this attribute.

Overrides:
toString in class AAttributeInfo
Returns:
string

adjustPC

public void adjustPC(short startPC,
                     short deltaPC)
Adjust program counter values contained in this attribute, starting at startPC, by adding deltaPC to them. NOTE: This does not transform branch targets in the code.

Specified by:
adjustPC in class AAttributeInfo
Parameters:
startPC - program counter to start at
deltaPC - change in program counter values

translatePC

public void translatePC(short index,
                        short deltaIndex,
                        LineNumberTable oldLnt,
                        LineNumberTable newLnt)
Translate the program counter values contained in this attribute from an old line number table to a new one.

Specified by:
translatePC in class AAttributeInfo
Parameters:
index - critical point (insertion or deletion point)
deltaIndex - delta value to add to all old line numbers greater than the critical point
oldLnt - old line number table
newLnt - new line number table

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

getAttributeName

public static java.lang.String getAttributeName()
Returns the name of the attribute as it appears in the class file.

Returns:
name of the attribute.