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
A
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).-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intThe index of the first local variable, after formal parameters.protected intThe index of the next local variable to be created bynewLocal(org.objectweb.asm.Type).Fields inherited from class org.objectweb.asm.MethodVisitor
api, mv -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLocalVariablesSorter(int api, int access, String descriptor, org.objectweb.asm.MethodVisitor methodVisitor) Constructs a newLocalVariablesSorter.LocalVariablesSorter(int access, String descriptor, org.objectweb.asm.MethodVisitor methodVisitor) Constructs a newLocalVariablesSorter. -
Method Summary
Modifier and TypeMethodDescriptionintnewLocal(org.objectweb.asm.Type type) Constructs a new local variable of the given type.protected intnewLocalMapping(org.objectweb.asm.Type type) protected voidsetLocalType(int local, org.objectweb.asm.Type type) Notifies subclasses that a local variable has been added or remapped.protected voidupdateNewLocals(Object[] newLocals) Notifies subclasses that a new stack map frame is being visited.voidvisitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) voidvisitIincInsn(int varIndex, int increment) voidvisitLocalVariable(String name, String descriptor, String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index) org.objectweb.asm.AnnotationVisitorvisitLocalVariableAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, org.objectweb.asm.Label[] start, org.objectweb.asm.Label[] end, int[] index, String descriptor, boolean visible) voidvisitMaxs(int maxStack, int maxLocals) voidvisitVarInsn(int opcode, int varIndex) Methods inherited from class org.objectweb.asm.MethodVisitor
getDelegate, 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 Details
-
firstLocal
protected final int firstLocalThe index of the first local variable, after formal parameters. -
nextLocal
protected int nextLocalThe index of the next local variable to be created bynewLocal(org.objectweb.asm.Type).
-
-
Constructor Details
-
LocalVariablesSorter
public LocalVariablesSorter(int access, 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:
IllegalStateException- if a subclass calls this constructor.
-
LocalVariablesSorter
protected LocalVariablesSorter(int api, int access, String descriptor, org.objectweb.asm.MethodVisitor methodVisitor) Constructs a newLocalVariablesSorter.- Parameters:
api- the ASM API version implemented by this visitor. Must be one of theASMx 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 Details
-
visitVarInsn
public void visitVarInsn(int opcode, int varIndex) - Overrides:
visitVarInsnin classorg.objectweb.asm.MethodVisitor
-
visitIincInsn
public void visitIincInsn(int varIndex, int increment) - Overrides:
visitIincInsnin classorg.objectweb.asm.MethodVisitor
-
visitMaxs
public void visitMaxs(int maxStack, int maxLocals) - Overrides:
visitMaxsin classorg.objectweb.asm.MethodVisitor
-
visitLocalVariable
public void visitLocalVariable(String name, String descriptor, String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index) - Overrides:
visitLocalVariablein 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, String descriptor, boolean visible) - Overrides:
visitLocalVariableAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitFrame
- Overrides:
visitFramein 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
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)
-