Class ShadowProperty<T>

java.lang.Object
dev.nokee.companion.ShadowProperty<T>
Type Parameters:
T - the property type
All Implemented Interfaces:
Callable<T>

public final class ShadowProperty<T> extends Object implements Callable<T>
Represents an extra property lives in the shadow of read-only getter.
  • Constructor Details

    • ShadowProperty

      public ShadowProperty(Object self, String propertyName, Supplier<T> getter)
      Constructs a shadow property.
      Parameters:
      self - the target object
      propertyName - the property name (in terms of Groovy/Kotlin)
      getter - the plain object getter to the read-only value
  • Method Details

    • get

      public T get()
      Returns the property's value. The shadow (extra properties) are checked first, else it defaults to the plain getter.
      Returns:
      the property value
    • set

      public void set(T newValue)
      Replace the property value. Note: the new value will live in the shadow of the original value, make sure everyone knows.
      Parameters:
      newValue - the new value, must be of the same type as the original value
    • call

      public T call() throws Exception
      Convenience to use in project.files(shadowProperty) or in project.provider(shadowProperty). In both cases, the value will be deferred. Note: Must NOT be used during self-assign.
      Specified by:
      call in interface Callable<T>
      Returns:
      the property value
      Throws:
      Exception - if get() fails
    • toString

      public String toString()
      Overrides:
      toString in class Object