javassist.bytecode

Class MethodInfo

public final class MethodInfo extends Object

method_info structure.

See Also: CtMethod CtConstructor

Field Summary
static StringnameClinit
The name of class initializer (static initializer): <clinit>.
static StringnameInit
The name of constructors: <init>.
Constructor Summary
MethodInfo(ConstPool cp, String methodname, String desc)
Constructs a method_info structure.
MethodInfo(ConstPool cp, String methodname, MethodInfo src, Map classnameMap)
Constructs a copy of method_info structure.
Method Summary
voidaddAttribute(AttributeInfo info)
Appends an attribute.
intgetAccessFlags()
Returns access flags.
AttributeInfogetAttribute(String name)
Returns the attribute with the specified name.
ListgetAttributes()
Returns all the attributes.
CodeAttributegetCodeAttribute()
Returns a Code attribute.
ConstPoolgetConstPool()
Returns a constant pool table used by this method.
StringgetDescriptor()
Returns a method descriptor.
ExceptionsAttributegetExceptionsAttribute()
Returns an Exceptions attribute.
intgetLineNumber(int pos)
Returns the line number of the source line corresponding to the specified bytecode contained in this method.
StringgetName()
Returns a method name.
booleanisConstructor()
Returns true if this is a constructor.
booleanisMethod()
Returns true if this is not a constructor or a class initializer (static initializer).
booleanisStaticInitializer()
Returns true if this is a class initializer (static initializer).
voidremoveCodeAttribute()
Removes a Code attribute.
voidremoveExceptionsAttribute()
Removes an Exception attribute.
voidsetAccessFlags(int acc)
Sets access flags.
voidsetCodeAttribute(CodeAttribute cattr)
Adds a Code attribute.
voidsetDescriptor(String desc)
Sets a method descriptor.
voidsetExceptionsAttribute(ExceptionsAttribute cattr)
Adds an Exception attribute.
voidsetName(String newName)
Sets a method name.
voidsetSuperclass(String superclass)
Changes a super constructor called by this constructor.
StringtoString()
Returns a string representation of the object.

Field Detail

nameClinit

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

nameInit

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

Constructor Detail

MethodInfo

public MethodInfo(ConstPool cp, String methodname, String desc)
Constructs a method_info structure. The initial value of access_flags is zero.

Parameters: cp a constant pool table methodname method name desc method descriptor

See Also: Descriptor

MethodInfo

public MethodInfo(ConstPool cp, String methodname, MethodInfo src, Map classnameMap)
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.

See Also: Descriptor

Method Detail

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.

See Also: getAttributes

getAccessFlags

public int getAccessFlags()
Returns access flags.

See Also: AccessFlag

getAttribute

public AttributeInfo getAttribute(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.

See Also: getAttributes

getAttributes

public List getAttributes()
Returns all the attributes. The returned List object is shared with this object. If you add a new attribute to the list, the attribute is also added to the method represented by this object. If you remove an attribute from the list, it is also removed from the method.

Returns: a list of AttributeInfo objects.

See Also: AttributeInfo

getCodeAttribute

public CodeAttribute getCodeAttribute()
Returns a Code attribute.

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

getConstPool

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

getDescriptor

public String getDescriptor()
Returns a method descriptor.

See Also: Descriptor

getExceptionsAttribute

public ExceptionsAttribute getExceptionsAttribute()
Returns an Exceptions attribute.

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

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.

getName

public String getName()
Returns a method name.

isConstructor

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

isMethod

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

isStaticInitializer

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

removeCodeAttribute

public void removeCodeAttribute()
Removes a Code attribute.

removeExceptionsAttribute

public void removeExceptionsAttribute()
Removes an Exception attribute.

setAccessFlags

public void setAccessFlags(int acc)
Sets access flags.

See Also: AccessFlag

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.

setDescriptor

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

See Also: Descriptor

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.

setName

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

setSuperclass

public void setSuperclass(String superclass)
Changes a super constructor called by this constructor.

This method modifies a call to super(), which should be at 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

toString

public String toString()
Returns a string representation of the object.
Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.