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 Details

  • 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

      @NotNull public @NotNull Field getMember()
      Get the java.lang.reflect member which is wrapped by this accessor.
      Specified by:
      getMember in interface BaseAccessor<Field>
      Returns:
      the wrapped member.
    • getReflexion

      @NotNull public @NotNull Reflexion getReflexion()
      Get the reflexion instance which created this accessor instance.
      Specified by:
      getReflexion in interface BaseAccessor<Field>
      Returns:
      the reflexion instance which created this instance.
    • getValue

      @NotNull public <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). This method never throws an exception, all exceptions are given back to the caller in the returned result instance.
      Specified by:
      getValue in interface FieldAccessor
      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

      @NotNull public <T> @NotNull Result<T> getValue(@Nullable @Nullable Object instance)
      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:
      getValue in interface FieldAccessor
      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

      @NotNull public @NotNull Result<Void> setValue(@Nullable @Nullable Object value)
      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:
      setValue in interface FieldAccessor
      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:
      setValue in interface FieldAccessor
      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.