public class LocalVariablesSorter
extends org.objectweb.asm.MethodVisitor
MethodVisitor 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 newLocal(org.objectweb.asm.Type) on this adapter (this
requires a reference back to this LocalVariablesSorter).| Modifier and Type | Field and Description |
|---|---|
protected int |
firstLocal
Index of the first local variable, after formal parameters.
|
protected int |
nextLocal
Index of the next local variable to be created by
newLocal(org.objectweb.asm.Type). |
| Modifier | Constructor and Description |
|---|---|
protected |
LocalVariablesSorter(int api,
int access,
java.lang.String desc,
org.objectweb.asm.MethodVisitor mv)
Creates a new
LocalVariablesSorter. |
|
LocalVariablesSorter(int access,
java.lang.String desc,
org.objectweb.asm.MethodVisitor mv)
Creates a new
LocalVariablesSorter. |
| Modifier and Type | Method and Description |
|---|---|
int |
newLocal(org.objectweb.asm.Type type)
Creates a new local variable of the given type.
|
protected int |
newLocalMapping(org.objectweb.asm.Type type) |
protected void |
setLocalType(int local,
org.objectweb.asm.Type type)
Notifies subclasses that a local variable has been added or remapped.
|
protected void |
updateNewLocals(java.lang.Object[] newLocals)
Notifies subclasses that a new stack map frame is being visited.
|
void |
visitFrame(int type,
int nLocal,
java.lang.Object[] local,
int nStack,
java.lang.Object[] stack) |
void |
visitIincInsn(int var,
int increment) |
void |
visitLocalVariable(java.lang.String name,
java.lang.String desc,
java.lang.String signature,
org.objectweb.asm.Label start,
org.objectweb.asm.Label end,
int index) |
void |
visitMaxs(int maxStack,
int maxLocals) |
void |
visitVarInsn(int opcode,
int var) |
visitAnnotableParameterCount, visitAnnotation, visitAnnotationDefault, visitAttribute, visitCode, visitEnd, visitFieldInsn, visitInsn, visitInsnAnnotation, visitIntInsn, visitInvokeDynamicInsn, visitJumpInsn, visitLabel, visitLdcInsn, visitLineNumber, visitLocalVariableAnnotation, visitLookupSwitchInsn, visitMethodInsn, visitMethodInsn, visitMultiANewArrayInsn, visitParameter, visitParameterAnnotation, visitTableSwitchInsn, visitTryCatchAnnotation, visitTryCatchBlock, visitTypeAnnotation, visitTypeInsnprotected final int firstLocal
protected int nextLocal
newLocal(org.objectweb.asm.Type).public LocalVariablesSorter(int access,
java.lang.String desc,
org.objectweb.asm.MethodVisitor mv)
LocalVariablesSorter. Subclasses must not use
this constructor. Instead, they must use the
LocalVariablesSorter(int, int, String, MethodVisitor) version.access - access flags of the adapted method.desc - the method's descriptor (see Type).mv - the method visitor to which this adapter delegates calls.protected LocalVariablesSorter(int api,
int access,
java.lang.String desc,
org.objectweb.asm.MethodVisitor mv)
LocalVariablesSorter.api - the ASM API version implemented by this visitor. Must be one
of Opcodes.ASM4.access - access flags of the adapted method.desc - the method's descriptor (see Type).mv - the method visitor to which this adapter delegates calls.public void visitVarInsn(int opcode,
int var)
visitVarInsn in class org.objectweb.asm.MethodVisitorpublic void visitIincInsn(int var,
int increment)
visitIincInsn in class org.objectweb.asm.MethodVisitorpublic void visitMaxs(int maxStack,
int maxLocals)
visitMaxs in class org.objectweb.asm.MethodVisitorpublic void visitLocalVariable(java.lang.String name,
java.lang.String desc,
java.lang.String signature,
org.objectweb.asm.Label start,
org.objectweb.asm.Label end,
int index)
visitLocalVariable in class org.objectweb.asm.MethodVisitorpublic void visitFrame(int type,
int nLocal,
java.lang.Object[] local,
int nStack,
java.lang.Object[] stack)
visitFrame in class org.objectweb.asm.MethodVisitorpublic int newLocal(org.objectweb.asm.Type type)
type - the type of the local variable to be created.protected void updateNewLocals(java.lang.Object[] newLocals)
newLocal(org.objectweb.asm.Type). This method can update
these types in place for the stack map frame being visited. The default
implementation of this method does nothing, i.e. a local variable added
with newLocal(org.objectweb.asm.Type) will have the same type in all stack map frames.
But this behavior is not always the desired one, for instance if a local
variable is added in the middle of a try/catch block: the frame for the
exception handler should have a TOP type for this new local.newLocals - the stack map frame types corresponding to the local variables
added with newLocal(org.objectweb.asm.Type) (and null for the others). The
format of this array is the same as in
MethodVisitor.visitFrame(int, int, java.lang.Object[], int, java.lang.Object[]), except that long and double
types use two slots. The types for the current stack map frame
must be updated in place in this array.protected void setLocalType(int local,
org.objectweb.asm.Type type)
local - a local variable identifier, as returned by newLocal().type - the type of the value being stored in the local variable.protected int newLocalMapping(org.objectweb.asm.Type type)