Class Method
java.lang.Object
EDU.purdue.cs.bloat.file.Method
- All Implemented Interfaces:
MethodInfo
Method represents a method in a Java classfile. A method's name and value
(the types of its parameters and its return type) are modeled as indices into
it class's constant pool. A method has modifiers that determine whether it is
public, private, static, final, etc. Methods have a number of attributes such
as their Code and any Exceptions they may throw.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a clone of this MethodInfo except that its declaring class does not know about it.byte[]code()Get the byte code array of the method.intReturns the length of the Code array.Get the class which declared the method.Catch[]Get the exception handlers in the method.int[]Get the indices into the constant pool of the types of the exceptions thrown by the method.Get the line numbers of the instructions in the method.locals()Get the local variable debug info for the method.intGet the maximum number of locals used in the method.intmaxStack()Get the maximum height of the operand stack.intGet the modifiers of the method.intGet the index into the constant pool of the name of the method.voidsetCode(byte[] bytes) Set the byte code array of the method.voidsetExceptionHandlers(Catch[] handlers) Set the exception handlers in the method.voidsetLineNumbers(LineNumberDebugInfo[] lineNumbers) Set the line numbers of the instructions in the method.voidsetLocals(LocalDebugInfo[] locals) Set the local variable debug info for the method.voidsetMaxLocals(int maxLocals) Set the maximum number of locals used in the method.voidsetMaxStack(int maxStack) Set the maximum height of the operand stack.voidsetModifiers(int modifiers) Set the modifiers of the method.voidsetNameIndex(int name) Set the index into the constant pool of the name of the method.voidsetTypeIndex(int type) Set the index into the constant pool of the type of the method.toString()Returns a string representation of the method.intGet the index into the constant pool of the type of the method.voidwrite(DataOutputStream out) Write the method to a class file.
-
Field Details
-
DEBUG
public static boolean DEBUG
-
-
Constructor Details
-
Method
Constructor. Read a method from a class file.- Parameters:
in- The data stream of the class file.classInfo- The class file containing the method.- Throws:
IOException- If an error occurs while reading.
-
-
Method Details
-
declaringClass
Get the class which declared the method.- Specified by:
declaringClassin interfaceMethodInfo- Returns:
- The ClassInfo of the class which declared the method.
-
setNameIndex
public void setNameIndex(int name) Set the index into the constant pool of the name of the method.- Specified by:
setNameIndexin interfaceMethodInfo- Parameters:
name- The index into the constant pool of the name of the method.
-
setTypeIndex
public void setTypeIndex(int type) Set the index into the constant pool of the type of the method.- Specified by:
setTypeIndexin interfaceMethodInfo- Parameters:
type- The index into the constant pool of the type of the method.
-
nameIndex
public int nameIndex()Get the index into the constant pool of the name of the method.- Specified by:
nameIndexin interfaceMethodInfo- Returns:
- The index into the constant pool of the name of the method.
-
typeIndex
public int typeIndex()Get the index into the constant pool of the type of the method.- Specified by:
typeIndexin interfaceMethodInfo- Returns:
- The index into the constant pool of the type of the method.
-
setModifiers
public void setModifiers(int modifiers) Set the modifiers of the method. The values correspond to the constants in the Modifiers class.- Specified by:
setModifiersin interfaceMethodInfo- Parameters:
modifiers- A bit vector of modifier flags for the method.- See Also:
-
modifiers
public int modifiers()Get the modifiers of the method. The values correspond to the constants in the Modifiers class.- Specified by:
modifiersin interfaceMethodInfo- Returns:
- A bit vector of modifier flags for the method.
- See Also:
-
maxStack
public int maxStack()Get the maximum height of the operand stack.- Specified by:
maxStackin interfaceMethodInfo- Returns:
- The maximum height of the operand stack.
-
setMaxStack
public void setMaxStack(int maxStack) Set the maximum height of the operand stack.- Specified by:
setMaxStackin interfaceMethodInfo- Parameters:
maxStack- The maximum height of the operand stack.
-
maxLocals
public int maxLocals()Get the maximum number of locals used in the method.- Specified by:
maxLocalsin interfaceMethodInfo- Returns:
- The maximum number of locals used in the method.
-
setMaxLocals
public void setMaxLocals(int maxLocals) Set the maximum number of locals used in the method.- Specified by:
setMaxLocalsin interfaceMethodInfo- Parameters:
maxLocals- The maximum number of locals used in the method.
-
code
public byte[] code()Get the byte code array of the method.- Specified by:
codein interfaceMethodInfo- Returns:
- The byte code array of the method.
-
codeLength
public int codeLength()Returns the length of the Code array. -
setCode
public void setCode(byte[] bytes) Set the byte code array of the method.- Specified by:
setCodein interfaceMethodInfo- Parameters:
bytes- The byte code array of the method.
-
exceptionTypes
public int[] exceptionTypes()Get the indices into the constant pool of the types of the exceptions thrown by the method.- Specified by:
exceptionTypesin interfaceMethodInfo- Returns:
- The indices into the constant pool of the types of the exceptions thrown by the method.
-
setLineNumbers
Set the line numbers of the instructions in the method.- Specified by:
setLineNumbersin interfaceMethodInfo- Parameters:
lineNumbers- The line numbers of the instructions in the method.
-
setLocals
Set the local variable debug info for the method.- Specified by:
setLocalsin interfaceMethodInfo- Parameters:
locals- The local variable debug info for the method.
-
lineNumbers
Get the line numbers of the instructions in the method.- Specified by:
lineNumbersin interfaceMethodInfo- Returns:
- The line numbers of the instructions in the method.
-
locals
Get the local variable debug info for the method.- Specified by:
localsin interfaceMethodInfo- Returns:
- The local variable debug info for the method.
-
exceptionHandlers
Get the exception handlers in the method.- Specified by:
exceptionHandlersin interfaceMethodInfo- Returns:
- The exception handlers in the method.
-
setExceptionHandlers
Set the exception handlers in the method.- Specified by:
setExceptionHandlersin interfaceMethodInfo- Parameters:
handlers- The exception handlers in the method.
-
write
Write the method to a class file.- Parameters:
out- The data stream of the class file.- Throws:
IOException- If an error occurs while writing.
-
toString
-
clone
Creates a clone of this MethodInfo except that its declaring class does not know about it.- Specified by:
clonein interfaceMethodInfo- Overrides:
clonein classObject
-