ClassVisitor that generates a corresponding ClassFile structure, as defined in the Java
Virtual Machine Specification (JVMS). It can be used alone, to generate a Java class "from
scratch", or with one or more ClassReader and adapter ClassVisitor to generate a
modified class from one or more existing Java classes.
| Modifier and Type | Field and Description |
|---|---|
| private int | accessFlags
The access_flags field of the JVMS ClassFile structure. |
| private int | compute
Indicates what must be automatically computed in |
| public static final int | COMPUTE_FRAMES
A flag to automatically compute the stack map frames of methods from scratch. |
| public static final int | COMPUTE_MAXS
A flag to automatically compute the maximum stack size and the maximum number of local variables of methods. |
| private ByteVector | debugExtension
The debug_extension field of the SourceDebugExtension attribute, or null. |
| private int | enclosingClassIndex
The class_index field of the EnclosingMethod attribute, or 0. |
| private int | enclosingMethodIndex
The method_index field of the EnclosingMethod attribute. |
| private Attribute | firstAttribute
The first non standard attribute of this class. |
| private FieldWriter | firstField
The fields of this class, stored in a linked list of |
| private MethodWriter | firstMethod
The methods of this class, stored in a linked list of |
| private RecordComponentWriter | firstRecordComponent
The record components of this class, stored in a linked list of |
| private final int | flags
The flags passed to the constructor. |
| private ByteVector | innerClasses
The 'classes' array of the InnerClasses attribute, or null. |
| private int | interfaceCount
The interface_count field of the JVMS ClassFile structure. |
| private int[] | interfaces
The 'interfaces' array of the JVMS ClassFile structure. |
| private FieldWriter | lastField
The fields of this class, stored in a linked list of |
| private MethodWriter | lastMethod
The methods of this class, stored in a linked list of |
| private RecordComponentWriter | lastRecordComponent
The record components of this class, stored in a linked list of |
| private AnnotationWriter | lastRuntimeInvisibleAnnotation
The last runtime invisible annotation of this class. |
| private AnnotationWriter | lastRuntimeInvisibleTypeAnnotation
The last runtime invisible type annotation of this class. |
| private AnnotationWriter | lastRuntimeVisibleAnnotation
The last runtime visible annotation of this class. |
| private AnnotationWriter | lastRuntimeVisibleTypeAnnotation
The last runtime visible type annotation of this class. |
| private ModuleWriter | moduleWriter
The Module attribute of this class, or null. |
| private int | nestHostClassIndex
The host_class_index field of the NestHost attribute, or 0. |
| private ByteVector | nestMemberClasses
The 'classes' array of the NestMembers attribute, or null. |
| private int | numberOfInnerClasses
The number_of_classes field of the InnerClasses attribute, or 0. |
| private int | numberOfNestMemberClasses
The number_of_classes field of the NestMembers attribute, or 0. |
| private int | numberOfPermittedSubclasses
The number_of_classes field of the PermittedSubclasses attribute, or 0. |
| private ByteVector | permittedSubclasses
The 'classes' array of the PermittedSubclasses attribute, or null. |
| private int | signatureIndex
The signature_index field of the Signature attribute, or 0. |
| private int | sourceFileIndex
The source_file_index field of the SourceFile attribute, or 0. |
| private int | superClass
The super_class field of the JVMS ClassFile structure. |
| private final SymbolTable | symbolTable
The symbol table for this class (contains the constant_pool and the BootstrapMethods). |
| private int | thisClass
The this_class field of the JVMS ClassFile structure. |
| private int | version
The minor_version and major_version fields of the JVMS ClassFile structure. |
| Access | Constructor and Description |
|---|---|
| public | ClassWriter(final int
option flags that can be used to modify the default behavior of this class. Must
be zero or more of flags)COMPUTE_MAXS and COMPUTE_FRAMES.Constructs a new |
| public | ClassWriter(final ClassReader
the classReader, final int ClassReader used to read the original class. It will be used to
copy the entire constant pool and bootstrap methods from the original class and also to
copy other fragments of original bytecode where applicable.option flags that can be used to modify the default behavior of this class. Must
be zero or more of flags)COMPUTE_MAXS and COMPUTE_FRAMES. These option flags
do not affect methods that are copied as is in the new class. This means that neither the
maximum stack size nor the stack frames will be computed for these methods.Constructs a new |
| Modifier and Type | Method and Description |
|---|---|
| private Attribute[] | Returns: the prototypes of the attributes used by this class, its fields and its methods.Returns the prototypes of the attributes used by this class, its fields and its methods. |
| protected ClassLoader | Returns: ClassLoaderReturns the |
| protected String | Returns: the internal name of the common super class of the two given classes (seeType#getInternalName()).the internal name of a class (see type1, final String Type#getInternalName()).the internal name of another class (see type2)Type#getInternalName()).Returns the common super type of the two given types. |
| public boolean | Returns: true if all the given flags, or more, were passed to the constructor.some option flags. Must be zero or more of flags)COMPUTE_MAXS and COMPUTE_FRAMES.Returns true if all the given flags were passed to the constructor. |
| public int | Returns: the index of a new or already existing class reference item.the internal name of the class (see value)Type#getInternalName()).Adds a class reference to the constant pool of the class being build. |
| public int | |
| public int | Returns: the index of a new or already existing dynamic constant reference item.name of the invoked method. name, final String field descriptor of the constant type. descriptor, final Handle the bootstrap method. bootstrapMethodHandle, final Object... the bootstrap method constant arguments. bootstrapMethodArguments)Adds a dynamic constant reference to the constant pool of the class being build. |
| public int | Returns: the index of a new or already existing field reference item.the internal name of the field's owner class (see owner, final String Type#getInternalName()).the field's name. name, final String the field's descriptor. descriptor)Adds a field reference to the constant pool of the class being build. |
| public int | Returns: the index of a new or already existing method type reference item.the kind of this handle. Must be tag, final String Opcodes#H_GETFIELD, Opcodes#H_GETSTATIC, Opcodes#H_PUTFIELD, Opcodes#H_PUTSTATIC, Opcodes#H_INVOKEVIRTUAL, Opcodes#H_INVOKESTATIC, Opcodes#H_INVOKESPECIAL,
Opcodes#H_NEWINVOKESPECIAL or Opcodes#H_INVOKEINTERFACE.the internal name of the field or method owner class (see owner, final String Type#getInternalName()).the name of the field or method. name, final String the descriptor of the field or method. descriptor)
Deprecated
this method is superseded by
Adds a handle to the constant pool of the class being build.
newHandle(int, String, String, String,
boolean).
|
| public int | Returns: the index of a new or already existing method type reference item.the kind of this handle. Must be tag, final String Opcodes#H_GETFIELD, Opcodes#H_GETSTATIC, Opcodes#H_PUTFIELD, Opcodes#H_PUTSTATIC, Opcodes#H_INVOKEVIRTUAL, Opcodes#H_INVOKESTATIC, Opcodes#H_INVOKESPECIAL,
Opcodes#H_NEWINVOKESPECIAL or Opcodes#H_INVOKEINTERFACE.the internal name of the field or method owner class (see owner, final String Type#getInternalName()).the name of the field or method. name, final String the descriptor of the field or method. descriptor, final boolean true if the owner is an interface. isInterface)Adds a handle to the constant pool of the class being build. |
| public int | Returns: the index of a new or already existing invokedynamic reference item.name of the invoked method. name, final String descriptor of the invoke method. descriptor, final Handle the bootstrap method. bootstrapMethodHandle, final Object... the bootstrap method constant arguments. bootstrapMethodArguments)Adds an invokedynamic reference to the constant pool of the class being build. |
| public int | Returns: the index of a new or already existing method reference item.the internal name of the method's owner class (see owner, final String Type#getInternalName()).the method's name. name, final String the method's descriptor. descriptor, final boolean true if isInterface)owner is an interface.Adds a method reference to the constant pool of the class being build. |
| public int | Returns: the index of a new or already existing method type reference item.method descriptor of the method type. methodDescriptor)Adds a method type reference to the constant pool of the class being build. |
| public int | |
| public int | Returns: the index of a new or already existing name and type item.a name. name, final String a type descriptor. descriptor)Adds a name and type to the constant pool of the class being build. |
| public int | Returns: the index of a new or already existing module reference item.name of the package in its internal form. packageName)Adds a package reference to the constant pool of the class being build. |
| public int | |
| private byte[] | Returns: an equivalent of 'classFile', with the ASM specific instructions replaced with standard ones.a class file containing ASM specific instructions, generated by this
ClassWriter. classFile, final boolean whether there is at least one stack map frames in 'classFile'. hasFrames)Returns the equivalent of the given class file, with the ASM specific instructions replaced with standard ones. |
| public byte[] | Returns: the binary content of the JVMS ClassFile structure that was built by this ClassWriter.Returns the content of the class file that was built by this ClassWriter. |
| public final void | visit(final int
the class version. The minor version is stored in the 16 most significant bits,
and the major version in the 16 least significant bits. version, final int the class's access flags (see access, final String Opcodes). This parameter also indicates if
the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.the internal name of the class (see name, final String Type#getInternalName()).the signature of this class. May be null if the class is not a
generic one, and does not extend or implement generic classes or interfaces. signature, final String the internal of name of the super class (see superName, final String[] Type#getInternalName()).
For interfaces, the super class is Object. May be null, but only for the
Object class.the internal names of the class's interfaces (see interfaces)Type#getInternalName()). May be null.Overrides net. |
| public final AnnotationVisitor | visitAnnotation(final String
the class descriptor of the annotation class. descriptor, final boolean true if the annotation is visible at runtime. visible)Overrides net. |
| public final void | visitAttribute(final Attribute
an attribute. attribute)Overrides net. |
| public final void | |
| public final FieldVisitor | visitField(final int
the field's access flags (see access, final String Opcodes). This parameter also indicates if
the field is synthetic and/or deprecated.the field's name. name, final String the field's descriptor (see descriptor, final String Type).the field's signature. May be null if the field's type does not use
generic types. signature, final Object the field's initial value. This parameter, which may be null if the
field does not have an initial value, must be an value)
Visits a field of the class.
Integer, a Float, a Long, a Double or a String (for int, float, long
or String fields respectively). This parameter is only used for static
fields. Its value is ignored for non static fields, which must be initialized through
bytecode instructions in constructors or methods. |
| public final void | visitInnerClass(final String
the internal name of C (see name, final String Type#getInternalName()).the internal name of the class or interface C is a member of (see outerName, final String Type#getInternalName()). Must be null if C is not the member of a class or
interface (e.g. for local or anonymous classes).the (simple) name of C. Must be null for anonymous inner classes. innerName, final int the access flags of C originally declared in the source code from which this
class was compiled. access)Overrides net. |
| public final MethodVisitor | visitMethod(final int
the method's access flags (see access, final String Opcodes). This parameter also indicates if
the method is synthetic and/or deprecated.the method's name. name, final String the method's descriptor (see descriptor, final String Type).the method's signature. May be null if the method parameters,
return type and exceptions do not use generic types. signature, final String[] the internal names of the method's exception classes (see exceptions)
Visits a method of the class.
Type#getInternalName()). May be null. |
| public final ModuleVisitor | visitModule(final String
the fully qualified name (using dots) of the module. name, final int the module access flags, among access, final String ACC_OPEN, ACC_SYNTHETIC and ACC_MANDATED.the module version, or null. version)
Visit the module corresponding to the class.
|
| public final void | visitNestHost(final String
the internal name of the host class of the nest (see nestHost)
Visits the nest host class of the class.
Type#getInternalName()). |
| public final void | visitNestMember(final String
the internal name of a nest member (see nestMember)Type#getInternalName()).Overrides net. |
| public final void | visitOuterClass(final String
internal name of the enclosing class of the class (see owner, final String Type#getInternalName()).the name of the method that contains the class, or null if the class is
not enclosed in a method or constructor of its enclosing class (e.g. if it is enclosed in
an instance initializer, static initializer, instance variable initializer, or class
variable initializer). name, final String the descriptor of the method that contains the class, or null if
the class is not enclosed in a method or constructor of its enclosing class (e.g. if it is
enclosed in an instance initializer, static initializer, instance variable initializer, or
class variable initializer). descriptor)Overrides net. |
| public final void | visitPermittedSubclass(final String
the internal name of a permitted subclass (see permittedSubclass)Type#getInternalName()).Overrides net. |
| public final RecordComponentVisitor | visitRecordComponent(final String
the record component name. name, final String the record component descriptor (see descriptor, final String Type).the record component signature. May be null if the record component
type does not use generic types. signature)Overrides net. |
| public final void | visitSource(final String
the name of the source file from which the class was compiled. May be null. file, final String additional debug information to compute the correspondence between source and
compiled elements of the class. May be null. debug)
Visits the source of the class.
|
| public final AnnotationVisitor | visitTypeAnnotation(final int
a reference to the annotated type. The sort of this type reference must be
typeRef, final TypePath TypeReference#CLASS_TYPE_PARAMETER, TypeReference#CLASS_TYPE_PARAMETER_BOUND or TypeReference#CLASS_EXTENDS. See
TypeReference.the path to the annotated type argument, wildcard bound, array element type, or
static inner type within 'typeRef'. May be null if the annotation targets
'typeRef' as a whole. typePath, final String the class descriptor of the annotation class. descriptor, final boolean true if the annotation is visible at runtime. visible)Overrides net. |