Package org.objectweb.asm.commons
Class LocalVariablesSorter
- java.lang.Object
-
- org.objectweb.asm.MethodVisitor
-
- org.objectweb.asm.commons.LocalVariablesSorter
-
- Direct Known Subclasses:
GeneratorAdapter
public class LocalVariablesSorter extends org.objectweb.asm.MethodVisitor
AMethodVisitor
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 callingnewLocal(org.objectweb.asm.Type)
on this adapter (this requires a reference back to thisLocalVariablesSorter
).
-
-
Field Summary
Fields Modifier and Type Field 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 bynewLocal(org.objectweb.asm.Type)
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
LocalVariablesSorter(int api, int access, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor)
Constructs a newLocalVariablesSorter
.LocalVariablesSorter(int access, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor)
Constructs a newLocalVariablesSorter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 numLocal, java.lang.Object[] local, int numStack, java.lang.Object[] stack)
void
visitIincInsn(int varIndex, 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 varIndex)
-
Methods inherited from class org.objectweb.asm.MethodVisitor
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
-
-
-
-
Field Detail
-
firstLocal
protected final int firstLocal
The index of the first local variable, after formal parameters.
-
nextLocal
protected int nextLocal
The index of the next local variable to be created bynewLocal(org.objectweb.asm.Type)
.
-
-
Constructor Detail
-
LocalVariablesSorter
public LocalVariablesSorter(int access, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor)
Constructs a newLocalVariablesSorter
. Subclasses must not use this constructor. Instead, they must use theLocalVariablesSorter(int, int, String, MethodVisitor)
version.- Parameters:
access
- access flags of the adapted method.descriptor
- the method's descriptor (seeType
).methodVisitor
- the method visitor to which this adapter delegates calls.- Throws:
java.lang.IllegalStateException
- if a subclass calls this constructor.
-
LocalVariablesSorter
protected LocalVariablesSorter(int api, int access, java.lang.String descriptor, org.objectweb.asm.MethodVisitor methodVisitor)
Constructs a newLocalVariablesSorter
.- Parameters:
api
- the ASM API version implemented by this visitor. Must be one of theASM
x values inOpcodes
.access
- access flags of the adapted method.descriptor
- the method's descriptor (seeType
).methodVisitor
- the method visitor to which this adapter delegates calls.
-
-
Method Detail
-
visitVarInsn
public void visitVarInsn(int opcode, int varIndex)
- Overrides:
visitVarInsn
in classorg.objectweb.asm.MethodVisitor
-
visitIincInsn
public void visitIincInsn(int varIndex, int increment)
- Overrides:
visitIincInsn
in classorg.objectweb.asm.MethodVisitor
-
visitMaxs
public void visitMaxs(int maxStack, int maxLocals)
- Overrides:
visitMaxs
in classorg.objectweb.asm.MethodVisitor
-
visitLocalVariable
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)
- Overrides:
visitLocalVariable
in classorg.objectweb.asm.MethodVisitor
-
visitLocalVariableAnnotation
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)
- Overrides:
visitLocalVariableAnnotation
in classorg.objectweb.asm.MethodVisitor
-
visitFrame
public void visitFrame(int type, int numLocal, java.lang.Object[] local, int numStack, java.lang.Object[] stack)
- Overrides:
visitFrame
in classorg.objectweb.asm.MethodVisitor
-
newLocal
public int newLocal(org.objectweb.asm.Type type)
Constructs 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.
-
updateNewLocals
protected void updateNewLocals(java.lang.Object[] newLocals)
Notifies subclasses that a new stack map frame is being visited. The array argument contains the stack map frame types corresponding to the local variables added withnewLocal(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 withnewLocal(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.- Parameters:
newLocals
- the stack map frame types corresponding to the local variables added withnewLocal(org.objectweb.asm.Type)
(and null for the others). The format of this array is the same as inMethodVisitor.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.
-
setLocalType
protected void setLocalType(int local, org.objectweb.asm.Type type)
Notifies subclasses that a local variable has been added or remapped. The default implementation of this method does nothing.- Parameters:
local
- a local variable identifier, as returned bynewLocal(org.objectweb.asm.Type)
.type
- the type of the value being stored in the local variable.
-
newLocalMapping
protected int newLocalMapping(org.objectweb.asm.Type type)
-
-