Package net.bytebuddy.implementation
Class Implementation.Context.Default
java.lang.Object
net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
net.bytebuddy.implementation.Implementation.Context.Default
- All Implemented Interfaces:
Implementation.Context
,Implementation.Context.ExtractableView
,MethodAccessorFactory
- Enclosing interface:
Implementation.Context
public static class Implementation.Context.Default
extends Implementation.Context.ExtractableView.AbstractBase
A default implementation of an
Implementation.Context.ExtractableView
which serves as its own MethodAccessorFactory
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A base implementation of a method that accesses a property of an instrumented type.protected static class
A description of an accessor method to access another method from outside the instrumented type.protected static class
An implementation of aTypeWriter.MethodPool.Record
for implementing an accessor method.protected static class
A description of a field that stores a cached value.protected static class
An abstract method pool entry that delegates the implementation of a method to itself.static enum
A factory for creating aImplementation.Context.Default
that uses a random suffix for accessors.protected static class
A field cache entry for uniquely identifying a cached field.protected static class
A description of a field getter method.protected static class
An implementation for a field getter.protected static class
A description of a field setter method.protected static class
An implementation for a field setter.Nested classes/interfaces inherited from interface net.bytebuddy.implementation.Implementation.Context
Implementation.Context.Default, Implementation.Context.Disabled, Implementation.Context.ExtractableView, Implementation.Context.FrameGeneration
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.Implementation.Context.ExtractableView
Implementation.Context.ExtractableView.AbstractBase
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.MethodAccessorFactory
MethodAccessorFactory.AccessType, MethodAccessorFactory.Illegal
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The name suffix to be appended to an accessor method.private final ClassFileVersion
The class file version to use for auxiliary classes.private final AuxiliaryType.NamingStrategy
The naming strategy for naming auxiliary types that are registered.private final Map
<AuxiliaryType, DynamicType> A map of registered auxiliary types to their dynamic type representation.static final String
The name prefix to be prepended to a field storing a cached value.private boolean
Iffalse
, the type initializer for this instance was already drained what prohibits the registration of additional cached field values.private final Map
<Implementation.SpecialMethodInvocation, Implementation.Context.Default.DelegationRecord> A mapping of special method invocations to their accessor methods that each invoke their mapped invocation.A map of already registered field caches to their field representation.private final Set
<FieldDescription.InDefinedShape> A set of registered field cache entries.private final Map
<FieldDescription, Implementation.Context.Default.DelegationRecord> The registered getters.private final Map
<FieldDescription, Implementation.Context.Default.DelegationRecord> The registered setters.private final String
The suffix to append to the names of accessor methods.private final TypeInitializer
The type initializer of the created instrumented type.Fields inherited from class net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
classFileVersion, frameGeneration, instrumentedType
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Default
(TypeDescription instrumentedType, ClassFileVersion classFileVersion, AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy, TypeInitializer typeInitializer, ClassFileVersion auxiliaryClassFileVersion, Implementation.Context.FrameGeneration frameGeneration, String suffix) Creates a new default implementation context. -
Method Summary
Modifier and TypeMethodDescriptioncache
(StackManipulation fieldValue, TypeDescription fieldType) Caches a single value by storing it in form of aprivate
,final
andstatic
field.void
drain
(TypeInitializer.Drain drain, org.objectweb.asm.ClassVisitor classVisitor, AnnotationValueFilter.Factory annotationValueFilterFactory) Writes any information that was registered with anImplementation.Context
to the provided class visitor.Returns anyAuxiliaryType
that was registered with thisImplementation.Context
.boolean
Returnstrue
if this implementation context permits the registration of any implicit type initializers.register
(AuxiliaryType auxiliaryType) Registers an auxiliary type as required for the current implementation.registerAccessorFor
(Implementation.SpecialMethodInvocation specialMethodInvocation, MethodAccessorFactory.AccessType accessType) Registers an accessor method for aImplementation.SpecialMethodInvocation
which cannot itself be triggered invoked directly from outside a type.registerGetterFor
(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType) Registers a getter for the givenFieldDescription
which might itself not be accessible from outside the class.registerSetterFor
(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType) Registers a setter for the givenFieldDescription
which might itself not be accessible from outside the class.Methods inherited from class net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
getClassFileVersion, getFrameGeneration, getInstrumentedType
-
Field Details
-
ACCESSOR_METHOD_SUFFIX
The name suffix to be appended to an accessor method.- See Also:
-
FIELD_CACHE_PREFIX
The name prefix to be prepended to a field storing a cached value.- See Also:
-
auxiliaryTypeNamingStrategy
The naming strategy for naming auxiliary types that are registered. -
typeInitializer
The type initializer of the created instrumented type. -
auxiliaryClassFileVersion
The class file version to use for auxiliary classes. -
registeredAccessorMethods
private final Map<Implementation.SpecialMethodInvocation,Implementation.Context.Default.DelegationRecord> registeredAccessorMethodsA mapping of special method invocations to their accessor methods that each invoke their mapped invocation. -
registeredGetters
private final Map<FieldDescription,Implementation.Context.Default.DelegationRecord> registeredGettersThe registered getters. -
registeredSetters
private final Map<FieldDescription,Implementation.Context.Default.DelegationRecord> registeredSettersThe registered setters. -
auxiliaryTypes
A map of registered auxiliary types to their dynamic type representation. -
registeredFieldCacheEntries
private final Map<Implementation.Context.Default.FieldCacheEntry,FieldDescription.InDefinedShape> registeredFieldCacheEntriesA map of already registered field caches to their field representation. -
registeredFieldCacheFields
A set of registered field cache entries. -
suffix
The suffix to append to the names of accessor methods. -
fieldCacheCanAppendEntries
private boolean fieldCacheCanAppendEntriesIffalse
, the type initializer for this instance was already drained what prohibits the registration of additional cached field values.
-
-
Constructor Details
-
Default
protected Default(TypeDescription instrumentedType, ClassFileVersion classFileVersion, AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy, TypeInitializer typeInitializer, ClassFileVersion auxiliaryClassFileVersion, Implementation.Context.FrameGeneration frameGeneration, String suffix) Creates a new default implementation context.- Parameters:
instrumentedType
- The description of the type that is currently subject of creation.classFileVersion
- The class file version of the created class.auxiliaryTypeNamingStrategy
- The naming strategy for naming an auxiliary type.typeInitializer
- The type initializer of the created instrumented type.auxiliaryClassFileVersion
- The class file version to use for auxiliary classes.frameGeneration
- Determines the frame generation to be applied.suffix
- The suffix to append to the names of accessor methods.
-
-
Method Details
-
isEnabled
public boolean isEnabled()Returnstrue
if this implementation context permits the registration of any implicit type initializers.- Returns:
true
if this implementation context permits the registration of any implicit type initializers.
-
registerAccessorFor
public MethodDescription.InDefinedShape registerAccessorFor(Implementation.SpecialMethodInvocation specialMethodInvocation, MethodAccessorFactory.AccessType accessType) Registers an accessor method for aImplementation.SpecialMethodInvocation
which cannot itself be triggered invoked directly from outside a type. The method is registered on the instrumented type with package-private visibility, similarly to a Java compiler's accessor methods.- Parameters:
specialMethodInvocation
- The special method invocation.accessType
- The required access type.- Returns:
- The accessor method for invoking the special method invocation.
-
registerGetterFor
public MethodDescription.InDefinedShape registerGetterFor(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType) Registers a getter for the givenFieldDescription
which might itself not be accessible from outside the class. The returned getter method defines the field type as its return type, does not take any arguments and is of package-private visibility, similarly to the Java compiler's accessor methods. If the field isstatic
, this accessor method is alsostatic
.- Parameters:
fieldDescription
- The field which is to be accessed.accessType
- The required access type.- Returns:
- A getter method for the given field.
-
registerSetterFor
public MethodDescription.InDefinedShape registerSetterFor(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType) Registers a setter for the givenFieldDescription
which might itself not be accessible from outside the class. The returned setter method defines the field type as its only argument type, returnsvoid
and is of package-private visibility, similarly to the Java compiler's accessor methods. If the field isstatic
, this accessor method is alsostatic
.- Parameters:
fieldDescription
- The field which is to be accessed.accessType
- The required access type.- Returns:
- A setter method for the given field.
-
register
Registers an auxiliary type as required for the current implementation. Registering a type will cause the creation of this type even if this type is not effectively used for the current implementation.- Parameters:
auxiliaryType
- The auxiliary type that is required for the current implementation.- Returns:
- A description of the registered auxiliary type.
-
getAuxiliaryTypes
Returns anyAuxiliaryType
that was registered with thisImplementation.Context
.- Returns:
- A list of all manifested registered auxiliary types.
-
cache
public FieldDescription.InDefinedShape cache(StackManipulation fieldValue, TypeDescription fieldType) Caches a single value by storing it in form of aprivate
,final
andstatic
field. By caching values, expensive instance creations can be avoided and object identity can be preserved. The field is initiated in a generated class's static initializer.- Parameters:
fieldValue
- A stack manipulation for creating the value that is to be cached in astatic
field. After executing the stack manipulation, exactly one value must be put onto the operand stack which is assignable to the givenfieldType
.fieldType
- The type of the field for storing the cached value. This field's type determines the value that is put onto the operand stack by this method's returned stack manipulation.- Returns:
- A description of a field that was defined on the instrumented type which contains the given value.
-
drain
public void drain(TypeInitializer.Drain drain, org.objectweb.asm.ClassVisitor classVisitor, AnnotationValueFilter.Factory annotationValueFilterFactory) Writes any information that was registered with anImplementation.Context
to the provided class visitor. This contains any fields for value caching, any accessor method and it writes the type initializer. The type initializer must therefore never be written manually.- Parameters:
drain
- The drain to write the type initializer to.classVisitor
- The class visitor to which the extractable view is to be written.annotationValueFilterFactory
- The annotation value filter factory to apply when writing annotation.
-