Class ClassAnnotationSceneWriter
java.lang.Object
org.objectweb.asm.ClassVisitor
org.checkerframework.afu.scenelib.io.classfile.CodeOffsetAdapter
org.checkerframework.afu.scenelib.io.classfile.ClassAnnotationSceneWriter
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.
-
Field Summary
Fields inherited from class org.objectweb.asm.ClassVisitor
api, cv
-
Constructor Summary
ConstructorsConstructorDescriptionClassAnnotationSceneWriter
(int api, org.objectweb.asm.ClassReader classReader, AScene scene, boolean overwrite) Constructs a newClassAnnotationSceneWriter
that will insert all the annotations inscene
into the class that it visits. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
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.void
visit
(int version, int access, String name, String signature, String superName, String[] interfaces) org.objectweb.asm.AnnotationVisitor
visitAnnotation
(String descriptor, boolean visible) void
visitEnd()
org.objectweb.asm.FieldVisitor
visitField
(int access, String name, String descriptor, String signature, Object value) void
visitInnerClass
(String name, String outerName, String innerName, int access) org.objectweb.asm.MethodVisitor
visitMethod
(int access, String name, String descriptor, String signature, String[] exceptions) org.objectweb.asm.AnnotationVisitor
visitTypeAnnotation
(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) Methods inherited from class org.checkerframework.afu.scenelib.io.classfile.CodeOffsetAdapter
getBytecodeOffset, getMethodCodeOffset, getPreviousCodeOffset
Methods inherited from class org.objectweb.asm.ClassVisitor
getDelegate, visitAttribute, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitSource
-
Constructor Details
-
ClassAnnotationSceneWriter
public ClassAnnotationSceneWriter(int api, org.objectweb.asm.ClassReader classReader, AScene scene, boolean overwrite) Constructs a newClassAnnotationSceneWriter
that will insert all the annotations inscene
into the class that it visits.scene
must be anAScene
over the class that this will visit.- Parameters:
api
- the ASM API version to useclassReader
- the reader for the class being modifiedscene
- the annotation scene containing annotations to be inserted into the class this visitsoverwrite
- 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 callingClassReader.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 classorg.objectweb.asm.ClassVisitor
-
visitInnerClass
- Overrides:
visitInnerClass
in classorg.objectweb.asm.ClassVisitor
-
visitField
public org.objectweb.asm.FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) - Overrides:
visitField
in classorg.objectweb.asm.ClassVisitor
-
visitMethod
public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) - Overrides:
visitMethod
in classCodeOffsetAdapter
-
visitEnd
public void visitEnd()- Overrides:
visitEnd
in classorg.objectweb.asm.ClassVisitor
-
visitAnnotation
- Overrides:
visitAnnotation
in classorg.objectweb.asm.ClassVisitor
-
visitTypeAnnotation
public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) - Overrides:
visitTypeAnnotation
in classorg.objectweb.asm.ClassVisitor
-