Package net.bytebuddy.implementation
Class Implementation.Context.Disabled
- java.lang.Object
-
- net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
-
- net.bytebuddy.implementation.Implementation.Context.Disabled
-
- All Implemented Interfaces:
Implementation.Context
,Implementation.Context.ExtractableView
,MethodAccessorFactory
- Enclosing interface:
- Implementation.Context
public static class Implementation.Context.Disabled extends Implementation.Context.ExtractableView.AbstractBase
An implementation context that does not allow for any injections into the static initializer block. This can be useful when redefining a class when it is not allowed to add methods to a class what is an implicit requirement when copying the static initializer block into another method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Implementation.Context.Disabled.Factory
A factory for creating aImplementation.Context.Disabled
.-
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 inherited from class net.bytebuddy.implementation.Implementation.Context.ExtractableView.AbstractBase
classFileVersion, instrumentedType
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Disabled(TypeDescription instrumentedType, ClassFileVersion classFileVersion)
Creates a new disabled 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
-
-
-
-
Constructor Detail
-
Disabled
protected Disabled(TypeDescription instrumentedType, ClassFileVersion classFileVersion)
Creates a new disabled implementation context.- Parameters:
instrumentedType
- The instrumented type.classFileVersion
- The class file version to create the class in.
-
-
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.
-
getAuxiliaryTypes
public java.util.List<DynamicType> getAuxiliaryTypes()
Returns anyAuxiliaryType
that was registered with thisImplementation.Context
.- Returns:
- A list of all manifested registered auxiliary types.
-
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.
-
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.
-
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.
-
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.
-
-