org.cojen.classfile
Class MethodInfo

java.lang.Object
  extended by org.cojen.classfile.MethodInfo

public class MethodInfo
extends Object

This class corresponds to the method_info data structure as defined in section 4.6 of The Java Virtual Machine Specification. To make it easier to create bytecode for a method's CodeAttr, the CodeBuilder class is provided.

Author:
Brian S O'Neill
See Also:
ClassFile, CodeBuilder

Method Summary
 void addAttribute(Attribute attr)
           
 void addException(TypeDesc type)
          Add a declared exception that this method may throw.
 ClassFile addInnerClass(String innerClassName)
          Add an inner class to this method.
 ClassFile addInnerClass(String innerClassName, Class superClass)
          Add an inner class to this method.
 ClassFile addInnerClass(String innerClassName, String superClassName)
          Add an inner class to this method.
 Annotation addRuntimeInvisibleAnnotation(TypeDesc type)
          Add a runtime invisible annotation.
 Annotation addRuntimeVisibleAnnotation(TypeDesc type)
          Add a runtime visible annotation.
 Attribute[] getAttributes()
           
 ClassFile getClassFile()
          Returns the parent ClassFile for this MethodInfo.
 CodeAttr getCodeAttr()
          Returns a CodeAttr object used to manipulate the method code body, or null if this method is abstract or native.
 ConstantUTFInfo getDescriptorConstant()
          Returns a constant from the constant pool with this method's type descriptor string.
 TypeDesc[] getExceptions()
          Returns the exceptions that this method is declared to throw.
 int getLength()
          Returns the length (in bytes) of this object in the class file.
 MethodDesc getMethodDescriptor()
          Returns a MethodDesc which describes return and parameter types of this method.
 Modifiers getModifiers()
          Returns this method's modifiers.
 String getName()
          Returns the name of this method.
 ConstantUTFInfo getNameConstant()
          Returns a constant from the constant pool with this method's name.
 Annotation[] getRuntimeInvisibleAnnotations()
          Returns all the runtime invisible annotations defined for this class file, or an empty array if none.
 Annotation[] getRuntimeVisibleAnnotations()
          Returns all the runtime visible annotations defined for this class file, or an empty array if none.
 SignatureAttr getSignatureAttr()
          Returns the signature attribute of this method, or null if none is defined.
 boolean isDeprecated()
           
 boolean isSynthetic()
           
 void markDeprecated()
          Mark this method as being deprecated by adding a special attribute.
 void markSynthetic()
          Mark this method as being synthetic by adding a special attribute.
 void setModifiers(Modifiers modifiers)
           
 String toString()
           
 void writeTo(DataOutput dout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getClassFile

public ClassFile getClassFile()
Returns the parent ClassFile for this MethodInfo.


getName

public String getName()
Returns the name of this method.


getMethodDescriptor

public MethodDesc getMethodDescriptor()
Returns a MethodDesc which describes return and parameter types of this method.


getModifiers

public Modifiers getModifiers()
Returns this method's modifiers.


setModifiers

public void setModifiers(Modifiers modifiers)

getNameConstant

public ConstantUTFInfo getNameConstant()
Returns a constant from the constant pool with this method's name.


getDescriptorConstant

public ConstantUTFInfo getDescriptorConstant()
Returns a constant from the constant pool with this method's type descriptor string.

See Also:
MethodDesc

getExceptions

public TypeDesc[] getExceptions()
Returns the exceptions that this method is declared to throw.


getCodeAttr

public CodeAttr getCodeAttr()
Returns a CodeAttr object used to manipulate the method code body, or null if this method is abstract or native.


isSynthetic

public boolean isSynthetic()

isDeprecated

public boolean isDeprecated()

getRuntimeInvisibleAnnotations

public Annotation[] getRuntimeInvisibleAnnotations()
Returns all the runtime invisible annotations defined for this class file, or an empty array if none.


getRuntimeVisibleAnnotations

public Annotation[] getRuntimeVisibleAnnotations()
Returns all the runtime visible annotations defined for this class file, or an empty array if none.


addRuntimeInvisibleAnnotation

public Annotation addRuntimeInvisibleAnnotation(TypeDesc type)
Add a runtime invisible annotation.


addRuntimeVisibleAnnotation

public Annotation addRuntimeVisibleAnnotation(TypeDesc type)
Add a runtime visible annotation.


getSignatureAttr

public SignatureAttr getSignatureAttr()
Returns the signature attribute of this method, or null if none is defined.


addException

public void addException(TypeDesc type)
Add a declared exception that this method may throw.


addInnerClass

public ClassFile addInnerClass(String innerClassName)
Add an inner class to this method.

Parameters:
innerClassName - Optional short inner class name.

addInnerClass

public ClassFile addInnerClass(String innerClassName,
                               Class superClass)
Add an inner class to this method.

Parameters:
innerClassName - Optional short inner class name.
superClass - Super class.

addInnerClass

public ClassFile addInnerClass(String innerClassName,
                               String superClassName)
Add an inner class to this method.

Parameters:
innerClassName - Optional short inner class name.
superClassName - Full super class name.

markSynthetic

public void markSynthetic()
Mark this method as being synthetic by adding a special attribute.


markDeprecated

public void markDeprecated()
Mark this method as being deprecated by adding a special attribute.


addAttribute

public void addAttribute(Attribute attr)

getAttributes

public Attribute[] getAttributes()

getLength

public int getLength()
Returns the length (in bytes) of this object in the class file.


writeTo

public void writeTo(DataOutput dout)
             throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2011 Brian S O'Neill. All Rights Reserved.