Class LocalVariablesSorter

  • Direct Known Subclasses:
    GeneratorAdapter

    public class LocalVariablesSorter
    extends 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).
    Author:
    Chris Nokleberg, Eugene Kuleshov, Eric Bruneton
    • Field Detail

      • firstLocal

        protected final int firstLocal
        The index of the first local variable, after formal parameters.
    • Constructor Detail

      • LocalVariablesSorter

        protected LocalVariablesSorter​(int api,
                                       int access,
                                       String descriptor,
                                       MethodVisitor methodVisitor)
        Constructs a new LocalVariablesSorter.
        Parameters:
        api - the ASM API version implemented by this visitor. Must be one of the ASMx values in Opcodes.
        access - access flags of the adapted method.
        descriptor - the method's descriptor (see Type).
        methodVisitor - the method visitor to which this adapter delegates calls.
    • Method Detail

      • visitMaxs

        public void visitMaxs​(int maxStack,
                              int maxLocals)
        Overrides:
        visitMaxs in class MethodVisitor
      • 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 with 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.
        Parameters:
        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.
      • 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 by newLocal(org.objectweb.asm.Type).
        type - the type of the value being stored in the local variable.
      • newLocalMapping

        protected int newLocalMapping​(Type type)