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
The index of the first local variable, after formal parameters.
|
protected int |
nextLocal
The 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 descriptor,
org.objectweb.asm.MethodVisitor methodVisitor)
Constructs a new
LocalVariablesSorter . |
|
LocalVariablesSorter(int access,
java.lang.String descriptor,
org.objectweb.asm.MethodVisitor methodVisitor)
Constructs a new
LocalVariablesSorter . |
Modifier and Type | Method and Description |
---|---|
int |
newLocal(org.objectweb.asm.Type type)
Constructs 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 descriptor,
java.lang.String signature,
org.objectweb.asm.Label start,
org.objectweb.asm.Label end,
int index) |
org.objectweb.asm.AnnotationVisitor |
visitLocalVariableAnnotation(int typeRef,
org.objectweb.asm.TypePath typePath,
org.objectweb.asm.Label[] start,
org.objectweb.asm.Label[] end,
int[] index,
java.lang.String descriptor,
boolean visible) |
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, visitLookupSwitchInsn, visitMethodInsn, visitMethodInsn, visitMultiANewArrayInsn, visitParameter, visitParameterAnnotation, visitTableSwitchInsn, visitTryCatchAnnotation, visitTryCatchBlock, visitTypeAnnotation, visitTypeInsn
protected final int firstLocal
protected int nextLocal
newLocal(org.objectweb.asm.Type)
.public LocalVariablesSorter(int access, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor)
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.descriptor
- the method's descriptor (see Type
).methodVisitor
- the method visitor to which this adapter delegates calls.java.lang.IllegalStateException
- if a subclass calls this constructor.protected LocalVariablesSorter(int api, int access, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor)
LocalVariablesSorter
.api
- the ASM API version implemented by this visitor. Must be one of Opcodes.ASM4
, Opcodes.ASM5
, Opcodes.ASM6
or Opcodes.ASM7_EXPERIMENTAL
.access
- access flags of the adapted method.descriptor
- the method's descriptor (see Type
).methodVisitor
- the method visitor to which this adapter delegates calls.public void visitVarInsn(int opcode, int var)
visitVarInsn
in class org.objectweb.asm.MethodVisitor
public void visitIincInsn(int var, int increment)
visitIincInsn
in class org.objectweb.asm.MethodVisitor
public void visitMaxs(int maxStack, int maxLocals)
visitMaxs
in class org.objectweb.asm.MethodVisitor
public void visitLocalVariable(java.lang.String name, java.lang.String descriptor, java.lang.String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index)
visitLocalVariable
in class org.objectweb.asm.MethodVisitor
public org.objectweb.asm.AnnotationVisitor visitLocalVariableAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, org.objectweb.asm.Label[] start, org.objectweb.asm.Label[] end, int[] index, java.lang.String descriptor, boolean visible)
visitLocalVariableAnnotation
in class org.objectweb.asm.MethodVisitor
public void visitFrame(int type, int nLocal, java.lang.Object[] local, int nStack, java.lang.Object[] stack)
visitFrame
in class org.objectweb.asm.MethodVisitor
public 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(org.objectweb.asm.Type)
.type
- the type of the value being stored in the local variable.protected int newLocalMapping(org.objectweb.asm.Type type)