Package EDU.purdue.cs.bloat.file
Class Method
- java.lang.Object
-
- EDU.purdue.cs.bloat.file.Method
-
- All Implemented Interfaces:
MethodInfo
public class Method extends java.lang.Object implements 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:
Code,Exceptions
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUG
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()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.intcodeLength()Returns the length of the Code array.ClassInfodeclaringClass()Get the class which declared the method.Catch[]exceptionHandlers()Get the exception handlers in the method.int[]exceptionTypes()Get the indices into the constant pool of the types of the exceptions thrown by the method.LineNumberDebugInfo[]lineNumbers()Get the line numbers of the instructions in the method.LocalDebugInfo[]locals()Get the local variable debug info for the method.intmaxLocals()Get the maximum number of locals used in the method.intmaxStack()Get the maximum height of the operand stack.intmodifiers()Get the modifiers of the method.intnameIndex()Get 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.java.lang.StringtoString()Returns a string representation of the method.inttypeIndex()Get the index into the constant pool of the type of the method.voidwrite(java.io.DataOutputStream out)Write the method to a class file.
-
-
-
Constructor Detail
-
Method
public Method(java.io.DataInputStream in, ClassInfo classInfo) throws java.io.IOExceptionConstructor. Read a method from a class file.- Parameters:
in- The data stream of the class file.classInfo- The class file containing the method.- Throws:
java.io.IOException- If an error occurs while reading.
-
-
Method Detail
-
declaringClass
public ClassInfo 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
-
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:
Modifiers
-
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
public void setLineNumbers(LineNumberDebugInfo[] lineNumbers)
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
public void setLocals(LocalDebugInfo[] locals)
Set the local variable debug info for the method.- Specified by:
setLocalsin interfaceMethodInfo- Parameters:
locals- The local variable debug info for the method.
-
lineNumbers
public LineNumberDebugInfo[] 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
public LocalDebugInfo[] locals()
Get the local variable debug info for the method.- Specified by:
localsin interfaceMethodInfo- Returns:
- The local variable debug info for the method.
-
exceptionHandlers
public Catch[] exceptionHandlers()
Get the exception handlers in the method.- Specified by:
exceptionHandlersin interfaceMethodInfo- Returns:
- The exception handlers in the method.
-
setExceptionHandlers
public void setExceptionHandlers(Catch[] handlers)
Set the exception handlers in the method.- Specified by:
setExceptionHandlersin interfaceMethodInfo- Parameters:
handlers- The exception handlers in the method.
-
write
public void write(java.io.DataOutputStream out) throws java.io.IOExceptionWrite the method to a class file.- Parameters:
out- The data stream of the class file.- Throws:
java.io.IOException- If an error occurs while writing.
-
toString
public java.lang.String toString()
Returns a string representation of the method.- Overrides:
toStringin classjava.lang.Object
-
clone
public java.lang.Object clone()
Creates a clone of this MethodInfo except that its declaring class does not know about it.- Specified by:
clonein interfaceMethodInfo- Overrides:
clonein classjava.lang.Object
-
-