public class CfMethod extends CfFieldOrMethod implements AttributeHandler
Methods are organized into a linked list within our ClassFile, rather than an array, to allow for efficient dynamic growth.
This class differs greatly from the ClassFile representation, in that the members of the Code attribute are represented here rather than having a separate Code class. From a programmer's perspective, a Method has a sequence of instructions, rather than a Method having a Code attribute which then has instructions.
Modifier and Type | Method and Description |
---|---|
void |
addHandler(ExceptionHandler h) |
void |
addHandler(int startPc,
int endPc,
int handlerPc,
CpClass catchType) |
void |
addLine(LineNumber line)
Append the given line number to the end of the linked-list of locals
for this line number table.
|
void |
addLocal(LocalVariable local)
Append the given local to the end of the linked-list of locals for this
local variable table.
|
void |
createLocalsFromSignature()
Based on the method signature, automatically build a set of matching
LocalVariables.
|
byte[] |
getCode() |
Attribute |
getCodeAttributes() |
CodeBuilder |
getCodeBuilder()
Return a CodeBuilder for constructing the method code attribute.
|
int[] |
getExceptionCps() |
int |
getHandlerCount() |
ExceptionHandler |
getHandlers() |
ExceptionHandler |
getLastHandler() |
LineNumber |
getLastLine() |
LocalVariable |
getLastLocal() |
int |
getLineCount() |
LineNumber |
getLines() |
LocalVariable |
getLocal(int index)
Return the first found local variable that occupies the given index.
|
LocalVariable |
getLocals() |
int |
getLocalsCount() |
int |
getMaxLocals()
Max local variable index as per class file specification.
|
int |
getMaxStack() |
CfMethod |
getNext() |
CpRef |
getRef()
Return a Cp(Method)Ref for invoking this method.
|
int |
getReturnType()
Return the return type of this method as one of the JVM.T_XXX
constants.
|
boolean |
handleAttribute(java.io.DataInputStream dataIn,
java.lang.String name,
int length)
For methods we must recognize:
Code, Exceptions, Synthetic, Deprecated.
|
void |
read(java.io.DataInputStream dataIn)
Read the member from the given stream, overwriting any previous values.
|
void |
setCode(byte[] code) |
void |
setCodeAttributes(Attribute codeAttributes) |
void |
setExceptionCps(int[] exceptionCps) |
void |
setExceptions(java.lang.Class[] exceptions) |
void |
setHandlerCount(int handlerCount) |
void |
setHandlers(ExceptionHandler handlers) |
void |
setLastHandler(ExceptionHandler lastHandler) |
void |
setLastLine(LineNumber lastLine) |
void |
setLastLocal(LocalVariable lastLocal) |
void |
setLineCount(int lineCount) |
void |
setLines(LineNumber lines) |
void |
setLocals(LocalVariable locals) |
void |
setLocalsCount(int localsCount) |
void |
setMaxLocals(int maxLocals) |
void |
setMaxStack(int maxStack) |
void |
setNext(CfMethod next) |
void |
write(java.io.DataOutput dout)
Write the field or method to a stream in JVM classfile format.
|
getClassFile, getConstantPool, getDescriptorIndex, getName, getNameIndex, getSignature, isSynthetic, setDescriptorIndex, setNameIndex, setSynthetic
getAccessFlags, getAttributeCount, getAttributes, isAbstract, isDeprecated, isFinal, isInterface, isNative, isPrivate, isProtected, isPublic, isStatic, isStrict, isSynchronized, isTransient, isVolatile, setAbstract, setAccessFlags, setAttributes, setDeprecated, setFinal, setInterface, setNative, setPrivate, setProtected, setPublic, setStatic, setStrict, setSynchronized, setTransient, setVolatile
public CfMethod(ClassFile classFile)
public CfMethod getNext()
public void setNext(CfMethod next)
public void read(java.io.DataInputStream dataIn) throws java.io.IOException, ClassFileFormatException
CfFieldOrMethod
Subclasses must override this method, first invoking this one, and then processing attributes.
field_info { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; } method_info { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; }
read
in class CfFieldOrMethod
java.io.IOException
ClassFileFormatException
public boolean handleAttribute(java.io.DataInputStream dataIn, java.lang.String name, int length) throws java.io.IOException, ClassFileFormatException
handleAttribute
in interface AttributeHandler
dataIn
- DataInputStream, positioned to attribute's data.name
- Attribute name from constant pool.length
- Length of info[] in bytes.java.io.IOException
- If an I/O error ocurrs.ClassFileFormatException
- If the attribute was processed but
was incorrectly formed.public void write(java.io.DataOutput dout) throws java.io.IOException
CfFieldOrMethod
Subclasses must override this and extend the behavior by writing the attribute table.
write
in class CfFieldOrMethod
java.io.IOException
public void addLocal(LocalVariable local)
local
- The localvariable to append.public void addLine(LineNumber line)
line
- the line number to add.public int getReturnType()
public Attribute getCodeAttributes()
public void setCodeAttributes(Attribute codeAttributes)
public void addHandler(ExceptionHandler h)
public void addHandler(int startPc, int endPc, int handlerPc, CpClass catchType)
public int[] getExceptionCps()
public void setExceptionCps(int[] exceptionCps)
public void setExceptions(java.lang.Class[] exceptions)
public int getMaxStack()
public void setMaxStack(int maxStack)
public int getMaxLocals()
This is actually the NEXT available local index, as the maximum index for a double or long local variable is maxLocals - 2, and for any other local is maxLocals - 1.
public void setMaxLocals(int maxLocals)
public byte[] getCode()
public void setCode(byte[] code)
public int getHandlerCount()
public void setHandlerCount(int handlerCount)
public ExceptionHandler getHandlers()
public void setHandlers(ExceptionHandler handlers)
public ExceptionHandler getLastHandler()
public void setLastHandler(ExceptionHandler lastHandler)
public int getLocalsCount()
public void setLocalsCount(int localsCount)
public LocalVariable getLocals()
public void setLocals(LocalVariable locals)
public void createLocalsFromSignature()
It is an error to invoke this if locals already are defined. This method is only for the case when a new method is generated and the user wants to work with LocalVariable objects for generating code.
public LocalVariable getLocal(int index)
Note that multiple locals can use the same index within different scopes. This method just returns the first one it finds, and not in any particular order. Specifically, it does not guarantee this to be the first declared local of this name.
public LocalVariable getLastLocal()
public void setLastLocal(LocalVariable lastLocal)
public int getLineCount()
public void setLineCount(int lineCount)
public LineNumber getLines()
public void setLines(LineNumber lines)
public LineNumber getLastLine()
public void setLastLine(LineNumber lastLine)
public CpRef getRef()
public CodeBuilder getCodeBuilder()
This is the preferred method, since the ClassFile caches a single CodeBuilder to be re-used.
Copyright ? 2000-2003 Clarity Systems Group, LLC. All Rights Reserved.