Class 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

      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 by newLocal(org.objectweb.asm.Type).
      • Fields inherited from class org.objectweb.asm.MethodVisitor

        api, mv
    • 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • firstLocal

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

      • LocalVariablesSorter

        public LocalVariablesSorter​(int access,
                                    java.lang.String descriptor,
                                    org.objectweb.asm.MethodVisitor methodVisitor)
        Constructs a new LocalVariablesSorter. Subclasses must not use this constructor. Instead, they must use the LocalVariablesSorter(int, int, String, MethodVisitor) version.
        Parameters:
        access - access flags of the adapted method.
        descriptor - the method's descriptor (see Type).
        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 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

      • visitVarInsn

        public void visitVarInsn​(int opcode,
                                 int varIndex)
        Overrides:
        visitVarInsn in class org.objectweb.asm.MethodVisitor
      • visitIincInsn

        public void visitIincInsn​(int varIndex,
                                  int increment)
        Overrides:
        visitIincInsn in class org.objectweb.asm.MethodVisitor
      • visitMaxs

        public void visitMaxs​(int maxStack,
                              int maxLocals)
        Overrides:
        visitMaxs in class org.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 class org.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 class org.objectweb.asm.MethodVisitor
      • visitFrame

        public void visitFrame​(int type,
                               int numLocal,
                               java.lang.Object[] local,
                               int numStack,
                               java.lang.Object[] stack)
        Overrides:
        visitFrame in class org.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 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,
                                    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 by newLocal(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)