Package EDU.purdue.cs.bloat.file
Class Code
- java.lang.Object
-
- EDU.purdue.cs.bloat.file.Attribute
-
- EDU.purdue.cs.bloat.file.Code
-
public class Code extends Attribute
Code is used to store the Code attribute of a method in a class file. The Code attribute stores the raw bytecode of the method, the maximum stack height and maximum number of locals used by the method, and the exception handlers used in the method. Code may have several attributes. The local variable table and the line number table are modeled explicitly. All other attributes are modeled as generic attributes.- See Also:
Catch,GenericAttribute,LineNumberDebugInfo,LocalVariableTable
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()byte[]code()Get the bytes of the code.intcodeLength()Return the length of the code arrayCatch[]exceptionHandlers()Get the exception handlers in the method.intlength()Get the length of the attribute.LineNumberDebugInfo[]lineNumbers()Get the line number debug info for the code.LocalDebugInfo[]locals()Get the local variable debug info for the code.intmaxLocals()Get the maximum number of locals used by the code.intmaxStack()Get the maximum height of the operand stack used by the code.voidsetCode(byte[] code)Set the bytes of the code.voidsetExceptionHandlers(Catch[] handlers)Set the exception handlers in the method.voidsetLineNumbers(LineNumberDebugInfo[] lineNumbers)Set the line number debug info for the code.voidsetLocals(LocalDebugInfo[] locals)Set the local variable debug info for the code.voidsetMaxLocals(int maxLocals)Set the maximum number of locals used by the code.voidsetMaxStack(int maxStack)Set the maximum height of the operand stack used by the code.java.lang.StringtoString()Returns a string representation of the attribute.voidwriteData(java.io.DataOutputStream out)Write the attribute to a data stream.
-
-
-
Constructor Detail
-
Code
public Code(ClassInfo classInfo, java.io.DataInputStream in, int index, int len) throws java.io.IOException
Constructor. Create a Code attribute from a data stream.- Parameters:
in- The data stream containing the class file.index- The index into the constant pool of the name of the attribute.len- The length of the attribute, excluding the header.- Throws:
java.io.IOException- If an error occurs while reading.
-
-
Method Detail
-
writeData
public void writeData(java.io.DataOutputStream out) throws java.io.IOExceptionWrite the attribute to a data stream.
-
setMaxStack
public void setMaxStack(int maxStack)
Set the maximum height of the operand stack used by the code.- Parameters:
maxStack- The maximum height of the stack.
-
setMaxLocals
public void setMaxLocals(int maxLocals)
Set the maximum number of locals used by the code.- Parameters:
maxLocals- The maximum number of locals.
-
maxStack
public int maxStack()
Get the maximum height of the operand stack used by the code.- Returns:
- The maximum number of locals.
-
maxLocals
public int maxLocals()
Get the maximum number of locals used by the code.- Returns:
- The maximum number of locals.
-
setExceptionHandlers
public void setExceptionHandlers(Catch[] handlers)
Set the exception handlers in the method.- Parameters:
handlers- The handlers.
-
length
public int length()
Get the length of the attribute.
-
lineNumbers
public LineNumberDebugInfo[] lineNumbers()
Get the line number debug info for the code.- Returns:
- The line number debug info for the code.
-
locals
public LocalDebugInfo[] locals()
Get the local variable debug info for the code.- Returns:
- The local variable debug info for the code.
-
setLineNumbers
public void setLineNumbers(LineNumberDebugInfo[] lineNumbers)
Set the line number debug info for the code.- Parameters:
lineNumbers- The line number debug info for the code.
-
setLocals
public void setLocals(LocalDebugInfo[] locals)
Set the local variable debug info for the code.- Parameters:
locals- The local variable debug info for the code.
-
exceptionHandlers
public Catch[] exceptionHandlers()
Get the exception handlers in the method.- Returns:
- The handlers.
-
code
public byte[] code()
Get the bytes of the code.- Returns:
- The code.
-
codeLength
public int codeLength()
Return the length of the code array
-
setCode
public void setCode(byte[] code)
Set the bytes of the code.- Parameters:
code- The code.
-
-