org.objectweb.asm.commons

Class LocalVariablesSorter

public class LocalVariablesSorter extends MethodAdapter

A MethodAdapter that renumbers local variables in their order of appearance. This adapter allows one to easily add new local variables to a method. It may be used by inheriting from this class, but the preferred way of using it is via delegation: the next visitor in the chain can indeed add new locals when needed by calling LocalVariablesSorter on this adapter (this requires a reference back to this LocalVariablesSorter).

Author: Chris Nokleberg Eugene Kuleshov Eric Bruneton

Field Summary
protected intfirstLocal
Index of the first local variable, after formal parameters.
protected intnextLocal
Index of the next local variable to be created by LocalVariablesSorter.
Constructor Summary
LocalVariablesSorter(int access, String desc, MethodVisitor mv)
Creates a new LocalVariablesSorter.
Method Summary
intnewLocal(Type type)
Creates a new local variable of the given type.
protected intnewLocalMapping(Type type)
protected voidsetLocalType(int local, Type type)
Sets the current type of the given local variable.
voidvisitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack)
voidvisitIincInsn(int var, int increment)
voidvisitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
voidvisitMaxs(int maxStack, int maxLocals)
voidvisitVarInsn(int opcode, int var)

Field Detail

firstLocal

protected final int firstLocal
Index of the first local variable, after formal parameters.

nextLocal

protected int nextLocal
Index of the next local variable to be created by LocalVariablesSorter.

Constructor Detail

LocalVariablesSorter

public LocalVariablesSorter(int access, String desc, MethodVisitor mv)
Creates a new LocalVariablesSorter.

Parameters: access access flags of the adapted method. desc the method's descriptor (see Type). mv the method visitor to which this adapter delegates calls.

Method Detail

newLocal

public int newLocal(Type type)
Creates a new local variable of the given type.

Parameters: type the type of the local variable to be created.

Returns: the identifier of the newly created local variable.

newLocalMapping

protected int newLocalMapping(Type type)

setLocalType

protected void setLocalType(int local, Type type)
Sets the current type of the given local variable. The default implementation of this method does nothing.

Parameters: local a local variable identifier, as returned by newLocal(). type the type of the value being stored in the local variable

visitFrame

public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack)

visitIincInsn

public void visitIincInsn(int var, int increment)

visitLocalVariable

public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)

visitMaxs

public void visitMaxs(int maxStack, int maxLocals)

visitVarInsn

public void visitVarInsn(int opcode, int var)