method_info structure.
The bytecode sequence of the method is represented
by a CodeAttribute object.
The following code adds the default constructor to a class:
of int type:
ClassFile cf = ...
Bytecode code = new Bytecode(cf.getConstPool());
code.addAload(0);
code.addInvokespecial("java/lang/Object", MethodInfo.nameInit, "()V");
code.addReturn(null);
code.setMaxLocals(1);
MethodInfo minfo = new MethodInfo(cf.getConstPool(), MethodInfo.nameInit, "()V");
minfo.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(minfo);
getCodeAttribute(), CodeAttribute, Bytecode, javassist.CtMethod#getMethodInfo() , javassist.CtConstructor#getMethodInfo()
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| pack-priv List | |
| pack-priv String | |
| pack-priv ConstPool | |
| pack-priv int | |
| public static boolean | doPreverify
If this value is true, Javassist maintains a |
| pack-priv int | |
| public static final String | nameClinit
The name of class initializer (static initializer):
|
| public static final String | nameInit
The name of constructors: |
| Access | Constructor and Description |
|---|---|
| private | |
| public | MethodInfo(ConstPool
a constant pool table cp, String method name methodname, String method descriptor desc)Constructs a |
| pack-priv | |
| public | MethodInfo(ConstPool
a constant pool table cp, String a method name methodname, MethodInfo a source src, Map<String, String> method_infospecifies pairs of replaced and substituted name. classnameMap)Constructs a copy of |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| pack-priv void | |
| public int | |
| public AttributeInfo | Returns: anAttributeInfo object or null.attribute name name)Returns the attribute with the specified name. |
| public List | |
| public CodeAttribute | Returns: a Code attribute or null if it is not specified.Returns a Code attribute. |
| public ConstPool | |
| public String | |
| public ExceptionsAttribute | Returns: an Exceptions attribute or null if it is not specified.Returns an Exceptions attribute. |
| public int | Returns: -1 if this information is not available.the position of the bytecode (>= 0). an index into the code
array. pos)Returns the line number of the source line corresponding to the specified bytecode contained in this method. |
| public String | |
| public boolean | |
| public boolean | |
| public boolean | |
| pack-priv void | |
| private void | |
| private void | |
| public void | |
| public void | rebuildStackMapForME(ClassPool
used for making type hierarchy. pool)Rebuilds a stack map table for J2ME (CLDC). |
| public void | rebuildStackMapIf6(ClassPool
used for making type hierarchy. pool, ClassFile rebuild if this class file is for Java 6 or later. cf)Rebuilds a stack map table if the class file is for Java 6 or later. |
| public AttributeInfo | Returns: the removed attribute or null.attribute name. name)Removes an attribute with the specified name. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setSuperclass(String
the new super class superclass)Changes a super constructor called by this constructor. |
| public String | |
| pack-priv void |
| accessFlags | back to summary |
|---|---|
| pack-priv int accessFlags | |
| attribute | back to summary |
|---|---|
| pack-priv List<AttributeInfo> attribute | |
| cachedName | back to summary |
|---|---|
| pack-priv String cachedName | |
| constPool | back to summary |
|---|---|
| pack-priv ConstPool constPool | |
| descriptor | back to summary |
|---|---|
| pack-priv int descriptor | |
| doPreverify | back to summary |
|---|---|
| public static boolean doPreverify If this value is true, Javassist maintains a | |
| name | back to summary |
|---|---|
| pack-priv int name | |
| nameClinit | back to summary |
|---|---|
| public static final String nameClinit The name of class initializer (static initializer):
| |
| nameInit | back to summary |
|---|---|
| public static final String nameInit The name of constructors: | |
| MethodInfo | back to summary |
|---|---|
| private MethodInfo(ConstPool cp) | |
| MethodInfo | back to summary |
|---|---|
| public MethodInfo(ConstPool cp, String methodname, String desc) Constructs a
| |
| MethodInfo | back to summary |
|---|---|
| pack-priv MethodInfo(ConstPool cp, DataInputStream in) throws IOException | |
| MethodInfo | back to summary |
|---|---|
| public MethodInfo(ConstPool cp, String methodname, MethodInfo src, Map<String, String> classnameMap) throws BadBytecode Constructs a copy of Note only
| |
| addAttribute | back to summary |
|---|---|
| public void addAttribute(AttributeInfo info) Appends an attribute. If there is already an attribute with the same name, the new one substitutes for it.
| |
| compact | back to summary |
|---|---|
| pack-priv void compact(ConstPool cp) Copies all constant pool items to a given new constant pool and replaces the original items with the new ones. This is used for garbage collecting the items of removed fields and methods.
| |
| getAccessFlags | back to summary |
|---|---|
| public int getAccessFlags() Returns access flags.
| |
| getAttribute | back to summary |
|---|---|
| public AttributeInfo getAttribute(String name) Returns the attribute with the specified name. If it is not found, this method returns null. An attribute name can be obtained by, for example,
| |
| getAttributes | back to summary |
|---|---|
| public List Returns all the attributes. The returned
| |
| getCodeAttribute | back to summary |
|---|---|
| public CodeAttribute getCodeAttribute() Returns a Code attribute.
| |
| getConstPool | back to summary |
|---|---|
| public ConstPool getConstPool() Returns a constant pool table used by this method. | |
| getDescriptor | back to summary |
|---|---|
| public String getDescriptor() Returns a method descriptor.
| |
| getExceptionsAttribute | back to summary |
|---|---|
| public ExceptionsAttribute getExceptionsAttribute() Returns an Exceptions attribute.
| |
| getLineNumber | back to summary |
|---|---|
| public int getLineNumber(int pos) Returns the line number of the source line corresponding to the specified bytecode contained in this method.
| |
| getName | back to summary |
|---|---|
| public String getName() Returns a method name. | |
| isConstructor | back to summary |
|---|---|
| public boolean isConstructor() Returns true if this is a constructor. | |
| isMethod | back to summary |
|---|---|
| public boolean isMethod() Returns true if this is not a constructor or a class initializer (static initializer). | |
| isStaticInitializer | back to summary |
|---|---|
| public boolean isStaticInitializer() Returns true if this is a class initializer (static initializer). | |
| prune | back to summary |
|---|---|
| pack-priv void prune(ConstPool cp) | |
| read | back to summary |
|---|---|
| private void read(MethodInfo src, String methodname, Map<String, String> classnames) | |
| read | back to summary |
|---|---|
| private void read(DataInputStream in) throws IOException | |
| rebuildStackMap | back to summary |
|---|---|
| public void rebuildStackMap(ClassPool pool) throws BadBytecode Rebuilds a stack map table. If no stack map table is included,
a new one is created. If this
| |
| rebuildStackMapForME | back to summary |
|---|---|
| public void rebuildStackMapForME(ClassPool pool) throws BadBytecode Rebuilds a stack map table for J2ME (CLDC). If no stack map table is included,
a new one is created. If this | |
| rebuildStackMapIf6 | back to summary |
|---|---|
| public void rebuildStackMapIf6(ClassPool pool, ClassFile cf) throws BadBytecode Rebuilds a stack map table if the class file is for Java 6
or later. Java 5 or older Java VMs do not recognize a stack
map table. If
| |
| removeAttribute | back to summary |
|---|---|
| public AttributeInfo removeAttribute(String name) Removes an attribute with the specified name.
| |
| removeCodeAttribute | back to summary |
|---|---|
| public void removeCodeAttribute() Removes a Code attribute. | |
| removeExceptionsAttribute | back to summary |
|---|---|
| public void removeExceptionsAttribute() Removes an Exception attribute. | |
| setAccessFlags | back to summary |
|---|---|
| public void setAccessFlags(int acc) Sets access flags.
| |
| setCodeAttribute | back to summary |
|---|---|
| public void setCodeAttribute(CodeAttribute cattr) Adds a Code attribute.
The added attribute must share the same constant pool table as this
| |
| setDescriptor | back to summary |
|---|---|
| public void setDescriptor(String desc) Sets a method descriptor.
| |
| setExceptionsAttribute | back to summary |
|---|---|
| public void setExceptionsAttribute(ExceptionsAttribute cattr) Adds an Exception attribute.
The added attribute must share the same constant pool table as this
| |
| setName | back to summary |
|---|---|
| public void setName(String newName) Sets a method name. | |
| setSuperclass | back to summary |
|---|---|
| public void setSuperclass(String superclass) throws BadBytecode Changes a super constructor called by this constructor.
This method modifies a call to 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
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of the object.
| |
| write | back to summary |
|---|---|
| pack-priv void write(DataOutputStream out) throws IOException | |