Class AnnotationMetadataProvider

java.lang.Object
org.vaadin.miki.superfields.object.reflect.AnnotationMetadataProvider
All Implemented Interfaces:
MetadataProvider

public class AnnotationMetadataProvider extends Object implements MetadataProvider
Provides PropertyMetadata based on previously registered annotations. Each field together with its setter and getter are scanned.
Since:
2022-09-01
Author:
miki
  • Constructor Details

    • AnnotationMetadataProvider

      public AnnotationMetadataProvider()
  • Method Details

    • getMetadata

      public Collection<PropertyMetadata> getMetadata(String name, Field field, Method setter, Method getter)
      Description copied from interface: MetadataProvider
      Collects PropertyMetadata for a given property.
      Specified by:
      getMetadata in interface MetadataProvider
      Parameters:
      name - Name of the property.
      field - A Field that corresponds to the property. Will not be null, but may not be accessible.
      setter - A Method that is a setter for the given field. May be null if there is no setter.
      getter - A Method that is a getter for the given field. May be null if there is no getter.
      Returns:
      A non-null, but possibly empty, collection of PropertyMetadata.
    • registerAnnotation

      public <V, A extends Annotation> void registerAnnotation(String name, Class<V> type, Class<A> annotation, com.vaadin.flow.function.SerializableFunction<A,V> valueFunction)
      Registers the given annotation to be discovered during scanning and maps it to a PropertyMetadata.
      Type Parameters:
      A - Annotation type.
      V - Metadata value type.
      Parameters:
      name - Name of the metadata.
      type - Value type of the metadata.
      annotation - Annotation to map.
      valueFunction - Function to obtain the value from the given annotation.
    • withRegisteredAnnotation

      public final <V, A extends Annotation> AnnotationMetadataProvider withRegisteredAnnotation(String name, Class<A> annotation, Class<V> type, com.vaadin.flow.function.SerializableFunction<A,V> valueFunction)
      Type Parameters:
      A - Annotation type.
      V - Metadata value type.
      Parameters:
      name - Name of the metadata.
      type - Value type of the metadata.
      annotation - Annotation to map.
      valueFunction - Function to obtain the value from the given annotation.
      Returns:
      This.
      See Also:
    • registerAnnotation

      public void registerAnnotation(String name, Class<? extends Annotation> annotation)
      Registers the given annotation to be discovered during scanning and maps it to a boolean PropertyMetadata. Only the presence of the annotation will result in creation of the metadata and setting its value to true. This means that the absence of the annotation will not create the metadata.
      Parameters:
      name - Name of the metadata.
      annotation - Annotation to map.
    • withRegisteredAnnotation

      public final AnnotationMetadataProvider withRegisteredAnnotation(String name, Class<? extends Annotation> annotation)
      Chains registerAnnotation(String, Class) and returns itself.
      Parameters:
      name - Name of the metadata.
      annotation - Annotation to map.
      Returns:
      This.
      See Also: