net.sf.jode.bytecode
Class MethodInfo

java.lang.Object
  extended by net.sf.jode.bytecode.BinaryInfo
      extended by net.sf.jode.bytecode.MethodInfo
All Implemented Interfaces:
Comparable

public final class MethodInfo
extends BinaryInfo
implements Comparable

Represents a java bytecode method. A method consists of the following parts:

name
The method's name
type
The method's type signature in bytecode format.
signature
The method's type signature in bytecode format including template information.
modifiers
The modifiers of the field like private, public etc. These are created by or-ing the constants Modifier.PUBLIC, Modifier.PRIVATE, Modifier.PROTECTED, Modifier.STATIC, Modifier.FINAL, Modifier.SYNCHRONIZED, Modifier.NATIVE, Modifier.ABSTRACT, Modifier.STRICT of class Modifier.
basicblocks
the bytecode of the method in form of basic blocks, null if it is native or abstract.
synthetic
true if this method is synthetic
deprecated
true if this method is deprecated
exceptions
the exceptions that the method declared in its throws clause

Author:
Jochen Hoenicke
See Also:
TypeSignature, BasicBlocks

Field Summary
 
Fields inherited from class net.sf.jode.bytecode.BinaryInfo
ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE
 
Constructor Summary
MethodInfo()
           
MethodInfo(String name, String typeSig, int modifier)
           
 
Method Summary
 int compareTo(Object other)
          Compares two MethodInfo objects for method order.
protected  void drop(int keep)
          Drops information from this info.
protected  int getAttributeCount()
          Returns the number of attributes of this class.
 BasicBlocks getBasicBlocks()
           
 List<InstructionHandle> getBCELInstructions()
           
 String[] getExceptions()
           
 Instruction[] getInstructions()
           
 int getModifiers()
           
 String getName()
           
 String getSignature()
          Gets the type signature including template information of the method.
 String getType()
           
 boolean isConstructor()
           
 boolean isDeprecated()
           
 boolean isStatic()
           
 boolean isSynthetic()
           
protected  void readAttribute(String name, int length, ConstantPool cp, DataInputStream input, int howMuch)
          Reads in an attributes of this class.
 void setBasicBlocks(BasicBlocks newBasicblocks)
           
 void setDeprecated(boolean flag)
           
 void setExceptions(String[] newExceptions)
           
 void setModifiers(int newModifier)
           
 void setName(String newName)
           
 void setSynthetic(boolean flag)
           
 void setType(String newType)
           
 String toString()
          Returns a string representation of this method.
protected  void writeAttributes(GrowableConstantPool gcp, DataOutputStream output)
          Writes the attributes to the output stream.
 
Methods inherited from class net.sf.jode.bytecode.BinaryInfo
addAttribute, findAttribute, getAttributes, getAttributeSize, prepareAttributes, removeAllAttributes, removeAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodInfo

public MethodInfo()

MethodInfo

public MethodInfo(String name,
                  String typeSig,
                  int modifier)
Method Detail

readAttribute

protected void readAttribute(String name,
                             int length,
                             ConstantPool cp,
                             DataInputStream input,
                             int howMuch)
                      throws IOException
Description copied from class: BinaryInfo
Reads in an attributes of this class. Overwrite this method if you want to handle your own attributes. If you don't know how to handle an attribute call this method for the super class.

Overrides:
readAttribute in class BinaryInfo
Parameters:
name - the attribute name.
length - the length of the attribute.
cp - the constant pool of the class.
input - a data input stream where you can read the attribute from. It will protect you to read more over the attribute boundary.
howMuch - the constant that was given to the ClassInfo.load(int) function when loading this class.
Throws:
IOException

getAttributeCount

protected int getAttributeCount()
Description copied from class: BinaryInfo
Returns the number of attributes of this class. Overwrite this method if you want to add your own attributes by providing a writeAttributes method. You should call this method for the super class and add the number of your own attributes to the returned value.

Overrides:
getAttributeCount in class BinaryInfo
Returns:
the number of attributes of this class.

writeAttributes

protected void writeAttributes(GrowableConstantPool gcp,
                               DataOutputStream output)
                        throws IOException
Description copied from class: BinaryInfo

Writes the attributes to the output stream. Overwrite this method if you want to add your own attributes. All constants you need from the growable constant pool must have been previously registered by the BinaryInfo.prepareAttributes(net.sf.jode.bytecode.GrowableConstantPool) method. This method must not add new constants to the pool

First call the method of the super class. Afterwrites write each of your own attributes including the attribute header (name and length entry).

Overrides:
writeAttributes in class BinaryInfo
Parameters:
gcp - The growable constant pool, which is not growable anymore (see above).
output - the data output stream. You must write exactly as many bytes to it as you have told with the BinaryInfo.getAttributeSize() method.
Throws:
IOException

drop

protected void drop(int keep)
Description copied from class: BinaryInfo
Drops information from this info. Override this to drop your own info and don't forget to call the method of the super class.

Overrides:
drop in class BinaryInfo
Parameters:
keep - the constant representing how much information we should keep (see ClassInfo.load(int)).

getName

public String getName()

getType

public String getType()

getSignature

public String getSignature()
Gets the type signature including template information of the method. WARNING: This field may disappear and merged into getType later.

Returns:
the type signature.
See Also:
TypeSignature

getModifiers

public int getModifiers()

isConstructor

public boolean isConstructor()

isStatic

public boolean isStatic()

isSynthetic

public boolean isSynthetic()

isDeprecated

public boolean isDeprecated()

getBasicBlocks

public BasicBlocks getBasicBlocks()

getExceptions

public String[] getExceptions()

setName

public void setName(String newName)

setType

public void setType(String newType)

setModifiers

public void setModifiers(int newModifier)

setSynthetic

public void setSynthetic(boolean flag)

setDeprecated

public void setDeprecated(boolean flag)

setBasicBlocks

public void setBasicBlocks(BasicBlocks newBasicblocks)

setExceptions

public void setExceptions(String[] newExceptions)

compareTo

public int compareTo(Object other)
Compares two MethodInfo objects for method order. The method order is as follows: First the static class intializer followed by constructor with type signature sorted lexicographic. Then all other methods sorted lexicographically by name. If two methods have the same name, they are sorted by type signature.

Specified by:
compareTo in interface Comparable
Returns:
a positive number if this method follows the other in method order, a negative number if it preceeds the other, and 0 if they are equal.
Throws:
ClassCastException - if other is not a ClassInfo.

getInstructions

public Instruction[] getInstructions()

getBCELInstructions

public List<InstructionHandle> getBCELInstructions()

toString

public String toString()
Returns a string representation of this method. It consists of the method's name and type signature.

Overrides:
toString in class Object
Returns:
a string representation of this method.