Class JdkClassWriter

java.lang.Object
org.objectweb.asm.ClassVisitor
codes.rafael.asmjdkbridge.JdkClassWriter

public class JdkClassWriter extends org.objectweb.asm.ClassVisitor
A class visitor that creates a class file which is based upon the JDK Class File API.
  • Constructor Details

    • JdkClassWriter

      public JdkClassWriter(int flags)
      Creates a class writer.
      Parameters:
      flags - The ASM flags to consider.
    • JdkClassWriter

      public JdkClassWriter(JdkClassReader classReader, int flags)
      Creates a class writer.
      Parameters:
      classReader - A class reader of which to retain the constant pool, if possible.
      flags - The ASM flags to consider.
    • JdkClassWriter

      public JdkClassWriter(int flags, Method getSuperClass, Object target)
      Creates a class writer.
      Parameters:
      flags - The ASM flags to consider.
      getSuperClass - A resolver for the supplied internal class name's internal super class name. If a class is an interface, null should be returned. As a method to allow pre-Java 8 code to call this constructor via reflection.
      target - The target to invoke the reflective method on.
    • JdkClassWriter

      public JdkClassWriter(JdkClassReader classReader, int flags, Method getSuperClass, Object target)
      Creates a class writer.
      Parameters:
      classReader - A class reader of which to retain the constant pool, if possible.
      flags - The ASM flags to consider.
      getSuperClass - A resolver for the supplied internal class name's internal super class name. If a class is an interface, null should be returned. As a method to allow pre-Java 8 code to call this constructor via reflection.
      target - The target to invoke the reflective method on.
    • JdkClassWriter

      public JdkClassWriter(int flags, Function<String,String> getSuperClass)
      Creates a class writer.
      Parameters:
      flags - The ASM flags to consider.
      getSuperClass - A resolver for the supplied internal class name's internal super class name. If a class is an interface, null should be returned.
    • JdkClassWriter

      public JdkClassWriter(JdkClassReader classReader, int flags, Function<String,String> getSuperClass)
      Creates a class writer.
      Parameters:
      classReader - A class reader of which to retain the constant pool, if possible.
      flags - The ASM flags to consider.
      getSuperClass - A resolver for the supplied internal class name's internal super class name. If a class is an interface, null should be returned.
  • Method Details

    • toByteArray

      public byte[] toByteArray()
      Returns the generated class file.
      Returns:
      The class file as a byte array.
    • getSuperClass

      protected String getSuperClass(String name)
      Returns the super class of the class that is provided by name. The default implementation resolves the super class from this instance's class' ClassLoader, unless getClassLoader() is overridden.

      This is used for generating stack map frames.

      Parameters:
      name - The name of the class for which to resolve the super class.
      Returns:
      The name of the resolved super class.
    • getClassLoader

      protected ClassLoader getClassLoader()
      Returns the class loader to use for resolving the super class of a discovered class.
      Returns:
      The class loader to use for resolving a super class's name.
    • visit

      public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
      Overrides:
      visit in class org.objectweb.asm.ClassVisitor
    • visitSource

      public void visitSource(String source, String debug)
      Overrides:
      visitSource in class org.objectweb.asm.ClassVisitor
    • visitModule

      public org.objectweb.asm.ModuleVisitor visitModule(String name, int access, String version)
      Overrides:
      visitModule in class org.objectweb.asm.ClassVisitor
    • visitNestHost

      public void visitNestHost(String nestHost)
      Overrides:
      visitNestHost in class org.objectweb.asm.ClassVisitor
    • visitOuterClass

      public void visitOuterClass(String owner, String name, String descriptor)
      Overrides:
      visitOuterClass in class org.objectweb.asm.ClassVisitor
    • visitAnnotation

      public org.objectweb.asm.AnnotationVisitor visitAnnotation(String descriptor, boolean visible)
      Overrides:
      visitAnnotation in class org.objectweb.asm.ClassVisitor
    • visitAttribute

      public void visitAttribute(org.objectweb.asm.Attribute attribute)
      Overrides:
      visitAttribute in class org.objectweb.asm.ClassVisitor
    • visitTypeAnnotation

      public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible)
      Overrides:
      visitTypeAnnotation in class org.objectweb.asm.ClassVisitor
    • visitNestMember

      public void visitNestMember(String nestMember)
      Overrides:
      visitNestMember in class org.objectweb.asm.ClassVisitor
    • visitPermittedSubclass

      public void visitPermittedSubclass(String permittedSubclass)
      Overrides:
      visitPermittedSubclass in class org.objectweb.asm.ClassVisitor
    • visitInnerClass

      public void visitInnerClass(String name, String outerName, String innerName, int access)
      Overrides:
      visitInnerClass in class org.objectweb.asm.ClassVisitor
    • visitRecordComponent

      public org.objectweb.asm.RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature)
      Overrides:
      visitRecordComponent in class org.objectweb.asm.ClassVisitor
    • visitField

      public org.objectweb.asm.FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value)
      Overrides:
      visitField in class org.objectweb.asm.ClassVisitor
    • visitMethod

      public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
      Overrides:
      visitMethod in class org.objectweb.asm.ClassVisitor
    • visitEnd

      public void visitEnd()
      Overrides:
      visitEnd in class org.objectweb.asm.ClassVisitor