Class BareAccessorFactory.BareFieldAccessor

java.lang.Object
dev.derklaro.reflexion.internal.bare.BareAccessorFactory.BareFieldAccessor
All Implemented Interfaces:
BaseAccessor<Field>, FieldAccessor
Enclosing class:
BareAccessorFactory

private static final class BareAccessorFactory.BareFieldAccessor extends Object implements FieldAccessor
A field accessor which invokes the bare java.lang.reflect field.
Since:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Field
     
    private final Reflexion
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BareFieldAccessor(@NotNull Field field, @NotNull Reflexion reflexion)
    Constructs a new bare field accessor instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Field
    Get the java.lang.reflect member which is wrapped by this accessor.
    @NotNull Reflexion
    Get the reflexion instance which created this accessor instance.
    <T> @NotNull Result<T>
    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>
    getValue(@Nullable Object instance)
    Gets the value of the wrapped field using the given instance.
    @NotNull Result<Void>
    setValue(@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).
    @NotNull Result<Void>
    setValue(@Nullable Object instance, @Nullable Object value)
    Sets the value of the wrapped field in the given object instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • field

      private final Field field
    • reflexion

      private final Reflexion reflexion
  • Constructor Details

    • BareFieldAccessor

      public BareFieldAccessor(@NotNull @NotNull Field field, @NotNull @NotNull Reflexion reflexion)
      Constructs a new bare field accessor instance.
      Parameters:
      field - the field to wrap.
      reflexion - the reflexion instance which produced the instance.
  • 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.