Package net.bytebuddy.implementation
Class FieldAccessor
- java.lang.Object
-
- net.bytebuddy.implementation.FieldAccessor
-
- All Implemented Interfaces:
InstrumentedType.Prepareable,Implementation
- Direct Known Subclasses:
FieldAccessor.ForImplicitProperty,FieldAccessor.ForSetter
@Enhance public abstract class FieldAccessor extends java.lang.Object implements Implementation
Defines a method to access a given field by following the Java bean conventions for getters and setters:
- Getter: A method named
getFoo()will be instrumented to read and return the value of a fieldfooor another field if one was specified explicitly. If a property is of typeBooleanorboolean, the nameisFoo()is also permitted. - Setter: A method named
setFoo(value)will be instrumented to write the given argumentvalueto a fieldfooor to another field if one was specified explicitly.
Field accessors always implement a getter if a non-
voidvalue is returned from a method and attempt to define a setter otherwise. If a field accessor is not explicitly defined as a setter viaFieldAccessor.PropertyConfigurable, an instrumented method must define exactly one parameter. Using the latter API, an explicit parameter index can be defined and a return value can be specified explicitly whenvoidis not returned.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFieldAccessor.AssignerConfigurableA field accessor that can be configured to use a given assigner and runtime type use configuration.protected static interfaceFieldAccessor.FieldLocationA field location represents an identified field description which depends on the instrumented type and method.static interfaceFieldAccessor.FieldNameExtractorA field name extractor is responsible for determining a field name to a method that is implemented to access this method.protected static classFieldAccessor.ForImplicitPropertyA field accessor for an implicit property where a getter or setter property is inferred from the signature.protected static classFieldAccessor.ForSetter<T>A field accessor for a field setter.static interfaceFieldAccessor.OwnerTypeLocatableA field accessor that can be configured to locate a field in a specific manner.static interfaceFieldAccessor.PropertyConfigurableA field accessor that allows to define the access to be a field write of a given argument.-
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.Implementation
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable
InstrumentedType.Prepareable.NoOp
-
-
Field Summary
Fields Modifier and Type Field Description protected AssignerassignerThe assigner to use.protected FieldAccessor.FieldLocationfieldLocationThe field's location.protected Assigner.TypingtypingIndicates if dynamic type castings should be attempted for incompatible assignments.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFieldAccessor(FieldAccessor.FieldLocation fieldLocation, Assigner assigner, Assigner.Typing typing)Creates a new field accessor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldAccessor.AssignerConfigurableof(java.lang.reflect.Field field)Defines a field accessor where the specified field is accessed.static FieldAccessor.OwnerTypeLocatableof(java.util.List<? extends FieldAccessor.FieldNameExtractor> fieldNameExtractors)Defines a custom strategy for determining the field that is accessed by this field accessor.static FieldAccessor.AssignerConfigurableof(FieldDescription fieldDescription)Defines a field accessor where the specified field is accessed.static FieldAccessor.OwnerTypeLocatableof(FieldAccessor.FieldNameExtractor fieldNameExtractor)Defines a custom strategy for determining the field that is accessed by this field accessor.static FieldAccessor.OwnerTypeLocatableof(FieldAccessor.FieldNameExtractor... fieldNameExtractor)Defines a custom strategy for determining the field that is accessed by this field accessor.static FieldAccessor.OwnerTypeLocatableofBeanProperty()Defines a field accessor where any access is targeted to a field that matches the methods name with the Java specification for bean properties, i.e.static FieldAccessor.OwnerTypeLocatableofField(java.lang.String name)Defines a field accessor where any access is targeted to a field namedname.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.bytebuddy.implementation.Implementation
appender
-
Methods inherited from interface net.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable
prepare
-
-
-
-
Field Detail
-
fieldLocation
protected final FieldAccessor.FieldLocation fieldLocation
The field's location.
-
assigner
protected final Assigner assigner
The assigner to use.
-
typing
protected final Assigner.Typing typing
Indicates if dynamic type castings should be attempted for incompatible assignments.
-
-
Constructor Detail
-
FieldAccessor
protected FieldAccessor(FieldAccessor.FieldLocation fieldLocation, Assigner assigner, Assigner.Typing typing)
Creates a new field accessor.- Parameters:
fieldLocation- The field's location.assigner- The assigner to use.typing- Indicates if dynamic type castings should be attempted for incompatible assignments.
-
-
Method Detail
-
ofField
public static FieldAccessor.OwnerTypeLocatable ofField(java.lang.String name)
Defines a field accessor where any access is targeted to a field namedname.- Parameters:
name- The name of the field to be accessed.- Returns:
- A field accessor for a field of a given name.
-
ofBeanProperty
public static FieldAccessor.OwnerTypeLocatable ofBeanProperty()
Defines a field accessor where any access is targeted to a field that matches the methods name with the Java specification for bean properties, i.e. a methodgetFooorsetFoo(value)will either read or write a field namedfoo.- Returns:
- A field accessor that follows the Java naming conventions for bean properties.
-
of
public static FieldAccessor.OwnerTypeLocatable of(FieldAccessor.FieldNameExtractor fieldNameExtractor)
Defines a custom strategy for determining the field that is accessed by this field accessor.- Parameters:
fieldNameExtractor- The field name extractor to use.- Returns:
- A field accessor using the given field name extractor.
-
of
public static FieldAccessor.OwnerTypeLocatable of(FieldAccessor.FieldNameExtractor... fieldNameExtractor)
Defines a custom strategy for determining the field that is accessed by this field accessor.- Parameters:
fieldNameExtractor- The field name extractors to use in their application order.- Returns:
- A field accessor using the given field name extractor.
-
of
public static FieldAccessor.OwnerTypeLocatable of(java.util.List<? extends FieldAccessor.FieldNameExtractor> fieldNameExtractors)
Defines a custom strategy for determining the field that is accessed by this field accessor.- Parameters:
fieldNameExtractors- The field name extractors to use in their application order.- Returns:
- A field accessor using the given field name extractor.
-
of
public static FieldAccessor.AssignerConfigurable of(java.lang.reflect.Field field)
Defines a field accessor where the specified field is accessed. The field must be within the hierarchy of the instrumented type.- Parameters:
field- The field being accessed.- Returns:
- A field accessor for the given field.
-
of
public static FieldAccessor.AssignerConfigurable of(FieldDescription fieldDescription)
Defines a field accessor where the specified field is accessed. The field must be within the hierarchy of the instrumented type.- Parameters:
fieldDescription- The field being accessed.- Returns:
- A field accessor for the given field.
-
-