Class PropertyRefs

java.lang.Object
org.vaadin.firitin.util.PropertyRefs

public final class PropertyRefs extends Object
Digs the property name out of a method reference to a getter.

Works with any serializable lambda, so also with plain Vaadin functional interfaces like ValueProvider, not only with PropertyRef. The JVM generates a writeReplace method for serializable lambdas, which returns a SerializedLambda describing the implementation method. Both javac and the Eclipse compiler produce it, so this is not a compiler specific trick.

  • Method Details

    • propertyName

      public static String propertyName(Serializable getterReference)
      Resolves the property name from a method reference to a getter, e.g. Person::getFirstName resolves to firstName.

      The result is cached per method reference call site, so the reflection cost is paid only once per Foo::getBar expression in the source code.

      Parameters:
      getterReference - the method reference
      Returns:
      the property name
      Throws:
      IllegalArgumentException - if the given lambda is not a method reference
    • serializedLambda

      public static SerializedLambda serializedLambda(Serializable lambda)
      Returns the SerializedLambda describing the given serializable lambda.
      Parameters:
      lambda - the lambda or method reference
      Returns:
      the serialized form, with e.g. the implementation method name
    • propertyNameFromGetterName

      public static String propertyNameFromGetterName(String methodName)
      Maps a getter method name to a property name, following the JavaBeans naming convention. Names that don't look like JavaBeans getters, like record accessors, are returned as such.
      Parameters:
      methodName - the name of the getter method
      Returns:
      the property name