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.ExtractableViewwhich serves as its ownMethodAccessorFactory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classImplementation.Context.Default.AbstractPropertyAccessorMethodA base implementation of a method that accesses a property of an instrumented type.protected static classImplementation.Context.Default.AccessorMethodA description of an accessor method to access another method from outside the instrumented type.protected static classImplementation.Context.Default.AccessorMethodDelegationAn implementation of aTypeWriter.MethodPool.Recordfor implementing an accessor method.protected static classImplementation.Context.Default.CacheValueFieldA description of a field that stores a cached value.protected static classImplementation.Context.Default.DelegationRecordAn abstract method pool entry that delegates the implementation of a method to itself.static classImplementation.Context.Default.FactoryA factory for creating aImplementation.Context.Defaultthat uses a random suffix for accessors.protected static classImplementation.Context.Default.FieldCacheEntryA field cache entry for uniquely identifying a cached field.protected static classImplementation.Context.Default.FieldGetterA description of a field getter method.protected static classImplementation.Context.Default.FieldGetterDelegationAn implementation for a field getter.protected static classImplementation.Context.Default.FieldSetterA description of a field setter method.protected static classImplementation.Context.Default.FieldSetterDelegationAn 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
Fields Modifier and Type Field Description static java.lang.StringACCESSOR_METHOD_SUFFIXThe name suffix to be appended to an accessor method.private ClassFileVersionauxiliaryClassFileVersionThe class file version to use for auxiliary classes.private AuxiliaryType.NamingStrategyauxiliaryTypeNamingStrategyThe naming strategy for naming auxiliary types that are registered.private java.util.Map<AuxiliaryType,DynamicType>auxiliaryTypesA map of registered auxiliary types to their dynamic type representation.static java.lang.StringFIELD_CACHE_PREFIXThe name prefix to be prepended to a field storing a cached value.private booleanfieldCacheCanAppendEntriesIffalse, 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>registeredAccessorMethodsA 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>registeredFieldCacheEntriesA map of already registered field caches to their field representation.private java.util.Set<FieldDescription.InDefinedShape>registeredFieldCacheFieldsA set of registered field cache entries.private java.util.Map<FieldDescription,Implementation.Context.Default.DelegationRecord>registeredGettersThe registered getters.private java.util.Map<FieldDescription,Implementation.Context.Default.DelegationRecord>registeredSettersThe registered setters.private java.lang.StringsuffixThe suffix to append to the names of accessor methods.private TypeInitializertypeInitializerThe type initializer of the created instrumented type.-
Fields inherited from class net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
classFileVersion, frameGeneration, instrumentedType
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDefault(TypeDescription instrumentedType, ClassFileVersion classFileVersion, AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy, TypeInitializer typeInitializer, ClassFileVersion auxiliaryClassFileVersion, Implementation.Context.FrameGeneration frameGeneration, java.lang.String suffix)Creates a new default implementation context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FieldDescription.InDefinedShapecache(StackManipulation fieldValue, TypeDescription fieldType)Caches a single value by storing it in form of aprivate,finalandstaticfield.voiddrain(TypeInitializer.Drain drain, org.objectweb.asm.ClassVisitor classVisitor, AnnotationValueFilter.Factory annotationValueFilterFactory)Writes any information that was registered with anImplementation.Contextto the provided class visitor.java.util.List<DynamicType>getAuxiliaryTypes()Returns anyAuxiliaryTypethat was registered with thisImplementation.Context.booleanisEnabled()Returnstrueif this implementation context permits the registration of any implicit type initializers.TypeDescriptionregister(AuxiliaryType auxiliaryType)Registers an auxiliary type as required for the current implementation.MethodDescription.InDefinedShaperegisterAccessorFor(Implementation.SpecialMethodInvocation specialMethodInvocation, MethodAccessorFactory.AccessType accessType)Registers an accessor method for aImplementation.SpecialMethodInvocationwhich cannot itself be triggered invoked directly from outside a type.MethodDescription.InDefinedShaperegisterGetterFor(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType)Registers a getter for the givenFieldDescriptionwhich might itself not be accessible from outside the class.MethodDescription.InDefinedShaperegisterSetterFor(FieldDescription fieldDescription, MethodAccessorFactory.AccessType accessType)Registers a setter for the givenFieldDescriptionwhich might itself not be accessible from outside the class.-
Methods inherited from class net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
getClassFileVersion, getFrameGeneration, 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
The 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, Implementation.Context.FrameGeneration frameGeneration, java.lang.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 Detail
-
isEnabled
public boolean isEnabled()
Returnstrueif this implementation context permits the registration of any implicit type initializers.- Returns:
trueif 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.SpecialMethodInvocationwhich 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 givenFieldDescriptionwhich 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 givenFieldDescriptionwhich might itself not be accessible from outside the class. The returned setter method defines the field type as its only argument type, returnsvoidand 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 anyAuxiliaryTypethat 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,finalandstaticfield. 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 astaticfield. 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.Contextto 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.
-
-