org.objectweb.asm.util

## Class Printer

- java.lang.Object
- - org.objectweb.asm.util.Printer

- Direct Known Subclasses:
    ASMifier, Textifier

      public abstract class Printer
      extends Object

  An abstract converter from visit events to text.
  Author:
    Eric Bruneton

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `api` The ASM API version implemented by this class.
    `protected StringBuffer` | `buf` A buffer that can be used to create strings.
    `static String[]` | `HANDLE_TAG` The names of the `tag` field values for `Handle`.
    `static String[]` | `OPCODES` The names of the Java Virtual Machine opcodes.
    `List<Object>` | `text` The text to be printed.
    `static String[]` | `TYPES` The names of the for `operand` parameter values of the `MethodVisitor.visitIntInsn(int, int)` method when `opcode` is `NEWARRAY`.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Printer(int api)` Constructs a new `Printer`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `appendString(StringBuffer buf, String s)` Appends a quoted string to a given buffer.
    `List<Object>` | `getText()` Returns the text constructed by this visitor.
    `void` | `print(PrintWriter pw)` Prints the text constructed by this visitor.
    `abstract void` | `visit(int version, int access, String name, String signature, String superName, String[] interfaces)` Class header.
    `abstract void` | `visit(String name, Object value)` Annotation value.
    `abstract Printer` | `visitAnnotation(String name, String desc)` Nested annotation value.
    `abstract Printer` | `visitAnnotationDefault()` Method default annotation.
    `abstract void` | `visitAnnotationEnd()` Annotation end.
    `abstract Printer` | `visitArray(String name)` Annotation array value.
    `abstract Printer` | `visitClassAnnotation(String desc, boolean visible)` Class annotation.
    `abstract void` | `visitClassAttribute(Attribute attr)` Class attribute.
    `abstract void` | `visitClassEnd()` Class end.
    `Printer` | `visitClassTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible)` Class type annotation.
    `abstract void` | `visitCode()` Method start.
    `abstract void` | `visitEnum(String name, String desc, String value)` Annotation enum value.
    `abstract Printer` | `visitField(int access, String name, String desc, String signature, Object value)` Class field.
    `abstract Printer` | `visitFieldAnnotation(String desc, boolean visible)` Field annotation.
    `abstract void` | `visitFieldAttribute(Attribute attr)` Field attribute.
    `abstract void` | `visitFieldEnd()` Field end.
    `abstract void` | `visitFieldInsn(int opcode, String owner, String name, String desc)` Method instruction.
    `Printer` | `visitFieldTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible)` Field type annotation.
    `abstract void` | `visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack)` Method stack frame.
    `abstract void` | `visitIincInsn(int var, int increment)` Method instruction.
    `abstract void` | `visitInnerClass(String name, String outerName, String innerName, int access)` Class inner name.
    `abstract void` | `visitInsn(int opcode)` Method instruction.
    `Printer` | `visitInsnAnnotation(int typeRef, TypePath typePath, String desc, boolean visible)` Instruction type annotation.
    `abstract void` | `visitIntInsn(int opcode, int operand)` Method instruction.
    `abstract void` | `visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs)` Method instruction.
    `abstract void` | `visitJumpInsn(int opcode, Label label)` Method instruction.
    `abstract void` | `visitLabel(Label label)` Method label.
    `abstract void` | `visitLdcInsn(Object cst)` Method instruction.
    `abstract void` | `visitLineNumber(int line, Label start)` Method debug info.
    `abstract void` | `visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)` Method debug info.
    `Printer` | `visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible)` Local variable type annotation.
    `abstract void` | `visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)` Method instruction.
    `abstract void` | `visitMaxs(int maxStack, int maxLocals)` Method max stack and max locals.
    `abstract Printer` | `visitMethod(int access, String name, String desc, String signature, String[] exceptions)` Class method.
    `abstract Printer` | `visitMethodAnnotation(String desc, boolean visible)` Method annotation.
    `abstract void` | `visitMethodAttribute(Attribute attr)` Method attribute.
    `abstract void` | `visitMethodEnd()` Method end.
    `void` | `visitMethodInsn(int opcode, String owner, String name, String desc)` Deprecated.
    `void` | `visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf)` Method instruction.
    `Printer` | `visitMethodTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible)` Method type annotation.
    `abstract void` | `visitMultiANewArrayInsn(String desc, int dims)` Method instruction.
    `abstract void` | `visitOuterClass(String owner, String name, String desc)` Class outer class.
    `void` | `visitParameter(String name, int access)` Method parameter.
    `abstract Printer` | `visitParameterAnnotation(int parameter, String desc, boolean visible)` Method parameter annotation.
    `abstract void` | `visitSource(String file, String debug)` Class source.
    `abstract void` | `visitTableSwitchInsn(int min, int max, Label dflt, Label... labels)` Method instruction.
    `Printer` | `visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible)` Try catch block type annotation.
    `abstract void` | `visitTryCatchBlock(Label start, Label end, Label handler, String type)` Method exception handler.
    `abstract void` | `visitTypeInsn(int opcode, String type)` Method instruction.
    `abstract void` | `visitVarInsn(int opcode, int var)` Method instruction.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### OPCODES

          public static final String[] OPCODES

      The names of the Java Virtual Machine opcodes.

    - #### TYPES

          public static final String[] TYPES

      The names of the for `operand` parameter values of the `MethodVisitor.visitIntInsn(int, int)` method when `opcode` is `NEWARRAY`.

    - #### HANDLE_TAG

          public static final String[] HANDLE_TAG

      The names of the `tag` field values for `Handle`.

    - #### api

          protected final int api

      The ASM API version implemented by this class. The value of this field must be one of `Opcodes.ASM4` or `Opcodes.ASM5`.

    - #### buf

          protected final StringBuffer buf

      A buffer that can be used to create strings.

    - #### text

          public final List<Object> text

      The text to be printed. Since the code of methods is not necessarily visited in sequential order, one method after the other, but can be interlaced (some instructions from method one, then some instructions from method two, then some instructions from method one again...), it is not possible to print the visited instructions directly to a sequential stream. A class is therefore printed in a two steps process: a string tree is constructed during the visit, and printed to a sequential stream at the end of the visit. This string tree is stored in this field, as a string list that can contain other string lists, which can themselves contain other string lists, and so on.

  - ### Constructor Detail

    - #### Printer

          protected Printer(int api)

      Constructs a new `Printer`.

  - ### Method Detail

    - #### visit

          public abstract void visit(int version,
                                     int access,
                                     String name,
                                     String signature,
                                     String superName,
                                     String[] interfaces)

      Class header. See `ClassVisitor.visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])`.

    - #### visitSource

          public abstract void visitSource(String file,
                                           String debug)

      Class source. See `ClassVisitor.visitSource(java.lang.String, java.lang.String)`.

    - #### visitOuterClass

          public abstract void visitOuterClass(String owner,
                                               String name,
                                               String desc)

      Class outer class. See `ClassVisitor.visitOuterClass(java.lang.String, java.lang.String, java.lang.String)`.

    - #### visitClassAnnotation

          public abstract Printer visitClassAnnotation(String desc,
                                                       boolean visible)

      Class annotation. See `ClassVisitor.visitAnnotation(java.lang.String, boolean)`.

    - #### visitClassTypeAnnotation

          public Printer visitClassTypeAnnotation(int typeRef,
                                                  TypePath typePath,
                                                  String desc,
                                                  boolean visible)

      Class type annotation. See `ClassVisitor.visitTypeAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean)`.

    - #### visitClassAttribute

          public abstract void visitClassAttribute(Attribute attr)

      Class attribute. See `ClassVisitor.visitAttribute(org.objectweb.asm.Attribute)`.

    - #### visitInnerClass

          public abstract void visitInnerClass(String name,
                                               String outerName,
                                               String innerName,
                                               int access)

      Class inner name. See `ClassVisitor.visitInnerClass(java.lang.String, java.lang.String, java.lang.String, int)`.

    - #### visitField

          public abstract Printer visitField(int access,
                                             String name,
                                             String desc,
                                             String signature,
                                             Object value)

      Class field. See `ClassVisitor.visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)`.

    - #### visitMethod

          public abstract Printer visitMethod(int access,
                                              String name,
                                              String desc,
                                              String signature,
                                              String[] exceptions)

      Class method. See `ClassVisitor.visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])`.

    - #### visitClassEnd

          public abstract void visitClassEnd()

      Class end. See `ClassVisitor.visitEnd()`.

    - #### visit

          public abstract void visit(String name,
                                     Object value)

      Annotation value. See `AnnotationVisitor.visit(java.lang.String, java.lang.Object)`.

    - #### visitEnum

          public abstract void visitEnum(String name,
                                         String desc,
                                         String value)

      Annotation enum value. See `AnnotationVisitor.visitEnum(java.lang.String, java.lang.String, java.lang.String)`.

    - #### visitAnnotation

          public abstract Printer visitAnnotation(String name,
                                                  String desc)

      Nested annotation value. See `AnnotationVisitor.visitAnnotation(java.lang.String, java.lang.String)`.

    - #### visitArray

          public abstract Printer visitArray(String name)

      Annotation array value. See `AnnotationVisitor.visitArray(java.lang.String)`.

    - #### visitAnnotationEnd

          public abstract void visitAnnotationEnd()

      Annotation end. See `AnnotationVisitor.visitEnd()`.

    - #### visitFieldAnnotation

          public abstract Printer visitFieldAnnotation(String desc,
                                                       boolean visible)

      Field annotation. See `FieldVisitor.visitAnnotation(java.lang.String, boolean)`.

    - #### visitFieldTypeAnnotation

          public Printer visitFieldTypeAnnotation(int typeRef,
                                                  TypePath typePath,
                                                  String desc,
                                                  boolean visible)

      Field type annotation. See `FieldVisitor.visitTypeAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean)`.

    - #### visitFieldAttribute

          public abstract void visitFieldAttribute(Attribute attr)

      Field attribute. See `FieldVisitor.visitAttribute(org.objectweb.asm.Attribute)`.

    - #### visitFieldEnd

          public abstract void visitFieldEnd()

      Field end. See `FieldVisitor.visitEnd()`.

    - #### visitParameter

          public void visitParameter(String name,
                                     int access)

      Method parameter. See `MethodVisitor.visitParameter(String, int)`.

    - #### visitAnnotationDefault

          public abstract Printer visitAnnotationDefault()

      Method default annotation. See `MethodVisitor.visitAnnotationDefault()`.

    - #### visitMethodAnnotation

          public abstract Printer visitMethodAnnotation(String desc,
                                                        boolean visible)

      Method annotation. See `MethodVisitor.visitAnnotation(java.lang.String, boolean)`.

    - #### visitMethodTypeAnnotation

          public Printer visitMethodTypeAnnotation(int typeRef,
                                                   TypePath typePath,
                                                   String desc,
                                                   boolean visible)

      Method type annotation. See `MethodVisitor.visitTypeAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean)`.

    - #### visitParameterAnnotation

          public abstract Printer visitParameterAnnotation(int parameter,
                                                           String desc,
                                                           boolean visible)

      Method parameter annotation. See `MethodVisitor.visitParameterAnnotation(int, java.lang.String, boolean)`.

    - #### visitMethodAttribute

          public abstract void visitMethodAttribute(Attribute attr)

      Method attribute. See `MethodVisitor.visitAttribute(org.objectweb.asm.Attribute)`.

    - #### visitCode

          public abstract void visitCode()

      Method start. See `MethodVisitor.visitCode()`.

    - #### visitFrame

          public abstract void visitFrame(int type,
                                          int nLocal,
                                          Object[] local,
                                          int nStack,
                                          Object[] stack)

      Method stack frame. See `MethodVisitor.visitFrame(int, int, java.lang.Object[], int, java.lang.Object[])`.

    - #### visitInsn

          public abstract void visitInsn(int opcode)

      Method instruction. See `MethodVisitor.visitInsn(int)` .

    - #### visitIntInsn

          public abstract void visitIntInsn(int opcode,
                                            int operand)

      Method instruction. See `MethodVisitor.visitIntInsn(int, int)`.

    - #### visitVarInsn

          public abstract void visitVarInsn(int opcode,
                                            int var)

      Method instruction. See `MethodVisitor.visitVarInsn(int, int)`.

    - #### visitTypeInsn

          public abstract void visitTypeInsn(int opcode,
                                             String type)

      Method instruction. See `MethodVisitor.visitTypeInsn(int, java.lang.String)`.

    - #### visitFieldInsn

          public abstract void visitFieldInsn(int opcode,
                                              String owner,
                                              String name,
                                              String desc)

      Method instruction. See `MethodVisitor.visitFieldInsn(int, java.lang.String, java.lang.String, java.lang.String)`.

    - #### visitMethodInsn

          @Deprecated
          public void visitMethodInsn(int opcode,
                                                   String owner,
                                                   String name,
                                                   String desc)

      Deprecated.
      Method instruction. See `MethodVisitor.visitMethodInsn(int, java.lang.String, java.lang.String, java.lang.String)`.

    - #### visitMethodInsn

          public void visitMethodInsn(int opcode,
                                      String owner,
                                      String name,
                                      String desc,
                                      boolean itf)

      Method instruction. See `MethodVisitor.visitMethodInsn(int, java.lang.String, java.lang.String, java.lang.String)`.

    - #### visitInvokeDynamicInsn

          public abstract void visitInvokeDynamicInsn(String name,
                                                      String desc,
                                                      Handle bsm,
                                                      Object... bsmArgs)

      Method instruction. See `MethodVisitor.visitInvokeDynamicInsn(java.lang.String, java.lang.String, org.objectweb.asm.Handle, java.lang.Object...)`.

    - #### visitJumpInsn

          public abstract void visitJumpInsn(int opcode,
                                             Label label)

      Method instruction. See `MethodVisitor.visitJumpInsn(int, org.objectweb.asm.Label)`.

    - #### visitLabel

          public abstract void visitLabel(Label label)

      Method label. See `MethodVisitor.visitLabel(org.objectweb.asm.Label)`.

    - #### visitLdcInsn

          public abstract void visitLdcInsn(Object cst)

      Method instruction. See `MethodVisitor.visitLdcInsn(java.lang.Object)`.

    - #### visitIincInsn

          public abstract void visitIincInsn(int var,
                                             int increment)

      Method instruction. See `MethodVisitor.visitIincInsn(int, int)`.

    - #### visitTableSwitchInsn

          public abstract void visitTableSwitchInsn(int min,
                                                    int max,
                                                    Label dflt,
                                                    Label... labels)

      Method instruction. See `MethodVisitor.visitTableSwitchInsn(int, int, org.objectweb.asm.Label, org.objectweb.asm.Label...)`.

    - #### visitLookupSwitchInsn

          public abstract void visitLookupSwitchInsn(Label dflt,
                                                     int[] keys,
                                                     Label[] labels)

      Method instruction. See `MethodVisitor.visitLookupSwitchInsn(org.objectweb.asm.Label, int[], org.objectweb.asm.Label[])`.

    - #### visitMultiANewArrayInsn

          public abstract void visitMultiANewArrayInsn(String desc,
                                                       int dims)

      Method instruction. See `MethodVisitor.visitMultiANewArrayInsn(java.lang.String, int)`.

    - #### visitInsnAnnotation

          public Printer visitInsnAnnotation(int typeRef,
                                             TypePath typePath,
                                             String desc,
                                             boolean visible)

      Instruction type annotation. See `MethodVisitor.visitInsnAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean)`.

    - #### visitTryCatchBlock

          public abstract void visitTryCatchBlock(Label start,
                                                  Label end,
                                                  Label handler,
                                                  String type)

      Method exception handler. See `MethodVisitor.visitTryCatchBlock(org.objectweb.asm.Label, org.objectweb.asm.Label, org.objectweb.asm.Label, java.lang.String)`.

    - #### visitTryCatchAnnotation

          public Printer visitTryCatchAnnotation(int typeRef,
                                                 TypePath typePath,
                                                 String desc,
                                                 boolean visible)

      Try catch block type annotation. See `MethodVisitor.visitTryCatchAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean)`.

    - #### visitLocalVariable

          public abstract void visitLocalVariable(String name,
                                                  String desc,
                                                  String signature,
                                                  Label start,
                                                  Label end,
                                                  int index)

      Method debug info. See `MethodVisitor.visitLocalVariable(java.lang.String, java.lang.String, java.lang.String, org.objectweb.asm.Label, org.objectweb.asm.Label, int)`.

    - #### visitLocalVariableAnnotation

          public Printer visitLocalVariableAnnotation(int typeRef,
                                                      TypePath typePath,
                                                      Label[] start,
                                                      Label[] end,
                                                      int[] index,
                                                      String desc,
                                                      boolean visible)

      Local variable type annotation. See `MethodVisitor.visitTryCatchAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean)`.

    - #### visitLineNumber

          public abstract void visitLineNumber(int line,
                                               Label start)

      Method debug info. See `MethodVisitor.visitLineNumber(int, org.objectweb.asm.Label)`.

    - #### visitMaxs

          public abstract void visitMaxs(int maxStack,
                                         int maxLocals)

      Method max stack and max locals. See `MethodVisitor.visitMaxs(int, int)`.

    - #### visitMethodEnd

          public abstract void visitMethodEnd()

      Method end. See `MethodVisitor.visitEnd()`.

    - #### getText

          public List<Object> getText()

      Returns the text constructed by this visitor.
      Returns:
        the text constructed by this visitor.

    - #### print

          public void print(PrintWriter pw)

      Prints the text constructed by this visitor.
      Parameters:
        `pw` - the print writer to be used.

    - #### appendString

          public static void appendString(StringBuffer buf,
                                          String s)

      Appends a quoted string to a given buffer.
      Parameters:
        `buf` - the buffer where the string must be added.
        `s` - the string to be added.