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 MethodVisitor
AMethodVisitorthat 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).- Author:
- Chris Nokleberg, Eugene Kuleshov, Eric Bruneton
-
-
Field Summary
Fields Modifier and Type Field Description protected intfirstLocalThe index of the first local variable, after formal parameters.protected intnextLocalThe 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
Constructors Modifier Constructor Description protectedLocalVariablesSorter(int api, int access, String descriptor, MethodVisitor methodVisitor)Constructs a newLocalVariablesSorter.LocalVariablesSorter(int access, String descriptor, MethodVisitor methodVisitor)Constructs a newLocalVariablesSorter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intnewLocal(Type type)Constructs a new local variable of the given type.protected intnewLocalMapping(Type type)protected voidsetLocalType(int local, 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, Label start, Label end, int index)AnnotationVisitorvisitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, 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
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, String descriptor, 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, MethodVisitor methodVisitor)Constructs a newLocalVariablesSorter.
-
-
Method Detail
-
visitVarInsn
public void visitVarInsn(int opcode, int varIndex)- Overrides:
visitVarInsnin classMethodVisitor
-
visitIincInsn
public void visitIincInsn(int varIndex, int increment)- Overrides:
visitIincInsnin classMethodVisitor
-
visitMaxs
public void visitMaxs(int maxStack, int maxLocals)- Overrides:
visitMaxsin classMethodVisitor
-
visitLocalVariable
public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index)
- Overrides:
visitLocalVariablein classMethodVisitor
-
visitLocalVariableAnnotation
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String descriptor, boolean visible)
- Overrides:
visitLocalVariableAnnotationin classMethodVisitor
-
visitFrame
public void visitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack)- Overrides:
visitFramein classMethodVisitor
-
newLocal
public int newLocal(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(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, 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(Type type)
-
-