Class RecordGetExecutor

All Implemented Interfaces:
JexlPropertyGet

public final class RecordGetExecutor extends AbstractExecutor.Get
Specialized executor to get a property from a Java record component.

A record (JEP 395, Java 16+) exposes one accessor per component, named exactly like the component - x(), not getX(). PropertyGetExecutor only looks for the bean convention, so a record component was otherwise never resolved as a property.

Record detection and lookup are delegated to ClassTool, which resolves the relevant methods through reflection so this module remains usable on the Java 8 baseline this project still targets; on such a runtime, Class#isRecord() and Class#getRecordComponents() simply do not exist and discovery quietly reports no match instead of failing to link.

Since:
3.7.1
  • Field Details

    • EMPTY_PARAMS

      private static final Object[] EMPTY_PARAMS
      A static signature for method().
    • property

      private final String property
      The property (record component name).
  • Constructor Details

    • RecordGetExecutor

      private RecordGetExecutor(Class<?> clazz, Method method, String identifier)
      Creates an instance.
      Parameters:
      clazz - the class the accessor applies to
      method - the accessor method held by this executor
      identifier - the property to get
  • Method Details

    • discover

      public static RecordGetExecutor discover(Introspector is, Class<?> clazz, String property)
      Discovers a RecordGetExecutor.

      The class must be a record and declare a component named property; the accessor method itself is resolved through is so it goes through the same permission checks as every other property accessor.

      Parameters:
      is - the introspector
      clazz - the class to find the accessor method from
      property - the property (record component) name to find
      Returns:
      the executor if found, null otherwise
    • getTargetProperty

      public Object getTargetProperty()
      Description copied from class: AbstractExecutor
      Gets the property targeted by this executor.
      Overrides:
      getTargetProperty in class AbstractExecutor
      Returns:
      The target property
    • invoke

      Description copied from interface: JexlPropertyGet
      Method used to get the property value of an object.
      Parameters:
      o - The object to get the property value from.
      Returns:
      The property value.
      Throws:
      IllegalAccessException
      InvocationTargetException
    • tryInvoke

      public Object tryInvoke(Object o, Object identifier)
      Description copied from interface: JexlPropertyGet
      Attempts to reuse this JexlPropertyGet, checking that it is compatible with the actual set of arguments.
      Parameters:
      o - The object to invoke the property get upon
      identifier - The property key to get
      Returns:
      The result of the method invocation that should be checked by tryFailed to determine if it succeeded or failed.