classUtils.javassist.bytecode
Class MethodInfo

java.lang.Object
  extended by classUtils.javassist.bytecode.MethodInfo

public final class MethodInfo
extends java.lang.Object

method_info structure.

See Also:
CtMethod.getMethodInfo(), CtConstructor.getMethodInfo()

Field Summary
static java.lang.String nameClinit
          The name of class initializer (static initializer): <clinit>.
static java.lang.String nameInit
          The name of constructors: <init>.
 
Constructor Summary
MethodInfo(ConstPool cp, java.lang.String methodname, MethodInfo src, java.util.Map classnameMap)
          Constructs a copy of method_info structure.
MethodInfo(ConstPool cp, java.lang.String methodname, java.lang.String desc)
          Constructs a method_info structure.
 
Method Summary
 void addAttribute(AttributeInfo info)
          Appends an attribute.
 int getAccessFlags()
          Returns access flags.
 AttributeInfo getAttribute(java.lang.String name)
          Returns the attribute with the specified name.
 java.util.List getAttributes()
          Returns all the attributes.
 CodeAttribute getCodeAttribute()
          Returns a Code attribute.
 ConstPool getConstPool()
          Returns a constant pool table used by this method.
 java.lang.String getDescriptor()
          Returns a method descriptor.
 ExceptionsAttribute getExceptionsAttribute()
          Returns an Exceptions attribute.
 int getLineNumber(int pos)
          Returns the line number of the source line corresponding to the specified bytecode contained in this method.
 java.lang.String getName()
          Returns a method name.
 boolean isConstructor()
          Returns true if this is a constructor.
 boolean isMethod()
          Returns true if this is not a constructor or a class initializer (static initializer).
 boolean isStaticInitializer()
          Returns true if this is a class initializer (static initializer).
 void removeCodeAttribute()
          Removes a Code attribute.
 void removeExceptionsAttribute()
          Removes an Exception attribute.
 void setAccessFlags(int acc)
          Sets access flags.
 void setCodeAttribute(CodeAttribute cattr)
          Adds a Code attribute.
 void setDescriptor(java.lang.String desc)
          Sets a method descriptor.
 void setExceptionsAttribute(ExceptionsAttribute cattr)
          Adds an Exception attribute.
 void setName(java.lang.String newName)
          Sets a method name.
 void setSuperclass(java.lang.String superclass)
          Changes a super constructor called by this constructor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameInit

public static final java.lang.String nameInit
The name of constructors: <init>.

See Also:
Constant Field Values

nameClinit

public static final java.lang.String nameClinit
The name of class initializer (static initializer): <clinit>.

See Also:
Constant Field Values
Constructor Detail

MethodInfo

public MethodInfo(ConstPool cp,
                  java.lang.String methodname,
                  java.lang.String desc)
Constructs a method_info structure.

Parameters:
cp - a constant pool table
methodname - method name
desc - method descriptor
See Also:
Descriptor

MethodInfo

public MethodInfo(ConstPool cp,
                  java.lang.String methodname,
                  MethodInfo src,
                  java.util.Map classnameMap)
           throws BadBytecode
Constructs a copy of method_info structure. Class names appearing in the source method_info are renamed according to classnameMap.

Note: only Code and Exceptions attributes are copied from the source. The other attributes are ignored.

Parameters:
cp - a constant pool table
methodname - a method name
src - a source method_info
classnameMap - specifies pairs of replaced and substituted name.
Throws:
BadBytecode
See Also:
Descriptor
Method Detail

getName

public java.lang.String getName()
Returns a method name.


setName

public void setName(java.lang.String newName)
Sets a method name.


isMethod

public boolean isMethod()
Returns true if this is not a constructor or a class initializer (static initializer).


getConstPool

public ConstPool getConstPool()
Returns a constant pool table used by this method.


isConstructor

public boolean isConstructor()
Returns true if this is a constructor.


isStaticInitializer

public boolean isStaticInitializer()
Returns true if this is a class initializer (static initializer).


getAccessFlags

public int getAccessFlags()
Returns access flags.

See Also:
AccessFlag

setAccessFlags

public void setAccessFlags(int acc)
Sets access flags.

See Also:
AccessFlag

getDescriptor

public java.lang.String getDescriptor()
Returns a method descriptor.

See Also:
Descriptor

setDescriptor

public void setDescriptor(java.lang.String desc)
Sets a method descriptor.

See Also:
Descriptor

getAttributes

public java.util.List getAttributes()
Returns all the attributes.

Returns:
a list of AttributeInfo objects.
See Also:
AttributeInfo

getAttribute

public AttributeInfo getAttribute(java.lang.String name)
Returns the attribute with the specified name. If it is not found, this method returns null.

Parameters:
name - attribute name
Returns:
an AttributeInfo object or null.

addAttribute

public void addAttribute(AttributeInfo info)
Appends an attribute. If there is already an attribute with the same name, the new one substitutes for it.


getExceptionsAttribute

public ExceptionsAttribute getExceptionsAttribute()
Returns an Exceptions attribute.

Returns:
an Exceptions attribute or null if it is not specified.

getCodeAttribute

public CodeAttribute getCodeAttribute()
Returns a Code attribute.

Returns:
a Code attribute or null if it is not specified.

removeExceptionsAttribute

public void removeExceptionsAttribute()
Removes an Exception attribute.


setExceptionsAttribute

public void setExceptionsAttribute(ExceptionsAttribute cattr)
Adds an Exception attribute.

The added attribute must share the same constant pool table as this method_info structure.


removeCodeAttribute

public void removeCodeAttribute()
Removes a Code attribute.


setCodeAttribute

public void setCodeAttribute(CodeAttribute cattr)
Adds a Code attribute.

The added attribute must share the same constant pool table as this method_info structure.


getLineNumber

public int getLineNumber(int pos)
Returns the line number of the source line corresponding to the specified bytecode contained in this method.

Parameters:
pos - the position of the bytecode (>= 0). an index into the code array.
Returns:
-1 if this information is not available.

setSuperclass

public void setSuperclass(java.lang.String superclass)
                   throws BadBytecode
Changes a super constructor called by this constructor.

This method modifies a call to super(), which should be affineTransform the head of a constructor body, so that a constructor in a different super class is called. This method does not change actural parameters. Hence the new super class must have a constructor with the same signature as the original one.

This method should be called when the super class of the class declaring this method is changed.

This method does not perform anything unless this MethodInfo represents a constructor.

Parameters:
superclass - the new super class
Throws:
BadBytecode