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 anImplementation.Context.ExtractableView
which serves as its ownMethodAccessorFactory
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Implementation.Context.Default.AbstractPropertyAccessorMethod
A base implementation of a method that accesses a property of an instrumented type.protected static class
Implementation.Context.Default.AccessorMethod
A description of an accessor method to access another method from outside the instrumented type.protected static class
Implementation.Context.Default.AccessorMethodDelegation
An implementation of aTypeWriter.MethodPool.Record
for implementing an accessor method.protected static class
Implementation.Context.Default.CacheValueField
A description of a field that stores a cached value.protected static class
Implementation.Context.Default.DelegationRecord
An abstract method pool entry that delegates the implementation of a method to itself.static class
Implementation.Context.Default.Factory
A factory for creating aImplementation.Context.Default
.protected static class
Implementation.Context.Default.FieldCacheEntry
A field cache entry for uniquely identifying a cached field.protected static class
Implementation.Context.Default.FieldGetter
A description of a field getter method.protected static class
Implementation.Context.Default.FieldGetterDelegation
An implementation for a field getter.protected static class
Implementation.Context.Default.FieldSetter
A description of a field setter method.protected static class
Implementation.Context.Default.FieldSetterDelegation
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
-
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
Fields Modifier and Type Field Description static java.lang.String
ACCESSOR_METHOD_SUFFIX
The name suffix to be appended to an accessor method.private ClassFileVersion
auxiliaryClassFileVersion
The class file version to use for auxiliary classes.private AuxiliaryType.NamingStrategy
auxiliaryTypeNamingStrategy
The naming strategy for naming auxiliary types that are registered.private java.util.Map<AuxiliaryType,DynamicType>
auxiliaryTypes
A map of registered auxiliary types to their dynamic type representation.static java.lang.String
FIELD_CACHE_PREFIX
The name prefix to be prepended to a field storing a cached value.private boolean
fieldCacheCanAppendEntries
Iffalse
, the type initializer for this instance was already drained what prohibits the registration of additional cached field values.private java.util.Map<Implementation.SpecialMethodInvocation,Implementation.Context.Default.DelegationRecord>
registeredAccessorMethods
A mapping of special method invocations to their accessor methods that each invoke their mapped invocation.private java.util.Map<Implementation.Context.Default.FieldCacheEntry,FieldDescription.InDefinedShape>
registeredFieldCacheEntries
A map of already registered field caches to their field representation.private java.util.Set<FieldDescription.InDefinedShape>
registeredFieldCacheFields
A set of registered field cache entries.private java.util.Map<FieldDescription,Implementation.Context.Default.DelegationRecord>
registeredGetters
The registered getters.private java.util.Map<FieldDescription,Implementation.Context.Default.DelegationRecord>
registeredSetters
The registered setters.private java.lang.String
suffix
A random suffix to append to the names of accessor methods.private TypeInitializer
typeInitializer
The type initializer of the created instrumented type.-
Fields inherited from class net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
classFileVersion, instrumentedType
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Default(TypeDescription instrumentedType, ClassFileVersion classFileVersion, AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy, TypeInitializer typeInitializer, ClassFileVersion auxiliaryClassFileVersion)
Creates a new default implementation context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FieldDescription.InDefinedShape
cache(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.java.util.List<DynamicType>
getAuxiliaryTypes()
Returns anyAuxiliaryType
that was registered with thisImplementation.Context
.boolean
isEnabled()
Returnstrue
if this implementation context permits the registration of any implicit type initializers.TypeDescription
register(AuxiliaryType auxiliaryType)
Registers an auxiliary type as required for the current implementation.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.MethodDescription.InDefinedShape
registerGetterFor(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType)
Registers a getter for the givenFieldDescription
which might itself not be accessible from outside the class.MethodDescription.InDefinedShape
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, getInstrumentedType
-
-
-
-
Field Detail
-
ACCESSOR_METHOD_SUFFIX
public static final java.lang.String ACCESSOR_METHOD_SUFFIX
The name suffix to be appended to an accessor method.- See Also:
- Constant Field Values
-
FIELD_CACHE_PREFIX
public static final java.lang.String FIELD_CACHE_PREFIX
The name prefix to be prepended to a field storing a cached value.- See Also:
- Constant Field Values
-
auxiliaryTypeNamingStrategy
private final AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy
The naming strategy for naming auxiliary types that are registered.
-
typeInitializer
private final TypeInitializer typeInitializer
The type initializer of the created instrumented type.
-
auxiliaryClassFileVersion
private final ClassFileVersion auxiliaryClassFileVersion
The class file version to use for auxiliary classes.
-
registeredAccessorMethods
private final java.util.Map<Implementation.SpecialMethodInvocation,Implementation.Context.Default.DelegationRecord> registeredAccessorMethods
A mapping of special method invocations to their accessor methods that each invoke their mapped invocation.
-
registeredGetters
private final java.util.Map<FieldDescription,Implementation.Context.Default.DelegationRecord> registeredGetters
The registered getters.
-
registeredSetters
private final java.util.Map<FieldDescription,Implementation.Context.Default.DelegationRecord> registeredSetters
The registered setters.
-
auxiliaryTypes
private final java.util.Map<AuxiliaryType,DynamicType> auxiliaryTypes
A map of registered auxiliary types to their dynamic type representation.
-
registeredFieldCacheEntries
private final java.util.Map<Implementation.Context.Default.FieldCacheEntry,FieldDescription.InDefinedShape> registeredFieldCacheEntries
A map of already registered field caches to their field representation.
-
registeredFieldCacheFields
private final java.util.Set<FieldDescription.InDefinedShape> registeredFieldCacheFields
A set of registered field cache entries.
-
suffix
private final java.lang.String suffix
A random suffix to append to the names of accessor methods.
-
fieldCacheCanAppendEntries
private boolean fieldCacheCanAppendEntries
Iffalse
, the type initializer for this instance was already drained what prohibits the registration of additional cached field values.
-
-
Constructor Detail
-
Default
protected Default(TypeDescription instrumentedType, ClassFileVersion classFileVersion, AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy, TypeInitializer typeInitializer, ClassFileVersion auxiliaryClassFileVersion)
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.
-
-
Method Detail
-
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
public TypeDescription register(AuxiliaryType auxiliaryType)
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
public java.util.List<DynamicType> 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.
-
-