Class MethodHandleAccessorFactory.MethodHandleFieldAccessor
java.lang.Object
dev.derklaro.reflexion.internal.handles.MethodHandleAccessorFactory.MethodHandleFieldAccessor
- All Implemented Interfaces:
BaseAccessor<Field>,FieldAccessor
- Enclosing class:
MethodHandleAccessorFactory
private static final class MethodHandleAccessorFactory.MethodHandleFieldAccessor
extends Object
implements FieldAccessor
An accessor for field get/set access using method handles.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Fieldprivate final MethodHandleprivate final Reflexionprivate final MethodHandle -
Constructor Summary
ConstructorsConstructorDescriptionMethodHandleFieldAccessor(@NotNull Field field, @NotNull Reflexion reflexion, @NotNull MethodHandle getter, @NotNull MethodHandle setter) Constructs a new method handle field accessor instance. -
Method Summary
Modifier and TypeMethodDescription@NotNull FieldGet the java.lang.reflect member which is wrapped by this accessor.@NotNull ReflexionGet the reflexion instance which created this accessor instance.<T> @NotNull Result<T> getValue()Gets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static).<T> @NotNull Result<T> Gets the value of the wrapped field using the given instance.Sets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static).Sets the value of the wrapped field in the given object instance.
-
Field Details
-
field
-
reflexion
-
getter
-
setter
-
-
Constructor Details
-
MethodHandleFieldAccessor
public MethodHandleFieldAccessor(@NotNull @NotNull Field field, @NotNull @NotNull Reflexion reflexion, @NotNull @NotNull MethodHandle getter, @NotNull @NotNull MethodHandle setter) Constructs a new method handle field accessor instance.- Parameters:
field- the field which is wrapped by the new accessor.reflexion- the reflexion instance which produced the reflection lookup.getter- the getter method handle for the given field.setter- the setter method handle for the given field.
-
-
Method Details
-
getMember
Get the java.lang.reflect member which is wrapped by this accessor.- Specified by:
getMemberin interfaceBaseAccessor<Field>- Returns:
- the wrapped member.
-
getReflexion
Get the reflexion instance which created this accessor instance.- Specified by:
getReflexionin interfaceBaseAccessor<Field>- Returns:
- the reflexion instance which created this instance.
-
getValue
Gets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static). This method never throws an exception, all exceptions are given back to the caller in the returned result instance.- Specified by:
getValuein interfaceFieldAccessor- Type Parameters:
T- the type of the data returned from the field.- Returns:
- the result of the get operation, either holding the field value or a read exception.
-
getValue
Gets the value of the wrapped field using the given instance. This method never throws an exception, all exceptions are given back to the caller in the returned result instance.The given instance should be present in case the field is not static, and the associated reflexion instance has no instance bound to it. If an instance is given in case the field is static, the instance will be ignored silently.
- Specified by:
getValuein interfaceFieldAccessor- Type Parameters:
T- the type of the data returned from the field.- Parameters:
instance- the instance to use when getting the field value.- Returns:
- the result of the get operation, either holding the field value or a read exception.
-
setValue
Sets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static). This method never throws an exception, all exceptions are given back to the caller in the returned result instance.- Specified by:
setValuein interfaceFieldAccessor- Parameters:
value- the new value of the field.- Returns:
- the result of the set operation, either successful or holding the set exception.
-
setValue
@NotNull public @NotNull Result<Void> setValue(@Nullable @Nullable Object instance, @Nullable @Nullable Object value) Sets the value of the wrapped field in the given object instance. This method never throws an exception, all exceptions are given back to the caller in the returned result instance.The given instance should be present in case the field is not static, and the associated reflexion instance has no instance bound to it. If an instance is given in case the field is static, the instance will be ignored silently.
- Specified by:
setValuein interfaceFieldAccessor- Parameters:
instance- the instance of the object to set the new field value in.value- the new value of the field to set.- Returns:
- the result of the set operation, either successful or holding the set exception.
-