edu.wisc.cs.java
Class MethodInfo

java.lang.Object
  |
  +--edu.wisc.cs.java.Accessible
        |
        +--edu.wisc.cs.java.MethodInfo

public class MethodInfo
extends Accessible

This object maintains a Method_Info table, as specified by the Java Virtual Machine specification for class files.


Field Summary
protected  java.util.Vector attributes
          An array of sttributes for this method.
protected  int code_index
          The index into the attributes array containing the code attribute for this method.
protected  ConstantPool cpool
          The constant pool to which this MethodInfo refers.
protected  int descriptor_index
          The index in the constant pool of the descriptor (type) of this method.
protected  int name_index
          The index in the constant pool of the name of this method.
 
Fields inherited from class edu.wisc.cs.java.Accessible
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, access_flags
 
Constructor Summary
MethodInfo(ClassFile cls, int flags, java.lang.String name, java.lang.String desc)
          Creates a new method for a class class with the specified access flags, name and descriptor.
MethodInfo(java.io.DataInputStream in, ConstantPool cp)
          Constructs a MethodInfo object reading data from the given stream, and and refering to the given constant pool.
 
Method Summary
 CodeAttribute getCode()
          Returns the code attribute for this method.
 java.lang.String getDescriptor()
          Returns a string containing the descriptor of this method.
 int getDescriptorIndex()
          Returns the index of the descriptor of this method in the constant pool.
 java.lang.String getName()
          Returns a string containing the name of this method.
 int getNameIndex()
          Returns the index of the name of this method in the constant pool.
 void printData(java.io.PrintStream out)
          Prints information about this method to the specified stream.
 void writeTo(java.io.DataOutputStream out)
          Writes a method to the specified stream.
 
Methods inherited from class edu.wisc.cs.java.Accessible
getFlag, setFlag, unSetFlag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cpool

protected ConstantPool cpool
The constant pool to which this MethodInfo refers.

name_index

protected int name_index
The index in the constant pool of the name of this method.

descriptor_index

protected int descriptor_index
The index in the constant pool of the descriptor (type) of this method.

attributes

protected java.util.Vector attributes
An array of sttributes for this method.

code_index

protected int code_index
The index into the attributes array containing the code attribute for this method.
Constructor Detail

MethodInfo

public MethodInfo(ClassFile cls,
                  int flags,
                  java.lang.String name,
                  java.lang.String desc)
Creates a new method for a class class with the specified access flags, name and descriptor. This constructor adds the necessary entries to the constant pool and also creates a stub for the method. If the new method is a constructor, code is added to call the super class's default constuctor. If the super class does not have a default constructor, the caller of this method must edit the bytecode afterward.
Parameters:
cls - the class to which the new method will belong.
flags - the access flags for the new method.
name - the name of the new method.
desc - the descriptor of the new method.

MethodInfo

public MethodInfo(java.io.DataInputStream in,
                  ConstantPool cp)
           throws java.io.IOException
Constructs a MethodInfo object reading data from the given stream, and and refering to the given constant pool.
Parameters:
in - a stream from which to read the data for this method.
Throws:
java.io.IOException - if there is a problem reading from the stream.
Method Detail

writeTo

public void writeTo(java.io.DataOutputStream out)
             throws java.io.IOException
Writes a method to the specified stream. The format of the data written is the format required by the Java Virtual Machine specification.
Parameters:
out - the destination stream to write data to.
Throws:
java.io.IOException - if there is a problem writing the method data.

getCode

public CodeAttribute getCode()
Returns the code attribute for this method. If this method is abstract or native, it returns null.
Returns:
the code attribute for this method, null if the method has no code.

getName

public java.lang.String getName()
Returns a string containing the name of this method.
Returns:
a string containing the name of this method.

getDescriptor

public java.lang.String getDescriptor()
Returns a string containing the descriptor of this method.
Returns:
a string containing the descriptor of this method.

getNameIndex

public int getNameIndex()
Returns the index of the name of this method in the constant pool.
Returns:
the index of the name of this method in the constant pool.

getDescriptorIndex

public int getDescriptorIndex()
Returns the index of the descriptor of this method in the constant pool.
Returns:
the index of the descriptor of this method in the constant pool.

printData

public void printData(java.io.PrintStream out)
Prints information about this method to the specified stream. This method is primarily for debugging purposes.
Parameters:
out - the stream to which to print the data.