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 Classes Modifier and Type Class Description protected classTypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor.AttributeObtainingFieldVisitorA field visitor that obtains all attributes and annotations of a field that is found in the class file but that discards all code.protected classTypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor.AttributeObtainingMethodVisitorA method visitor that obtains all attributes and annotations of a method that is found in the class file but that discards all code.protected classTypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor.AttributeObtainingRecordComponentVisitorA 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 classTypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor.CodePreservingMethodVisitorA 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.protected classTypeWriter.Default.ForInlining.WithFullProcessing.RedefinitionClassVisitor.DeduplicatingClassVisitorA class visitor that deduplicates fields and methods, mostly when access bridge methods are previously declared, but incomplete.
-
Field Summary
Fields Modifier and Type Field Description private TypeWriter.Default.ForInlining.ContextRegistrycontextRegistryA context registry to register the lazily created implementation context to.private java.util.LinkedHashMap<TypeWriter.Default.SignatureKey,FieldDescription>declarableFieldsA mapping of fields to write by their unique signature.private java.util.LinkedHashMap<TypeWriter.Default.SignatureKey,MethodDescription>declarableMethodsA mapping of methods to write by their unique signature.private java.util.LinkedHashMap<java.lang.String,RecordComponentDescription>declarableRecordComponentsA mapping of record components to write by their names.private java.util.LinkedHashMap<java.lang.String,TypeDescription>declaredTypesA mapping of the internal names of all declared types to their description.private java.util.Set<TypeWriter.Default.SignatureKey>fieldKeysA set of keys for fields that were previosuly visited.private Implementation.Context.ExtractableViewimplementationContextThe implementation context for this class creation ornullif it was not yet created.private TypeWriter.Default.ForInlining.WithFullProcessing.InitializationHandlerinitializationHandlerThe initialization handler to use ornullif the handler was not yet initialized.private TypeWriter.MethodPoolmethodPoolThe method pool to use ornullif the pool was not yet initialized.private java.util.Set<TypeWriter.Default.SignatureKey>methodsKeysA set of keys for methods that were previosuly visited.private java.util.Set<java.lang.String>nestMembersA set of internal names of all nest members not yet defined by this type.private java.util.Set<java.lang.String>permittedSubclassesA list of internal names of permitted subclasses to include.private intreaderFlagsThe reader flags being used.private booleanretainDeprecationModifierstrueif the modifiers for deprecation should be retained.private TypeInitializertypeInitializerThe type initializer to apply.private intwriterFlagsThe writer flags being used.
-
Constructor Summary
Constructors Modifier Constructor Description protectedRedefinitionClassVisitor(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidonAfterAttributes()Invoked if the attribute visitation is about to complete.protected voidonModule()Invoked if the module was not visited.protected voidonNestHost()Invoked if the nest host was not visited.protected voidonOuterType()Invoked if the outer class was not visited.protected org.objectweb.asm.AnnotationVisitoronVisitAnnotation(java.lang.String descriptor, boolean visible)An order-sensitive invocation ofClassVisitor.visitAnnotation(String, boolean).protected voidonVisitEnd()An order-sensitive invocation ofClassVisitor.visitEnd().protected org.objectweb.asm.FieldVisitoronVisitField(int modifiers, java.lang.String internalName, java.lang.String descriptor, java.lang.String genericSignature, java.lang.Object value)An order-sensitive invocation ofClassVisitor.visitField(int, String, String, String, Object).protected voidonVisitInnerClass(java.lang.String internalName, java.lang.String outerName, java.lang.String innerName, int modifiers)An order-sensitive invocation ofClassVisitor.visitInnerClass(String, String, String, int).protected org.objectweb.asm.MethodVisitoronVisitMethod(int modifiers, java.lang.String internalName, java.lang.String descriptor, java.lang.String genericSignature, java.lang.String[] exceptionName)An order-sensitive invocation ofClassVisitor.visitMethod(int, String, String, String, String[]).protected org.objectweb.asm.ModuleVisitoronVisitModule(java.lang.String name, int modifiers, java.lang.String version)An order-sensitive invocation ogClassVisitor.visitModule(String, int, String).protected voidonVisitNestHost(java.lang.String nestHost)An order-sensitive invocation ofClassVisitor.visitNestHost(String).protected voidonVisitNestMember(java.lang.String nestMember)An order-sensitive invocation ofClassVisitor.visitNestMember(String).protected voidonVisitOuterClass(java.lang.String owner, java.lang.String name, java.lang.String descriptor)An order-sensitive invocation ofClassVisitor.visitOuterClass(String, String, String).protected voidonVisitPermittedSubclass(java.lang.String permittedSubclass)An order-sensitive invocation ofClassVisitor#visitPermittedSubclass.protected org.objectweb.asm.RecordComponentVisitoronVisitRecordComponent(java.lang.String name, java.lang.String descriptor, java.lang.String genericSignature)An order-sensitive invocation ofClassVisitor.visitRecordComponent(String, String, String).protected org.objectweb.asm.AnnotationVisitoronVisitTypeAnnotation(int typeReference, org.objectweb.asm.TypePath typePath, java.lang.String descriptor, boolean visible)An order-sensitive invocation ofClassVisitor.visitTypeAnnotation(int, TypePath, String, boolean).protected org.objectweb.asm.MethodVisitorredefine(MethodDescription methodDescription, boolean abstractOrigin, int modifiers, java.lang.String genericSignature)Redefines a given method if this is required by looking up a potential implementation from theTypeWriter.MethodPool.protected org.objectweb.asm.FieldVisitorredefine(TypeWriter.FieldPool.Record record, java.lang.Object value, int modifiers, java.lang.String genericSignature)Redefines a field using the given explicit field pool record and default value.protected org.objectweb.asm.RecordComponentVisitorredefine(TypeWriter.RecordComponentPool.Record record, java.lang.String genericSignature)Redefines a record component using the given explicit record component pool record.private intresolveDeprecationModifiers(int modifiers)ReturnsOpcodes.ACC_DEPRECATEDif 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.voidvisit(int classFileVersionNumber, int modifiers, java.lang.String internalName, java.lang.String genericSignature, java.lang.String superClassInternalName, java.lang.String[] interfaceTypeInternalName)-
Methods inherited from class net.bytebuddy.utility.visitor.MetadataAwareClassVisitor
onSource, onVisitAttribute, onVisitSource, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitMethod, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitSource, visitTypeAnnotation
-
-
-
-
Field Detail
-
typeInitializer
private final TypeInitializer typeInitializer
The type initializer to apply.
-
contextRegistry
private final TypeWriter.Default.ForInlining.ContextRegistry contextRegistry
A context registry to register the lazily created implementation context to.
-
writerFlags
private final int writerFlags
The writer flags being used.
-
readerFlags
private final int readerFlags
The reader flags being used.
-
declarableFields
private final java.util.LinkedHashMap<TypeWriter.Default.SignatureKey,FieldDescription> declarableFields
A mapping of fields to write by their unique signature.
-
declarableMethods
private final java.util.LinkedHashMap<TypeWriter.Default.SignatureKey,MethodDescription> declarableMethods
A mapping of methods to write by their unique signature.
-
declarableRecordComponents
private final java.util.LinkedHashMap<java.lang.String,RecordComponentDescription> declarableRecordComponents
A mapping of record components to write by their names.
-
nestMembers
private final java.util.Set<java.lang.String> 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
private final java.util.LinkedHashMap<java.lang.String,TypeDescription> declaredTypes
A mapping of the internal names of all declared types to their description.
-
permittedSubclasses
@MaybeNull private final java.util.Set<java.lang.String> permittedSubclasses
A list of internal names of permitted subclasses to include.
-
methodPool
@UnknownNull private TypeWriter.MethodPool methodPool
The method pool to use ornullif the pool was not yet initialized.
-
initializationHandler
@UnknownNull private TypeWriter.Default.ForInlining.WithFullProcessing.InitializationHandler initializationHandler
The initialization handler to use ornullif the handler was not yet initialized.
-
implementationContext
@UnknownNull private Implementation.Context.ExtractableView implementationContext
The implementation context for this class creation ornullif it was not yet created.
-
retainDeprecationModifiers
private boolean retainDeprecationModifiers
trueif the modifiers for deprecation should be retained.
-
fieldKeys
private final java.util.Set<TypeWriter.Default.SignatureKey> fieldKeys
A set of keys for fields that were previosuly visited.
-
methodsKeys
private final java.util.Set<TypeWriter.Default.SignatureKey> methodsKeys
A set of keys for methods that were previosuly visited.
-
-
Constructor Detail
-
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 Detail
-
visit
public void visit(int classFileVersionNumber, int modifiers, java.lang.String internalName, java.lang.String genericSignature, java.lang.String superClassInternalName, java.lang.String[] interfaceTypeInternalName)- Overrides:
visitin classorg.objectweb.asm.ClassVisitor
-
onVisitModule
@MaybeNull protected org.objectweb.asm.ModuleVisitor onVisitModule(java.lang.String name, int modifiers, @MaybeNull java.lang.String version)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ogClassVisitor.visitModule(String, int, String).- Overrides:
onVisitModulein classMetadataAwareClassVisitor- Parameters:
name- The name of the modulemodifiers- The modifiers of the module.version- The module version ornullif not available.- Returns:
- A visitor for the module information or
nullif skipped.
-
onModule
protected void onModule()
Description copied from class:MetadataAwareClassVisitorInvoked if the module was not visited.- Overrides:
onModulein classMetadataAwareClassVisitor
-
onVisitNestHost
protected void onVisitNestHost(java.lang.String nestHost)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitNestHost(String).- Overrides:
onVisitNestHostin classMetadataAwareClassVisitor- Parameters:
nestHost- The internal name of the nest host.
-
onNestHost
protected void onNestHost()
Description copied from class:MetadataAwareClassVisitorInvoked if the nest host was not visited.- Overrides:
onNestHostin classMetadataAwareClassVisitor
-
onVisitPermittedSubclass
protected void onVisitPermittedSubclass(java.lang.String permittedSubclass)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor#visitPermittedSubclass.- Overrides:
onVisitPermittedSubclassin classMetadataAwareClassVisitor- Parameters:
permittedSubclass- The internal name of the permitted subclass.
-
onVisitOuterClass
protected void onVisitOuterClass(java.lang.String owner, @MaybeNull java.lang.String name, @MaybeNull java.lang.String descriptor)Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitOuterClass(String, String, String).- Overrides:
onVisitOuterClassin classMetadataAwareClassVisitor- Parameters:
owner- The outer class's internal name.name- The outer method's name ornullif it does not exist.descriptor- The outer method's descriptor ornullif it does not exist.
-
onOuterType
protected void onOuterType()
Description copied from class:MetadataAwareClassVisitorInvoked if the outer class was not visited.- Overrides:
onOuterTypein classMetadataAwareClassVisitor
-
onAfterAttributes
protected void onAfterAttributes()
Description copied from class:MetadataAwareClassVisitorInvoked if the attribute visitation is about to complete.- Overrides:
onAfterAttributesin classMetadataAwareClassVisitor
-
onVisitTypeAnnotation
@MaybeNull protected org.objectweb.asm.AnnotationVisitor onVisitTypeAnnotation(int typeReference, org.objectweb.asm.TypePath typePath, java.lang.String descriptor, boolean visible)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitTypeAnnotation(int, TypePath, String, boolean).- Overrides:
onVisitTypeAnnotationin 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-trueif the annotation is visible at runtime.- Returns:
- An annotation visitor or
nullif the annotation should be ignored.
-
onVisitAnnotation
@MaybeNull protected org.objectweb.asm.AnnotationVisitor onVisitAnnotation(java.lang.String descriptor, boolean visible)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitAnnotation(String, boolean).- Overrides:
onVisitAnnotationin classMetadataAwareClassVisitor- Parameters:
descriptor- The annotation type's descriptor.visible-trueif the annotation is visible at runtime.- Returns:
- An annotation visitor or
nullif the annotation should be ignored.
-
onVisitRecordComponent
@MaybeNull protected org.objectweb.asm.RecordComponentVisitor onVisitRecordComponent(java.lang.String name, java.lang.String descriptor, @MaybeNull java.lang.String genericSignature)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitRecordComponent(String, String, String).- Overrides:
onVisitRecordComponentin classMetadataAwareClassVisitor- Parameters:
name- The record component's name.descriptor- The record component's descriptor.genericSignature- The record component's generic signature ornullif the record component's type is non-generic.- Returns:
- The record component visitor or
nullif the component should not be visited.
-
redefine
@MaybeNull protected org.objectweb.asm.RecordComponentVisitor redefine(TypeWriter.RecordComponentPool.Record record, @MaybeNull java.lang.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, java.lang.String internalName, java.lang.String descriptor, @MaybeNull java.lang.String genericSignature, @MaybeNull java.lang.Object value)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitField(int, String, String, String, Object).- Overrides:
onVisitFieldin 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 ornullif the field is not generic.value- The field's default value ornullif no such value exists.- Returns:
- A field visitor to visit the field or
nullto ignore it.
-
redefine
@MaybeNull protected org.objectweb.asm.FieldVisitor redefine(TypeWriter.FieldPool.Record record, @MaybeNull java.lang.Object value, int modifiers, @MaybeNull java.lang.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, java.lang.String internalName, java.lang.String descriptor, @MaybeNull java.lang.String genericSignature, @MaybeNull java.lang.String[] exceptionName)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitMethod(int, String, String, String, String[]).- Overrides:
onVisitMethodin 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 ornullif the method is not generic.exceptionName- The method's declared exceptions ornullif no exceptions are declared.- Returns:
- A method visitor to visit the method or
nullto ignore it.
-
redefine
@MaybeNull protected org.objectweb.asm.MethodVisitor redefine(MethodDescription methodDescription, boolean abstractOrigin, int modifiers, @MaybeNull java.lang.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-trueif 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(java.lang.String internalName, @MaybeNull java.lang.String outerName, @MaybeNull java.lang.String innerName, int modifiers)Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitInnerClass(String, String, String, int).- Overrides:
onVisitInnerClassin classMetadataAwareClassVisitor- Parameters:
internalName- The internal name of the inner class.outerName- The internal name of the outer class ornullfor a member class.innerName- The inner class's simple name ornullfor an anonymous class.modifiers- The inner class's source code modifiers.
-
onVisitNestMember
protected void onVisitNestMember(java.lang.String nestMember)
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitNestMember(String).- Overrides:
onVisitNestMemberin classMetadataAwareClassVisitor- Parameters:
nestMember- The internal name of the nest member.
-
onVisitEnd
protected void onVisitEnd()
Description copied from class:MetadataAwareClassVisitorAn order-sensitive invocation ofClassVisitor.visitEnd().- Overrides:
onVisitEndin classMetadataAwareClassVisitor
-
resolveDeprecationModifiers
private int resolveDeprecationModifiers(int modifiers)
ReturnsOpcodes.ACC_DEPRECATEDif 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_DEPRECATEDif the supplied modifiers imply deprecation.
-
-