Class ClassAnnotationSceneWriter

java.lang.Object
org.objectweb.asm.ClassVisitor
org.checkerframework.afu.scenelib.io.classfile.CodeOffsetAdapter
org.checkerframework.afu.scenelib.io.classfile.ClassAnnotationSceneWriter

public class ClassAnnotationSceneWriter extends CodeOffsetAdapter
A ClassAnnotationSceneWriter is a ClassVisitor that can be used to write a class file that is the combination of an existing class file and annotations in an AScene. The "write" in ClassAnnotationSceneWriter refers to a class file being rewritten with information from a scene. Also see ClassAnnotationSceneReader.

The proper usage of this class is to construct a ClassAnnotationSceneWriter with a AScene that already contains all its annotations, pass this as a ClassVisitor to ClassReader.accept(org.objectweb.asm.ClassVisitor, int), and then obtain the resulting class, ready to be written to a file, with toByteArray().

All other methods are intended to be called only by ClassReader.accept(org.objectweb.asm.ClassVisitor, int), and should not be called anywhere else, due to the order in which ClassVisitor methods should be called.

Throughout this class, "scene" refers to the AScene this class is merging into a class file.

  • Constructor Details

    • ClassAnnotationSceneWriter

      public ClassAnnotationSceneWriter(int api, org.objectweb.asm.ClassReader classReader, AScene scene, boolean overwrite)
      Constructs a new ClassAnnotationSceneWriter that will insert all the annotations in scene into the class that it visits. scene must be an AScene over the class that this will visit.
      Parameters:
      api - the ASM API version to use
      classReader - the reader for the class being modified
      scene - the annotation scene containing annotations to be inserted into the class this visits
      overwrite - true if to overwrite existing annotations on the same element
  • Method Details

    • toByteArray

      public byte[] toByteArray()
      Returns a byte array that represents the resulting class file from merging all the annotations in the scene into the class file this has visited. This method may only be called once this has already completely visited a class, which is done by calling ClassReader.accept(org.objectweb.asm.ClassVisitor, int).
      Returns:
      a byte array of the merged class file
    • visit

      public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
      Overrides:
      visit 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
    • 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 CodeOffsetAdapter
    • visitEnd

      public void visitEnd()
      Overrides:
      visitEnd 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
    • 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