Class ReflectivePropertyProvider

java.lang.Object
org.vaadin.miki.superfields.object.reflect.ReflectivePropertyProvider
All Implemented Interfaces:
Serializable, PropertyProvider

public class ReflectivePropertyProvider extends Object implements PropertyProvider
Simple reflection-based definition provider. It scans a given type for private fields (including final) and corresponding setters and/or getters. Delegates the scanning to ReflectTools.extractFieldsWithMethods(Class, boolean). Superclasses are by default included, unless DoNotScanSuperclasses is used on the type. All fields are included in the results, except fields annotated with Ignore. The declared field types are used, unless UseActualType is used, in which case the actual type of the field's value is used. The results are cached, except when a type has UseActualType annotation on any of its fields.
Since:
2022-06-03
Author:
miki
See Also:
  • Constructor Details

    • ReflectivePropertyProvider

      public ReflectivePropertyProvider()
  • Method Details

    • getObjectPropertyDefinitions

      public <T> List<Property<T,?>> getObjectPropertyDefinitions(Class<T> type, T instance)
      Description copied from interface: PropertyProvider
      Builds a list of property definitions for a given object.
      Specified by:
      getObjectPropertyDefinitions in interface PropertyProvider
      Type Parameters:
      T - Generic type to enforce both type and instance are compatible.
      Parameters:
      type - Type of the object.
      instance - An instance of the object. Can be null.
      Returns:
      A non-null list of Propertys that can be empty.
    • addMetadataProvider

      public final void addMetadataProvider(MetadataProvider... providers)
      Adds given MetadataProviders. They will be called in order of adding.
      Parameters:
      providers - An array of MetadataProviders to add.
    • withMetadataProvider

      public final ReflectivePropertyProvider withMetadataProvider(MetadataProvider... providers)
      Chains addMetadataProvider(MetadataProvider...) and returns itself.
      Parameters:
      providers - An array of MetadataProviders to add.
      Returns:
      This.
      See Also:
    • isUsingFakeSettersWhenNotPresent

      public boolean isUsingFakeSettersWhenNotPresent()
      Checks whether a fake setter (i.e. one that does nothing) is returned when there is no setter for a property.
      Returns:
      When true, a fake setter is used instead of a null value (default).
    • setUsingFakeSettersWhenNotPresent

      public void setUsingFakeSettersWhenNotPresent(boolean usingFakeSettersWhenNotPresent)
      Allows using a fake setter when there is no setter for a given property. This allows setters to be called regardless of whether they exist or not.
      Parameters:
      usingFakeSettersWhenNotPresent - When true and a setter for a property is missing, a fake one will be used instead of null.
    • withUsingFakeSettersWhenNotPresent

      public final ReflectivePropertyProvider withUsingFakeSettersWhenNotPresent(boolean setting)
      Parameters:
      setting - Whether to fake setters.
      Returns:
      This.
      See Also:
    • isUsingFakeGettersWhenNotPresent

      public boolean isUsingFakeGettersWhenNotPresent()
      Checks whether a fake getter (i.e. one that always returns null) is returned when there is no getter for a property.
      Returns:
      When true, a fake getter is used instead of a null value (default).
    • setUsingFakeGettersWhenNotPresent

      public void setUsingFakeGettersWhenNotPresent(boolean usingFakeGettersWhenNotPresent)
      Allows using a fake getter when there is no getter for a given property. This allows getters to be called regardless of whether they exist or not.
      Parameters:
      usingFakeGettersWhenNotPresent - When true and a getter for a property is missing, a fake one will be used instead of null.
    • withUsingFakeGettersWhenNotPresent

      public final ReflectivePropertyProvider withUsingFakeGettersWhenNotPresent(boolean setting)
      Parameters:
      setting - When true and a getter for a property is missing, a fake one will be used instead of null.
      Returns:
      This.
      See Also: