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.