Class ProbingClassReader

java.lang.Object
codes.rafael.asmjdkbridge.ProbingClassReader

public class ProbingClassReader extends Object
A class reader that automatically resolves a suitable reader, either based on ASM (if ASM officially supports a class file version) or a JDK Class File API based implementation.
  • Constructor Details

    • ProbingClassReader

      public ProbingClassReader(byte[] classFile, org.objectweb.asm.Attribute... attributePrototypes)
      Creates a new class reader.
      Parameters:
      classFile - The class file to represent.
      attributePrototypes - Prototypes of ASM attributes to map if discovered.
    • ProbingClassReader

      public ProbingClassReader(InputStream inputStream, org.objectweb.asm.Attribute... attributePrototypes) throws IOException
      Creates a new class reader.
      Parameters:
      inputStream - An input stream of the class file to represent.
      attributePrototypes - Prototypes of ASM attributes to map if discovered.
      Throws:
      IOException - If the stream cannot be read.
    • ProbingClassReader

      public ProbingClassReader(String className, org.objectweb.asm.Attribute... attributePrototypes) throws IOException
      Creates a new class reader.
      Parameters:
      className - The name of the class to represent. The class must be resolvable from the system loader.
      attributePrototypes - Prototypes of ASM attributes to map if discovered.
      Throws:
      IOException - If the class file cannot be read.
  • Method Details

    • accept

      public void accept(org.objectweb.asm.ClassVisitor classVisitor, int flags)
      Accepts a class visitor for the represented class file.
      Parameters:
      classVisitor - The class visitor to delegate calls to.
      flags - The ASM flags to consider when visiting the class file.
    • toClassWriter

      public ProbingClassReader.ClassWriterContainer<?> toClassWriter(int flags)
      Resolves the underlying class reader to an implementation-equivalent class writer. Using this approach, an attempt is made to retain the constant pool if a class is supposed to be transformed.
      Parameters:
      flags - The ASM flags to consider when creating the class writer.
      Returns:
      A suitable container for a class writer.