Package net.bytebuddy.dynamic.scaffold
Class TypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor
java.lang.Object
org.objectweb.asm.ClassVisitor
net.bytebuddy.utility.visitor.MetadataAwareClassVisitor
net.bytebuddy.dynamic.scaffold.TypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor
- Enclosing class:
TypeWriter.Default.ForInlining.WithFullProcessing<V>
protected class TypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor
extends MetadataAwareClassVisitor
A class visitor which is capable of applying a redefinition of an existing class file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
A field visitor that obtains all attributes and annotations of a field that is found in the class file but that discards all code.protected class
A method visitor that obtains all attributes and annotations of a method that is found in the class file but that discards all code.protected class
A record component visitor that obtains all attributes and annotations of a record component that is found in the class file but discards all code.protected class
A method visitor that preserves the code of a method in the class file by copying it into a rebased method while copying all attributes and annotations to the actual method. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TypeWriter.Default.ForInlining.ContextRegistry
A context registry to register the lazily created implementation context to.private final LinkedHashMap
<TypeWriter.Default.SignatureKey, FieldDescription> A mapping of fields to write by their unique signature.private final LinkedHashMap
<TypeWriter.Default.SignatureKey, MethodDescription> A mapping of methods to write by their unique signature.private final LinkedHashMap
<String, RecordComponentDescription> A mapping of record components to write by their names.private final LinkedHashMap
<String, TypeDescription> A mapping of the internal names of all declared types to their description.The implementation context for this class creation ornull
if it was not yet created.The initialization handler to use ornull
if the handler was not yet initialized.private TypeWriter.MethodPool
The method pool to use ornull
if the pool was not yet initialized.A set of internal names of all nest members not yet defined by this type.A list of internal names of permitted subclasses to include.private final int
The reader flags being used.private boolean
true
if the modifiers for deprecation should be retained.private final TypeInitializer
The type initializer to apply.private final int
The writer flags being used.Fields inherited from class org.objectweb.asm.ClassVisitor
api, cv
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
RedefinitionClassVisitor
(org.objectweb.asm.ClassVisitor classVisitor, TypeInitializer typeInitializer, TypeWriter.Default.ForInlining.ContextRegistry contextRegistry, int writerFlags, int readerFlags) Creates a class visitor which is capable of redefining an existent class on the fly. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Invoked if the attribute visitation is about to complete.protected void
Invoked if the nest host was not visited.protected void
Invoked if the outer class was not visited.protected org.objectweb.asm.AnnotationVisitor
onVisitAnnotation
(String descriptor, boolean visible) An order-sensitive invocation ofClassVisitor.visitAnnotation(String, boolean)
.protected void
An order-sensitive invocation ofClassVisitor.visitEnd()
.protected org.objectweb.asm.FieldVisitor
onVisitField
(int modifiers, String internalName, String descriptor, String genericSignature, Object value) An order-sensitive invocation ofClassVisitor.visitField(int, String, String, String, Object)
.protected void
onVisitInnerClass
(String internalName, String outerName, String innerName, int modifiers) An order-sensitive invocation ofClassVisitor.visitInnerClass(String, String, String, int)
.protected org.objectweb.asm.MethodVisitor
onVisitMethod
(int modifiers, String internalName, String descriptor, String genericSignature, String[] exceptionName) An order-sensitive invocation ofClassVisitor.visitMethod(int, String, String, String, String[])
.protected void
onVisitNestHost
(String nestHost) An order-sensitive invocation ofClassVisitor.visitNestHost(String)
.protected void
onVisitNestMember
(String nestMember) An order-sensitive invocation ofClassVisitor.visitNestMember(String)
.protected void
onVisitOuterClass
(String owner, String name, String descriptor) An order-sensitive invocation ofClassVisitor.visitOuterClass(String, String, String)
.protected void
onVisitPermittedSubclass
(String permittedSubclass) An order-sensitive invocation ofClassVisitor#visitPermittedSubclass
.protected org.objectweb.asm.RecordComponentVisitor
onVisitRecordComponent
(String name, String descriptor, String genericSignature) An order-sensitive invocation ofClassVisitor.visitRecordComponent(String, String, String)
.protected org.objectweb.asm.AnnotationVisitor
onVisitTypeAnnotation
(int typeReference, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) An order-sensitive invocation ofClassVisitor.visitTypeAnnotation(int, TypePath, String, boolean)
.protected org.objectweb.asm.MethodVisitor
redefine
(MethodDescription methodDescription, boolean abstractOrigin, int modifiers, String genericSignature) Redefines a given method if this is required by looking up a potential implementation from theTypeWriter.MethodPool
.protected org.objectweb.asm.FieldVisitor
redefine
(TypeWriter.FieldPool.Record record, Object value, int modifiers, String genericSignature) Redefines a field using the given explicit field pool record and default value.protected org.objectweb.asm.RecordComponentVisitor
redefine
(TypeWriter.RecordComponentPool.Record record, String genericSignature) Redefines a record component using the given explicit record component pool record.private int
resolveDeprecationModifiers
(int modifiers) ReturnsOpcodes.ACC_DEPRECATED
if the current class file version only represents deprecated methods using modifiers that are not exposed in the type description API what is true for class files before Java 5 and if the supplied modifiers indicate deprecation.void
visit
(int classFileVersionNumber, int modifiers, String internalName, String genericSignature, String superClassInternalName, String[] interfaceTypeInternalName) Methods inherited from class net.bytebuddy.utility.visitor.MetadataAwareClassVisitor
onVisitAttribute, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitMethod, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitTypeAnnotation
Methods inherited from class org.objectweb.asm.ClassVisitor
getDelegate, visitModule, visitSource
-
Field Details
-
typeInitializer
The type initializer to apply. -
contextRegistry
A context registry to register the lazily created implementation context to. -
writerFlags
private final int writerFlagsThe writer flags being used. -
readerFlags
private final int readerFlagsThe reader flags being used. -
declarableFields
A mapping of fields to write by their unique signature. -
declarableMethods
A mapping of methods to write by their unique signature. -
declarableRecordComponents
A mapping of record components to write by their names. -
nestMembers
A set of internal names of all nest members not yet defined by this type. If this type is not a nest host, this set is empty. -
declaredTypes
A mapping of the internal names of all declared types to their description. -
permittedSubclasses
A list of internal names of permitted subclasses to include. -
methodPool
The method pool to use ornull
if the pool was not yet initialized. -
initializationHandler
@UnknownNull private TypeWriter.Default.ForInlining.WithFullProcessing.InitializationHandler initializationHandlerThe initialization handler to use ornull
if the handler was not yet initialized. -
implementationContext
The implementation context for this class creation ornull
if it was not yet created. -
retainDeprecationModifiers
private boolean retainDeprecationModifierstrue
if the modifiers for deprecation should be retained.
-
-
Constructor Details
-
RedefinitionClassVisitor
protected RedefinitionClassVisitor(org.objectweb.asm.ClassVisitor classVisitor, TypeInitializer typeInitializer, TypeWriter.Default.ForInlining.ContextRegistry contextRegistry, int writerFlags, int readerFlags) Creates a class visitor which is capable of redefining an existent class on the fly.- Parameters:
classVisitor
- The underlying class visitor to which writes are delegated.typeInitializer
- The type initializer to apply.contextRegistry
- A context registry to register the lazily created implementation context to.writerFlags
- The writer flags being used.readerFlags
- The reader flags being used.
-
-
Method Details
-
visit
public void visit(int classFileVersionNumber, int modifiers, String internalName, String genericSignature, String superClassInternalName, String[] interfaceTypeInternalName) - Overrides:
visit
in classorg.objectweb.asm.ClassVisitor
-
onVisitNestHost
Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitNestHost(String)
.- Overrides:
onVisitNestHost
in classMetadataAwareClassVisitor
- Parameters:
nestHost
- The internal name of the nest host.
-
onNestHost
protected void onNestHost()Description copied from class:MetadataAwareClassVisitor
Invoked if the nest host was not visited.- Overrides:
onNestHost
in classMetadataAwareClassVisitor
-
onVisitPermittedSubclass
Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor#visitPermittedSubclass
.- Overrides:
onVisitPermittedSubclass
in classMetadataAwareClassVisitor
- Parameters:
permittedSubclass
- The internal name of the permitted subclass.
-
onVisitOuterClass
protected void onVisitOuterClass(String owner, @MaybeNull String name, @MaybeNull String descriptor) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitOuterClass(String, String, String)
.- Overrides:
onVisitOuterClass
in classMetadataAwareClassVisitor
- Parameters:
owner
- The outer class's internal name.name
- The outer method's name ornull
if it does not exist.descriptor
- The outer method's descriptor ornull
if it does not exist.
-
onOuterType
protected void onOuterType()Description copied from class:MetadataAwareClassVisitor
Invoked if the outer class was not visited.- Overrides:
onOuterType
in classMetadataAwareClassVisitor
-
onAfterAttributes
protected void onAfterAttributes()Description copied from class:MetadataAwareClassVisitor
Invoked if the attribute visitation is about to complete.- Overrides:
onAfterAttributes
in classMetadataAwareClassVisitor
-
onVisitTypeAnnotation
@MaybeNull protected org.objectweb.asm.AnnotationVisitor onVisitTypeAnnotation(int typeReference, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitTypeAnnotation(int, TypePath, String, boolean)
.- Overrides:
onVisitTypeAnnotation
in classMetadataAwareClassVisitor
- Parameters:
typeReference
- The type reference of the type annotation.typePath
- The type path of the type annotation.descriptor
- The descriptor of the annotation type.visible
-true
if the annotation is visible at runtime.- Returns:
- An annotation visitor or
null
if the annotation should be ignored.
-
onVisitAnnotation
@MaybeNull protected org.objectweb.asm.AnnotationVisitor onVisitAnnotation(String descriptor, boolean visible) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitAnnotation(String, boolean)
.- Overrides:
onVisitAnnotation
in classMetadataAwareClassVisitor
- Parameters:
descriptor
- The annotation type's descriptor.visible
-true
if the annotation is visible at runtime.- Returns:
- An annotation visitor or
null
if the annotation should be ignored.
-
onVisitRecordComponent
@MaybeNull protected org.objectweb.asm.RecordComponentVisitor onVisitRecordComponent(String name, String descriptor, @MaybeNull String genericSignature) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitRecordComponent(String, String, String)
.- Overrides:
onVisitRecordComponent
in classMetadataAwareClassVisitor
- Parameters:
name
- The record component's name.descriptor
- The record component's descriptor.genericSignature
- The record component's generic signature ornull
if the record component's type is non-generic.- Returns:
- The record component visitor or
null
if the component should not be visited.
-
redefine
@MaybeNull protected org.objectweb.asm.RecordComponentVisitor redefine(TypeWriter.RecordComponentPool.Record record, @MaybeNull String genericSignature) Redefines a record component using the given explicit record component pool record.- Parameters:
record
- The record component pool record to apply during visitation of the existing record.genericSignature
- The record component's original generic signature which can benull
.- Returns:
- A record component visitor for visiting the existing record component definition.
-
onVisitField
@MaybeNull protected org.objectweb.asm.FieldVisitor onVisitField(int modifiers, String internalName, String descriptor, @MaybeNull String genericSignature, @MaybeNull Object value) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitField(int, String, String, String, Object)
.- Overrides:
onVisitField
in classMetadataAwareClassVisitor
- Parameters:
modifiers
- The field's modifiers.internalName
- The field's internal name.descriptor
- The field type's descriptor.genericSignature
- The field's generic signature ornull
if the field is not generic.value
- The field's default value ornull
if no such value exists.- Returns:
- A field visitor to visit the field or
null
to ignore it.
-
redefine
@MaybeNull protected org.objectweb.asm.FieldVisitor redefine(TypeWriter.FieldPool.Record record, @MaybeNull Object value, int modifiers, @MaybeNull String genericSignature) Redefines a field using the given explicit field pool record and default value.- Parameters:
record
- The field pool value to apply during visitation of the existing field.value
- The default value to write onto the field which might benull
.modifiers
- The original modifiers of the transformed field.genericSignature
- The field's original generic signature which can benull
.- Returns:
- A field visitor for visiting the existing field definition.
-
onVisitMethod
@MaybeNull protected org.objectweb.asm.MethodVisitor onVisitMethod(int modifiers, String internalName, String descriptor, @MaybeNull String genericSignature, @MaybeNull String[] exceptionName) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitMethod(int, String, String, String, String[])
.- Overrides:
onVisitMethod
in classMetadataAwareClassVisitor
- Parameters:
modifiers
- The method's modifiers.internalName
- The method's internal name.descriptor
- The field type's descriptor.genericSignature
- The method's generic signature ornull
if the method is not generic.exceptionName
- The method's declared exceptions ornull
if no exceptions are declared.- Returns:
- A method visitor to visit the method or
null
to ignore it.
-
redefine
@MaybeNull protected org.objectweb.asm.MethodVisitor redefine(MethodDescription methodDescription, boolean abstractOrigin, int modifiers, @MaybeNull String genericSignature) Redefines a given method if this is required by looking up a potential implementation from theTypeWriter.MethodPool
.- Parameters:
methodDescription
- The method being considered for redefinition.abstractOrigin
-true
if the original method is abstract, i.e. there is no implementation to preserve.modifiers
- The original modifiers of the transformed method.genericSignature
- The method's original generic signature which can benull
.- Returns:
- A method visitor which is capable of consuming the original method.
-
onVisitInnerClass
protected void onVisitInnerClass(String internalName, @MaybeNull String outerName, @MaybeNull String innerName, int modifiers) Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitInnerClass(String, String, String, int)
.- Overrides:
onVisitInnerClass
in classMetadataAwareClassVisitor
- Parameters:
internalName
- The internal name of the inner class.outerName
- The internal name of the outer class ornull
for a member class.innerName
- The inner class's simple name ornull
for an anonymous class.modifiers
- The inner class's source code modifiers.
-
onVisitNestMember
Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitNestMember(String)
.- Overrides:
onVisitNestMember
in classMetadataAwareClassVisitor
- Parameters:
nestMember
- The internal name of the nest member.
-
onVisitEnd
protected void onVisitEnd()Description copied from class:MetadataAwareClassVisitor
An order-sensitive invocation ofClassVisitor.visitEnd()
.- Overrides:
onVisitEnd
in classMetadataAwareClassVisitor
-
resolveDeprecationModifiers
private int resolveDeprecationModifiers(int modifiers) ReturnsOpcodes.ACC_DEPRECATED
if the current class file version only represents deprecated methods using modifiers that are not exposed in the type description API what is true for class files before Java 5 and if the supplied modifiers indicate deprecation.- Parameters:
modifiers
- The original modifiers.- Returns:
Opcodes.ACC_DEPRECATED
if the supplied modifiers imply deprecation.
-